Remove unused did_first_* fields from InternalDocumentStateData.
[chromium-blink-merge.git] / storage / browser / blob / shareable_file_reference.h
blob10f986faa1375e6e440961b04441d4deb4f7f3b0
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_
6 #define STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_
8 #include "storage/browser/blob/blob_data_item.h"
9 #include "storage/browser/blob/scoped_file.h"
10 #include "storage/browser/storage_browser_export.h"
12 namespace storage {
14 // ShareableFileReference allows consumers to share FileReference for the
15 // same path if it already exists in its internal map.
16 // This class is non-thread-safe and all methods must be called on a single
17 // thread.
18 class STORAGE_EXPORT ShareableFileReference : public BlobDataItem::DataHandle {
19 public:
20 typedef ScopedFile::ScopeOutCallback FinalReleaseCallback;
22 enum FinalReleasePolicy {
23 DELETE_ON_FINAL_RELEASE = ScopedFile::DELETE_ON_SCOPE_OUT,
24 DONT_DELETE_ON_FINAL_RELEASE = ScopedFile::DONT_DELETE_ON_SCOPE_OUT,
27 // Returns a ShareableFileReference for the given path, if no reference
28 // for this path exists returns NULL.
29 static scoped_refptr<ShareableFileReference> Get(const base::FilePath& path);
31 // Returns a ShareableFileReference for the given path, creating a new
32 // reference if none yet exists. If there's a pre-existing reference for
33 // the path, the policy parameter of this method is ignored.
34 static scoped_refptr<ShareableFileReference> GetOrCreate(
35 const base::FilePath& path,
36 FinalReleasePolicy policy,
37 base::TaskRunner* file_task_runner);
39 // Returns a ShareableFileReference for the given path of the |scoped_file|,
40 // creating a new reference if none yet exists. The ownership of |scoped_file|
41 // is passed to this reference.
42 // If there's a pre-existing reference for the path, the scope out policy
43 // and scope-out-callbacks of the given |scoped_file| is ignored.
44 // If the given scoped_file has an empty path (e.g. maybe already
45 // released) this returns NULL reference.
47 // TODO(kinuko): Make sure if this behavior is ok, we could alternatively
48 // merge callbacks to the existing one.
49 static scoped_refptr<ShareableFileReference> GetOrCreate(
50 ScopedFile scoped_file);
52 // The full file path.
53 const base::FilePath& path() const { return scoped_file_.path(); }
55 // The |callback| is fired when the final reference of this instance
56 // is released. If release policy is DELETE_ON_FINAL_RELEASE the
57 // callback task(s) is/are posted before the deletion is scheduled.
58 void AddFinalReleaseCallback(const FinalReleaseCallback& callback);
60 private:
61 ShareableFileReference(ScopedFile scoped_file);
62 ~ShareableFileReference() override;
64 ScopedFile scoped_file_;
66 DISALLOW_COPY_AND_ASSIGN(ShareableFileReference);
69 } // namespace storage
71 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_