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

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: Added back transport controller test, small cleanups 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.
(...skipping 18 matching lines...) Expand all
70 std::unique_ptr<BlobReader> CreateReader( 73 std::unique_ptr<BlobReader> CreateReader(
71 FileSystemContext* file_system_context, 74 FileSystemContext* file_system_context,
72 base::SequencedTaskRunner* file_task_runner) const; 75 base::SequencedTaskRunner* file_task_runner) const;
73 76
74 // May be accessed on any thread. 77 // May be accessed on any thread.
75 const std::string& uuid() const; 78 const std::string& uuid() const;
76 // May be accessed on any thread. 79 // May be accessed on any thread.
77 const std::string& content_type() const; 80 const std::string& content_type() const;
78 // May be accessed on any thread. 81 // May be accessed on any thread.
79 const std::string& content_disposition() const; 82 const std::string& content_disposition() const;
83 // May be accessed on any thread. In rare cases where the blob is created
84 // as a file from javascript, this will be kUnknownSize.
85 uint64_t size() const;
80 86
81 // This call and the destruction of the returned snapshot must be called 87 // 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. 88 // 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 89 // Please do not call this, and use CreateReader instead. It appropriately
84 // waits until the blob is built before having a size (see CalculateSize). 90 // 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. 91 // TODO(dmurph): Make this protected, where only the BlobReader can call it.
86 std::unique_ptr<BlobDataSnapshot> CreateSnapshot() const; 92 std::unique_ptr<BlobDataSnapshot> CreateSnapshot() const;
87 93
88 private: 94 private:
89 // Internal class whose destructor is guarenteed to be called on the IO 95 // Internal class whose destructor is guarenteed to be called on the IO
90 // thread. 96 // thread.
91 class BlobDataHandleShared 97 class BlobDataHandleShared
92 : public base::RefCountedThreadSafe<BlobDataHandleShared> { 98 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
93 public: 99 public:
94 BlobDataHandleShared(const std::string& uuid, 100 BlobDataHandleShared(const std::string& uuid,
95 const std::string& content_type, 101 const std::string& content_type,
96 const std::string& content_disposition, 102 const std::string& content_disposition,
103 uint64_t size,
97 BlobStorageContext* context); 104 BlobStorageContext* context);
98 105
99 private: 106 private:
100 friend class base::DeleteHelper<BlobDataHandleShared>; 107 friend class base::DeleteHelper<BlobDataHandleShared>;
101 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; 108 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
102 friend class BlobDataHandle; 109 friend class BlobDataHandle;
103 110
104 virtual ~BlobDataHandleShared(); 111 virtual ~BlobDataHandleShared();
105 112
106 const std::string uuid_; 113 const std::string uuid_;
107 const std::string content_type_; 114 const std::string content_type_;
108 const std::string content_disposition_; 115 const std::string content_disposition_;
116 const uint64_t size_;
109 base::WeakPtr<BlobStorageContext> context_; 117 base::WeakPtr<BlobStorageContext> context_;
110 118
111 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); 119 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
112 }; 120 };
113 121
114 friend class BlobStorageContext; 122 friend class BlobStorageContext;
115 BlobDataHandle(const std::string& uuid, 123 BlobDataHandle(const std::string& uuid,
116 const std::string& content_type, 124 const std::string& content_type,
117 const std::string& content_disposition, 125 const std::string& content_disposition,
126 uint64_t size,
118 BlobStorageContext* context, 127 BlobStorageContext* context,
119 base::SequencedTaskRunner* io_task_runner); 128 base::SequencedTaskRunner* io_task_runner);
120 129
121 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 130 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
122 scoped_refptr<BlobDataHandleShared> shared_; 131 scoped_refptr<BlobDataHandleShared> shared_;
123 }; 132 };
124 133
125 } // namespace storage 134 } // namespace storage
126 135
127 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ 136 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698