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

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

Issue 1337153002: [Blob] BlobReader class & tests, and removal of all redundant reading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windows fix Created 5 years, 3 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/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;
18 class SingleThreadTaskRunner;
17 } 19 }
18 20
19 namespace storage { 21 namespace storage {
20 22
21 class BlobDataSnapshot; 23 class BlobDataSnapshot;
24 class BlobReader;
22 class BlobStorageContext; 25 class BlobStorageContext;
26 class FileSystemContext;
23 27
24 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains 28 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains
25 // in the BlobStorageContext's collection while this object is alive. Anything 29 // in the BlobStorageContext's collection while this object is alive. Anything
26 // that needs to keep a blob alive needs to store this handle. 30 // 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() 31 // 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 32 // 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 33 // 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 34 // 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. 35 // 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. 36 // This object has delete semantics and may be deleted on any thread.
33 class STORAGE_EXPORT BlobDataHandle 37 class STORAGE_EXPORT BlobDataHandle
34 : public base::SupportsUserData::Data { 38 : public base::SupportsUserData::Data {
35 public: 39 public:
36 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. 40 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
37 ~BlobDataHandle() override; // May be deleted on any thread. 41 ~BlobDataHandle() override; // May be deleted on any thread.
38 42
39 // A BlobDataSnapshot is used to read the data from the blob. This object is 43 // 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 44 // intended to be transient and should not be stored for any extended period
41 // of time. 45 // of time.
46 scoped_ptr<BlobReader> CreateReader(
47 FileSystemContext* file_system_context,
48 base::SingleThreadTaskRunner* file_task_runner) const;
michaeln 2015/09/17 00:45:37 Does this really need to be a SingleThreadTaskRunn
dmurph 2015/09/19 00:33:43 Sure.
49
50 // May be accessed on any thread.
51 const std::string& uuid() const;
52 // May be accessed on any thread.
53 const std::string& content_type() const;
54 // May be accessed on any thread.
55 const std::string& content_disposition() const;
56
42 // This call and the destruction of the returned snapshot must be called 57 // This call and the destruction of the returned snapshot must be called
43 // on the IO thread. 58 // on the IO thread.
59 // TODO(dmurph): Make this protected, where only the BlobReader can call it.
44 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; 60 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
45 61
46 const std::string& uuid() const; // May be accessed on any thread.
47
48 private: 62 private:
49 // Internal class whose destructor is guarenteed to be called on the IO 63 // Internal class whose destructor is guarenteed to be called on the IO
50 // thread. 64 // thread.
51 class BlobDataHandleShared 65 class BlobDataHandleShared
52 : public base::RefCountedThreadSafe<BlobDataHandleShared> { 66 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
53 public: 67 public:
54 BlobDataHandleShared(const std::string& uuid, 68 BlobDataHandleShared(const std::string& uuid,
55 BlobStorageContext* context, 69 const std::string& content_type,
56 base::SequencedTaskRunner* task_runner); 70 const std::string& content_disposition,
71 BlobStorageContext* context);
57 72
58 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const; 73 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
59 const std::string& uuid() const;
60 74
61 private: 75 private:
62 friend class base::DeleteHelper<BlobDataHandleShared>; 76 friend class base::DeleteHelper<BlobDataHandleShared>;
63 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; 77 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
64 friend class BlobDataHandle; 78 friend class BlobDataHandle;
65 79
66 virtual ~BlobDataHandleShared(); 80 virtual ~BlobDataHandleShared();
67 81
68 const std::string uuid_; 82 const std::string uuid_;
83 const std::string content_type_;
84 const std::string content_disposition_;
69 base::WeakPtr<BlobStorageContext> context_; 85 base::WeakPtr<BlobStorageContext> context_;
70 86
71 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); 87 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
72 }; 88 };
73 89
74 friend class BlobStorageContext; 90 friend class BlobStorageContext;
75 BlobDataHandle(const std::string& uuid, 91 BlobDataHandle(const std::string& uuid,
92 const std::string& content_type,
93 const std::string& content_disposition,
76 BlobStorageContext* context, 94 BlobStorageContext* context,
77 base::SequencedTaskRunner* task_runner); 95 base::SequencedTaskRunner* task_runner);
78 96
79 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 97 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
80 scoped_refptr<BlobDataHandleShared> shared_; 98 scoped_refptr<BlobDataHandleShared> shared_;
81 }; 99 };
82 100
83 } // namespace storage 101 } // namespace storage
84 102
85 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ 103 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698