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

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

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments Created 4 years, 9 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 <string> 8 #include <string>
9 9
10 #include "base/callback_forward.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
14 #include "base/supports_user_data.h" 15 #include "base/supports_user_data.h"
15 #include "storage/browser/storage_browser_export.h" 16 #include "storage/browser/storage_browser_export.h"
16 17
17 namespace base { 18 namespace base {
18 class SequencedTaskRunner; 19 class SequencedTaskRunner;
19 } 20 }
(...skipping 13 matching lines...) Expand all
33 // is not intended to be persisted, and serves to ensure that the backing 34 // is not intended to be persisted, and serves to ensure that the backing
34 // resources remain around for the duration of reading the blob. This snapshot 35 // resources remain around for the duration of reading the blob. This snapshot
35 // can be read on any thread, but it must be destructed on the IO thread. 36 // can be read on any thread, but it must be destructed on the IO thread.
36 // This object has delete semantics and may be deleted on any thread. 37 // This object has delete semantics and may be deleted on any thread.
37 class STORAGE_EXPORT BlobDataHandle 38 class STORAGE_EXPORT BlobDataHandle
38 : public base::SupportsUserData::Data { 39 : public base::SupportsUserData::Data {
39 public: 40 public:
40 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. 41 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
41 ~BlobDataHandle() override; // May be deleted on any thread. 42 ~BlobDataHandle() override; // May be deleted on any thread.
42 43
44 // Returns if this blob is still constructing. If so, one can use the
45 // RunOnConstructionComplete to wait.
46 // Must be called on IO thread.
47 bool IsBeingBuilt() const;
48
49 // Returns if this blob is broken, and there is no data associated with it.
50 // Must be called on IO thread.
51 bool IsBroken() const;
52
53 // 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
55 // immediately on the current message loop (i.e. IO thread).
56 // Must be called on IO thread. Returns if construction successful.
57 // Calling this multiple times results in registering multiple
58 // completion callbacks.
59 void RunOnConstructionComplete(const base::Callback<void(bool)>& done);
60
43 // A BlobReader is used to read the data from the blob. This object is 61 // A BlobReader is used to read the data from the blob. This object is
44 // intended to be transient and should not be stored for any extended period 62 // intended to be transient and should not be stored for any extended period
45 // of time. 63 // of time.
46 scoped_ptr<BlobReader> CreateReader( 64 scoped_ptr<BlobReader> CreateReader(
47 FileSystemContext* file_system_context, 65 FileSystemContext* file_system_context,
48 base::SequencedTaskRunner* file_task_runner) const; 66 base::SequencedTaskRunner* file_task_runner) const;
49 67
50 // May be accessed on any thread. 68 // May be accessed on any thread.
51 const std::string& uuid() const; 69 const std::string& uuid() const;
52 // May be accessed on any thread. 70 // May be accessed on any thread.
53 const std::string& content_type() const; 71 const std::string& content_type() const;
54 // May be accessed on any thread. 72 // May be accessed on any thread.
55 const std::string& content_disposition() const; 73 const std::string& content_disposition() const;
56 74
57 // This call and the destruction of the returned snapshot must be called 75 // This call and the destruction of the returned snapshot must be called
58 // on the IO thread. 76 // on the IO thread. If the blob is broken, then we return a nullptr here.
77 // Please do not call this, and use CreateReader instead. It appropriately
78 // waits until the blob is built before having a size (see CalculateSize).
59 // TODO(dmurph): Make this protected, where only the BlobReader can call it. 79 // TODO(dmurph): Make this protected, where only the BlobReader can call it.
60 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; 80 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
61 81
62 private: 82 private:
63 // Internal class whose destructor is guarenteed to be called on the IO 83 // Internal class whose destructor is guarenteed to be called on the IO
64 // thread. 84 // thread.
65 class BlobDataHandleShared 85 class BlobDataHandleShared
66 : public base::RefCountedThreadSafe<BlobDataHandleShared> { 86 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
67 public: 87 public:
68 BlobDataHandleShared(const std::string& uuid, 88 BlobDataHandleShared(const std::string& uuid,
69 const std::string& content_type, 89 const std::string& content_type,
70 const std::string& content_disposition, 90 const std::string& content_disposition,
71 BlobStorageContext* context); 91 BlobStorageContext* context);
72 92
93 void RunOnConstructionComplete(const base::Callback<void(bool)>& done);
94
73 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; 95 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
74 96
75 private: 97 private:
76 friend class base::DeleteHelper<BlobDataHandleShared>; 98 friend class base::DeleteHelper<BlobDataHandleShared>;
77 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; 99 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
78 friend class BlobDataHandle; 100 friend class BlobDataHandle;
79 101
80 virtual ~BlobDataHandleShared(); 102 virtual ~BlobDataHandleShared();
81 103
82 const std::string uuid_; 104 const std::string uuid_;
(...skipping 11 matching lines...) Expand all
94 BlobStorageContext* context, 116 BlobStorageContext* context,
95 base::SequencedTaskRunner* io_task_runner); 117 base::SequencedTaskRunner* io_task_runner);
96 118
97 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 119 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
98 scoped_refptr<BlobDataHandleShared> shared_; 120 scoped_refptr<BlobDataHandleShared> shared_;
99 }; 121 };
100 122
101 } // namespace storage 123 } // namespace storage
102 124
103 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ 125 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698