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

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

Issue 1846363002: [BlobAsync] Adding better error reporting and some new tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 8 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h" 15 #include "base/supports_user_data.h"
16 #include "storage/browser/storage_browser_export.h" 16 #include "storage/browser/storage_browser_export.h"
17 #include "storage/common/blob_storage/blob_storage_constants.h"
17 18
18 namespace base { 19 namespace base {
19 class SequencedTaskRunner; 20 class SequencedTaskRunner;
20 } 21 }
21 22
22 namespace storage { 23 namespace storage {
23 24
24 class BlobDataSnapshot; 25 class BlobDataSnapshot;
25 class BlobReader; 26 class BlobReader;
26 class BlobStorageContext; 27 class BlobStorageContext;
27 class FileSystemContext; 28 class FileSystemContext;
28 29
29 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains 30 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains
30 // in the BlobStorageContext's collection while this object is alive. Anything 31 // in the BlobStorageContext's collection while this object is alive. Anything
31 // that needs to keep a blob alive needs to store this handle. 32 // that needs to keep a blob alive needs to store this handle.
32 // When the blob data itself is needed, clients must call the CreateSnapshot() 33 // When the blob data itself is needed, clients must call the CreateSnapshot()
33 // method on the IO thread to create a snapshot of the blob data. This snapshot 34 // method on the IO thread to create a snapshot of the blob data. This snapshot
34 // is not intended to be persisted, and serves to ensure that the backing 35 // is not intended to be persisted, and serves to ensure that the backing
35 // resources remain around for the duration of reading the blob. This snapshot 36 // resources remain around for the duration of reading the blob. This snapshot
36 // can be read on any thread, but it must be destructed on the IO thread. 37 // can be read on any thread, but it must be destructed on the IO thread.
37 // This object has delete semantics and may be deleted on any thread. 38 // This object has delete semantics and may be deleted on any thread.
38 class STORAGE_EXPORT BlobDataHandle 39 class STORAGE_EXPORT BlobDataHandle
39 : public base::SupportsUserData::Data { 40 : public base::SupportsUserData::Data {
40 public: 41 public:
42 // True means the blob was constructed successfully, and false means that
43 // there was an error, which is reported in the second argument.
44 using BlobConstructedCallback =
45 base::Callback<void(bool, IPCBlobCreationCancelCode)>;
46
41 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. 47 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
42 ~BlobDataHandle() override; // May be deleted on any thread. 48 ~BlobDataHandle() override; // May be deleted on any thread.
43 49
44 // Returns if this blob is still constructing. If so, one can use the 50 // Returns if this blob is still constructing. If so, one can use the
45 // RunOnConstructionComplete to wait. 51 // RunOnConstructionComplete to wait.
46 // Must be called on IO thread. 52 // Must be called on IO thread.
47 bool IsBeingBuilt() const; 53 bool IsBeingBuilt() const;
48 54
49 // Returns if this blob is broken, and there is no data associated with it. 55 // Returns if this blob is broken, and there is no data associated with it.
50 // Must be called on IO thread. 56 // Must be called on IO thread.
51 bool IsBroken() const; 57 bool IsBroken() const;
52 58
53 // The callback will be run on the IO thread when construction of the blob 59 // The callback will be run on the IO thread when construction of the blob
54 // is complete. If construction is already complete, then the task is run 60 // is complete. If construction is already complete, then the task is run
55 // immediately on the current message loop (i.e. IO thread). 61 // immediately on the current message loop (i.e. IO thread).
56 // Must be called on IO thread. Returns if construction successful. 62 // Must be called on IO thread. Returns if construction successful.
57 // Calling this multiple times results in registering multiple 63 // Calling this multiple times results in registering multiple
58 // completion callbacks. 64 // completion callbacks.
59 void RunOnConstructionComplete(const base::Callback<void(bool)>& done); 65 void RunOnConstructionComplete(const BlobConstructedCallback& done);
60 66
61 // A BlobReader is used to read the data from the blob. This object is 67 // A BlobReader is used to read the data from the blob. This object is
62 // intended to be transient and should not be stored for any extended period 68 // intended to be transient and should not be stored for any extended period
63 // of time. 69 // of time.
64 std::unique_ptr<BlobReader> CreateReader( 70 std::unique_ptr<BlobReader> CreateReader(
65 FileSystemContext* file_system_context, 71 FileSystemContext* file_system_context,
66 base::SequencedTaskRunner* file_task_runner) const; 72 base::SequencedTaskRunner* file_task_runner) const;
67 73
68 // May be accessed on any thread. 74 // May be accessed on any thread.
69 const std::string& uuid() const; 75 const std::string& uuid() const;
(...skipping 13 matching lines...) Expand all
83 // Internal class whose destructor is guarenteed to be called on the IO 89 // Internal class whose destructor is guarenteed to be called on the IO
84 // thread. 90 // thread.
85 class BlobDataHandleShared 91 class BlobDataHandleShared
86 : public base::RefCountedThreadSafe<BlobDataHandleShared> { 92 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
87 public: 93 public:
88 BlobDataHandleShared(const std::string& uuid, 94 BlobDataHandleShared(const std::string& uuid,
89 const std::string& content_type, 95 const std::string& content_type,
90 const std::string& content_disposition, 96 const std::string& content_disposition,
91 BlobStorageContext* context); 97 BlobStorageContext* context);
92 98
93 void RunOnConstructionComplete(const base::Callback<void(bool)>& done);
94
95 std::unique_ptr<BlobDataSnapshot> CreateSnapshot() const;
96
97 private: 99 private:
98 friend class base::DeleteHelper<BlobDataHandleShared>; 100 friend class base::DeleteHelper<BlobDataHandleShared>;
99 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; 101 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
100 friend class BlobDataHandle; 102 friend class BlobDataHandle;
101 103
102 virtual ~BlobDataHandleShared(); 104 virtual ~BlobDataHandleShared();
103 105
104 const std::string uuid_; 106 const std::string uuid_;
105 const std::string content_type_; 107 const std::string content_type_;
106 const std::string content_disposition_; 108 const std::string content_disposition_;
107 base::WeakPtr<BlobStorageContext> context_; 109 base::WeakPtr<BlobStorageContext> context_;
108 110
109 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); 111 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
110 }; 112 };
111 113
112 friend class BlobStorageContext; 114 friend class BlobStorageContext;
113 BlobDataHandle(const std::string& uuid, 115 BlobDataHandle(const std::string& uuid,
114 const std::string& content_type, 116 const std::string& content_type,
115 const std::string& content_disposition, 117 const std::string& content_disposition,
116 BlobStorageContext* context, 118 BlobStorageContext* context,
117 base::SequencedTaskRunner* io_task_runner); 119 base::SequencedTaskRunner* io_task_runner);
118 120
119 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 121 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
120 scoped_refptr<BlobDataHandleShared> shared_; 122 scoped_refptr<BlobDataHandleShared> shared_;
121 }; 123 };
122 124
123 } // namespace storage 125 } // namespace storage
124 126
125 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ 127 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_async_builder_host.cc ('k') | storage/browser/blob/blob_data_handle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698