OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_BLOB_DATA_HANDLE_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ |
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
13 #include "storage/browser/storage_browser_export.h" | 14 #include "storage/browser/storage_browser_export.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class SequencedTaskRunner; | 17 class SequencedTaskRunner; |
17 } | 18 } |
18 | 19 |
19 namespace storage { | 20 namespace storage { |
20 | 21 |
21 class BlobDataSnapshot; | 22 class BlobDataSnapshot; |
| 23 class BlobReader; |
22 class BlobStorageContext; | 24 class BlobStorageContext; |
| 25 class FileSystemContext; |
23 | 26 |
24 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains | 27 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains |
25 // in the BlobStorageContext's collection while this object is alive. Anything | 28 // in the BlobStorageContext's collection while this object is alive. Anything |
26 // that needs to keep a blob alive needs to store this handle. | 29 // that needs to keep a blob alive needs to store this handle. |
27 // When the blob data itself is needed, clients must call the CreateSnapshot() | 30 // When the blob data itself is needed, clients must call the CreateSnapshot() |
28 // method on the IO thread to create a snapshot of the blob data. This snapshot | 31 // method on the IO thread to create a snapshot of the blob data. This snapshot |
29 // is not intended to be persisted, and serves to ensure that the backing | 32 // is not intended to be persisted, and serves to ensure that the backing |
30 // resources remain around for the duration of reading the blob. This snapshot | 33 // resources remain around for the duration of reading the blob. This snapshot |
31 // can be read on any thread, but it must be destructed on the IO thread. | 34 // can be read on any thread, but it must be destructed on the IO thread. |
32 // This object has delete semantics and may be deleted on any thread. | 35 // This object has delete semantics and may be deleted on any thread. |
33 class STORAGE_EXPORT BlobDataHandle | 36 class STORAGE_EXPORT BlobDataHandle |
34 : public base::SupportsUserData::Data { | 37 : public base::SupportsUserData::Data { |
35 public: | 38 public: |
36 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. | 39 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. |
37 ~BlobDataHandle() override; // May be deleted on any thread. | 40 ~BlobDataHandle() override; // May be deleted on any thread. |
38 | 41 |
39 // A BlobDataSnapshot is used to read the data from the blob. This object is | 42 // A BlobReader is used to read the data from the blob. This object is |
40 // intended to be transient and should not be stored for any extended period | 43 // intended to be transient and should not be stored for any extended period |
41 // of time. | 44 // of time. |
| 45 scoped_ptr<BlobReader> CreateReader( |
| 46 FileSystemContext* file_system_context, |
| 47 base::SequencedTaskRunner* file_task_runner) const; |
| 48 |
| 49 // May be accessed on any thread. |
| 50 const std::string& uuid() const; |
| 51 // May be accessed on any thread. |
| 52 const std::string& content_type() const; |
| 53 // May be accessed on any thread. |
| 54 const std::string& content_disposition() const; |
| 55 |
42 // This call and the destruction of the returned snapshot must be called | 56 // This call and the destruction of the returned snapshot must be called |
43 // on the IO thread. | 57 // on the IO thread. |
| 58 // TODO(dmurph): Make this protected, where only the BlobReader can call it. |
44 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; | 59 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; |
45 | 60 |
46 const std::string& uuid() const; // May be accessed on any thread. | |
47 | |
48 private: | 61 private: |
49 // Internal class whose destructor is guarenteed to be called on the IO | 62 // Internal class whose destructor is guarenteed to be called on the IO |
50 // thread. | 63 // thread. |
51 class BlobDataHandleShared | 64 class BlobDataHandleShared |
52 : public base::RefCountedThreadSafe<BlobDataHandleShared> { | 65 : public base::RefCountedThreadSafe<BlobDataHandleShared> { |
53 public: | 66 public: |
54 BlobDataHandleShared(const std::string& uuid, | 67 BlobDataHandleShared(const std::string& uuid, |
55 BlobStorageContext* context, | 68 const std::string& content_type, |
56 base::SequencedTaskRunner* task_runner); | 69 const std::string& content_disposition, |
| 70 BlobStorageContext* context); |
57 | 71 |
58 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; | 72 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; |
59 const std::string& uuid() const; | |
60 | 73 |
61 private: | 74 private: |
62 friend class base::DeleteHelper<BlobDataHandleShared>; | 75 friend class base::DeleteHelper<BlobDataHandleShared>; |
63 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; | 76 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; |
64 friend class BlobDataHandle; | 77 friend class BlobDataHandle; |
65 | 78 |
66 virtual ~BlobDataHandleShared(); | 79 virtual ~BlobDataHandleShared(); |
67 | 80 |
68 const std::string uuid_; | 81 const std::string uuid_; |
| 82 const std::string content_type_; |
| 83 const std::string content_disposition_; |
69 base::WeakPtr<BlobStorageContext> context_; | 84 base::WeakPtr<BlobStorageContext> context_; |
70 | 85 |
71 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); | 86 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); |
72 }; | 87 }; |
73 | 88 |
74 friend class BlobStorageContext; | 89 friend class BlobStorageContext; |
75 BlobDataHandle(const std::string& uuid, | 90 BlobDataHandle(const std::string& uuid, |
| 91 const std::string& content_type, |
| 92 const std::string& content_disposition, |
76 BlobStorageContext* context, | 93 BlobStorageContext* context, |
77 base::SequencedTaskRunner* task_runner); | 94 base::SequencedTaskRunner* io_task_runner); |
78 | 95 |
79 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 96 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
80 scoped_refptr<BlobDataHandleShared> shared_; | 97 scoped_refptr<BlobDataHandleShared> shared_; |
81 }; | 98 }; |
82 | 99 |
83 } // namespace storage | 100 } // namespace storage |
84 | 101 |
85 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ | 102 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ |
OLD | NEW |