Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: storage/browser/blob/blob_data_handle.h

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, simplifications Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <limits>
8 #include <memory> 9 #include <memory>
9 #include <string> 10 #include <string>
10 11
11 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h" 16 #include "base/supports_user_data.h"
16 #include "storage/browser/storage_browser_export.h" 17 #include "storage/browser/storage_browser_export.h"
17 #include "storage/common/blob_storage/blob_storage_constants.h" 18 #include "storage/common/blob_storage/blob_storage_constants.h"
(...skipping 14 matching lines...) Expand all
32 // that needs to keep a blob alive needs to store this handle. 33 // that needs to keep a blob alive needs to store this handle.
33 // When the blob data itself is needed, clients must call the CreateSnapshot() 34 // When the blob data itself is needed, clients must call the CreateSnapshot()
34 // method on the IO thread to create a snapshot of the blob data. This snapshot 35 // method on the IO thread to create a snapshot of the blob data. This snapshot
35 // is not intended to be persisted, and serves to ensure that the backing 36 // is not intended to be persisted, and serves to ensure that the backing
36 // resources remain around for the duration of reading the blob. This snapshot 37 // resources remain around for the duration of reading the blob. This snapshot
37 // can be read on any thread, but it must be destructed on the IO thread. 38 // can be read on any thread, but it must be destructed on the IO thread.
38 // This object has delete semantics and may be deleted on any thread. 39 // This object has delete semantics and may be deleted on any thread.
39 class STORAGE_EXPORT BlobDataHandle 40 class STORAGE_EXPORT BlobDataHandle
40 : public base::SupportsUserData::Data { 41 : public base::SupportsUserData::Data {
41 public: 42 public:
43 static constexpr uint64_t kUnknownSize = std::numeric_limits<uint64_t>::max();
44
42 // True means the blob was constructed successfully, and false means that 45 // True means the blob was constructed successfully, and false means that
43 // there was an error, which is reported in the second argument. 46 // there was an error, which is reported in the second argument.
44 using BlobConstructedCallback = 47 using BlobConstructedCallback =
45 base::Callback<void(bool, IPCBlobCreationCancelCode)>; 48 base::Callback<void(bool, IPCBlobCreationCancelCode)>;
46 49
47 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. 50 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
48 ~BlobDataHandle() override; // May be deleted on any thread. 51 ~BlobDataHandle() override; // May be deleted on any thread.
49 52
50 // Returns if this blob is still constructing. If so, one can use the 53 // Returns if this blob is still constructing. If so, one can use the
51 // RunOnConstructionComplete to wait. 54 // RunOnConstructionComplete to wait.
52 // Must be called on IO thread. 55 // Must be called on IO thread.
53 bool IsBeingBuilt() const; 56 bool IsBeingBuilt() const;
54 57
55 // Returns if this blob is broken, and there is no data associated with it. 58 // Returns if this blob is broken, and there is no data associated with it.
56 // Must be called on IO thread. 59 // Must be called on IO thread.
57 bool IsBroken() const; 60 bool IsBroken() const;
58 61
62 // Returns the broken reason if this blob is broken.
63 // Must be called on IO thread.
64 IPCBlobCreationCancelCode GetBrokenReason() const;
65
59 // The callback will be run on the IO thread when construction of the blob 66 // The callback will be run on the IO thread when construction of the blob
60 // is complete. If construction is already complete, then the task is run 67 // is complete. If construction is already complete, then the task is run
61 // immediately on the current message loop (i.e. IO thread). 68 // immediately on the current message loop (i.e. IO thread).
62 // Must be called on IO thread. Returns if construction successful. 69 // Must be called on IO thread. Returns if construction successful.
63 // Calling this multiple times results in registering multiple 70 // Calling this multiple times results in registering multiple
64 // completion callbacks. 71 // completion callbacks.
65 void RunOnConstructionComplete(const BlobConstructedCallback& done); 72 void RunOnConstructionComplete(const BlobConstructedCallback& done);
66 73
67 // A BlobReader is used to read the data from the blob. This object is 74 // A BlobReader is used to read the data from the blob. This object is
68 // intended to be transient and should not be stored for any extended period 75 // intended to be transient and should not be stored for any extended period
69 // of time. 76 // of time.
70 std::unique_ptr<BlobReader> CreateReader( 77 std::unique_ptr<BlobReader> CreateReader(
71 FileSystemContext* file_system_context, 78 FileSystemContext* file_system_context,
72 base::SequencedTaskRunner* file_task_runner) const; 79 base::SequencedTaskRunner* file_task_runner) const;
73 80
74 // May be accessed on any thread. 81 // May be accessed on any thread.
75 const std::string& uuid() const; 82 const std::string& uuid() const;
76 // May be accessed on any thread. 83 // May be accessed on any thread.
77 const std::string& content_type() const; 84 const std::string& content_type() const;
78 // May be accessed on any thread. 85 // May be accessed on any thread.
79 const std::string& content_disposition() const; 86 const std::string& content_disposition() const;
87 // May be accessed on any thread. In rare cases where the blob is created
88 // as a file from javascript, this will be kUnknownSize.
89 uint64_t size() const;
80 90
81 // This call and the destruction of the returned snapshot must be called 91 // This call and the destruction of the returned snapshot must be called
82 // on the IO thread. If the blob is broken, then we return a nullptr here. 92 // on the IO thread. If the blob is broken, then we return a nullptr here.
83 // Please do not call this, and use CreateReader instead. It appropriately 93 // Please do not call this, and use CreateReader instead. It appropriately
84 // waits until the blob is built before having a size (see CalculateSize). 94 // waits until the blob is built before having a size (see CalculateSize).
85 // TODO(dmurph): Make this protected, where only the BlobReader can call it. 95 // TODO(dmurph): Make this protected, where only the BlobReader can call it.
86 std::unique_ptr<BlobDataSnapshot> CreateSnapshot() const; 96 std::unique_ptr<BlobDataSnapshot> CreateSnapshot() const;
87 97
88 private: 98 private:
89 // Internal class whose destructor is guarenteed to be called on the IO 99 // Internal class whose destructor is guarenteed to be called on the IO
90 // thread. 100 // thread.
91 class BlobDataHandleShared 101 class BlobDataHandleShared
92 : public base::RefCountedThreadSafe<BlobDataHandleShared> { 102 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
93 public: 103 public:
94 BlobDataHandleShared(const std::string& uuid, 104 BlobDataHandleShared(const std::string& uuid,
95 const std::string& content_type, 105 const std::string& content_type,
96 const std::string& content_disposition, 106 const std::string& content_disposition,
107 uint64_t size,
97 BlobStorageContext* context); 108 BlobStorageContext* context);
98 109
99 private: 110 private:
100 friend class base::DeleteHelper<BlobDataHandleShared>; 111 friend class base::DeleteHelper<BlobDataHandleShared>;
101 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; 112 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
102 friend class BlobDataHandle; 113 friend class BlobDataHandle;
103 114
104 virtual ~BlobDataHandleShared(); 115 virtual ~BlobDataHandleShared();
105 116
106 const std::string uuid_; 117 const std::string uuid_;
107 const std::string content_type_; 118 const std::string content_type_;
108 const std::string content_disposition_; 119 const std::string content_disposition_;
120 const uint64_t size_;
109 base::WeakPtr<BlobStorageContext> context_; 121 base::WeakPtr<BlobStorageContext> context_;
110 122
111 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); 123 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
112 }; 124 };
113 125
114 friend class BlobStorageContext; 126 friend class BlobStorageContext;
115 BlobDataHandle(const std::string& uuid, 127 BlobDataHandle(const std::string& uuid,
116 const std::string& content_type, 128 const std::string& content_type,
117 const std::string& content_disposition, 129 const std::string& content_disposition,
130 uint64_t size,
118 BlobStorageContext* context, 131 BlobStorageContext* context,
119 base::SequencedTaskRunner* io_task_runner); 132 base::SequencedTaskRunner* io_task_runner);
120 133
121 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 134 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
122 scoped_refptr<BlobDataHandleShared> shared_; 135 scoped_refptr<BlobDataHandleShared> shared_;
123 }; 136 };
124 137
125 } // namespace storage 138 } // namespace storage
126 139
127 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ 140 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698