OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ |
6 #define STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ | 6 #define STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ |
7 | 7 |
8 #include <vector> | 8 #include "storage/browser/blob/blob_data_item.h" |
9 | |
10 #include "storage/browser/blob/scoped_file.h" | 9 #include "storage/browser/blob/scoped_file.h" |
11 #include "storage/browser/storage_browser_export.h" | 10 #include "storage/browser/storage_browser_export.h" |
12 | 11 |
13 namespace storage { | 12 namespace storage { |
14 | 13 |
15 // ShareableFileReference allows consumers to share FileReference for the | 14 // ShareableFileReference allows consumers to share FileReference for the |
16 // same path if it already exists in its internal map. | 15 // same path if it already exists in its internal map. |
17 // This class is non-thread-safe and all methods must be called on a single | 16 // This class is non-thread-safe and all methods must be called on a single |
18 // thread. | 17 // thread. |
19 class STORAGE_EXPORT ShareableFileReference | 18 class STORAGE_EXPORT ShareableFileReference : public BlobDataItem::DataHandle { |
20 : public base::RefCounted<ShareableFileReference> { | |
21 public: | 19 public: |
22 typedef ScopedFile::ScopeOutCallback FinalReleaseCallback; | 20 typedef ScopedFile::ScopeOutCallback FinalReleaseCallback; |
23 | 21 |
24 enum FinalReleasePolicy { | 22 enum FinalReleasePolicy { |
25 DELETE_ON_FINAL_RELEASE = ScopedFile::DELETE_ON_SCOPE_OUT, | 23 DELETE_ON_FINAL_RELEASE = ScopedFile::DELETE_ON_SCOPE_OUT, |
26 DONT_DELETE_ON_FINAL_RELEASE = ScopedFile::DONT_DELETE_ON_SCOPE_OUT, | 24 DONT_DELETE_ON_FINAL_RELEASE = ScopedFile::DONT_DELETE_ON_SCOPE_OUT, |
27 }; | 25 }; |
28 | 26 |
29 // Returns a ShareableFileReference for the given path, if no reference | 27 // Returns a ShareableFileReference for the given path, if no reference |
30 // for this path exists returns NULL. | 28 // for this path exists returns NULL. |
(...skipping 22 matching lines...) Expand all Loading... |
53 | 51 |
54 // The full file path. | 52 // The full file path. |
55 const base::FilePath& path() const { return scoped_file_.path(); } | 53 const base::FilePath& path() const { return scoped_file_.path(); } |
56 | 54 |
57 // The |callback| is fired when the final reference of this instance | 55 // The |callback| is fired when the final reference of this instance |
58 // is released. If release policy is DELETE_ON_FINAL_RELEASE the | 56 // is released. If release policy is DELETE_ON_FINAL_RELEASE the |
59 // callback task(s) is/are posted before the deletion is scheduled. | 57 // callback task(s) is/are posted before the deletion is scheduled. |
60 void AddFinalReleaseCallback(const FinalReleaseCallback& callback); | 58 void AddFinalReleaseCallback(const FinalReleaseCallback& callback); |
61 | 59 |
62 private: | 60 private: |
63 friend class base::RefCounted<ShareableFileReference>; | |
64 | |
65 ShareableFileReference(ScopedFile scoped_file); | 61 ShareableFileReference(ScopedFile scoped_file); |
66 ~ShareableFileReference(); | 62 ~ShareableFileReference() override; |
67 | 63 |
68 ScopedFile scoped_file_; | 64 ScopedFile scoped_file_; |
69 | 65 |
70 DISALLOW_COPY_AND_ASSIGN(ShareableFileReference); | 66 DISALLOW_COPY_AND_ASSIGN(ShareableFileReference); |
71 }; | 67 }; |
72 | 68 |
73 } // namespace storage | 69 } // namespace storage |
74 | 70 |
75 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ | 71 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ |
OLD | NEW |