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

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

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Snapshots now created by the Handle, one more rename Created 5 years, 11 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/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/supports_user_data.h" 12 #include "base/supports_user_data.h"
13 #include "storage/browser/storage_browser_export.h" 13 #include "storage/browser/storage_browser_export.h"
14 14
15 namespace base { 15 namespace base {
16 class SequencedTaskRunner; 16 class SequencedTaskRunner;
17 } 17 }
18 18
19 namespace storage { 19 namespace storage {
20 20
21 class BlobData; 21 class BlobDataSnapshot;
22 class BlobStorageContext; 22 class BlobStorageContext;
23 23
24 // A scoper object for use in chrome's main browser process, ensures 24 // BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains
25 // the underlying BlobData and its uuid remain in BlobStorageContext's 25 // in the BlobStorageContext's collection while this object is alive. Anything
26 // collection for the duration. This object has delete semantics and 26 // that needs to keep a blob alive needs to store this handle.
27 // maybe deleted on any thread. 27 // 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
29 // 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
31 // can be read on any thread.
32 // This object has delete semantics and may be deleted on any thread.
28 class STORAGE_EXPORT BlobDataHandle 33 class STORAGE_EXPORT BlobDataHandle
29 : public base::SupportsUserData::Data { 34 : public base::SupportsUserData::Data {
30 public: 35 public:
31 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. 36 BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread.
32 ~BlobDataHandle() override; // Maybe be deleted on any thread. 37 ~BlobDataHandle() override; // May be deleted on any thread.
33 BlobData* data() const; // May only be accessed on the IO thread.
34 38
35 std::string uuid() const; // May be accessed on any thread. 39 // This must be called on the IO thread, but the snapshot can be accessed
40 // from any thread.
41 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
42
43 const std::string& uuid() const; // May be accessed on any thread.
36 44
37 private: 45 private:
46 // Internal class whose destructor is guarenteed to be called on the IO
47 // thread.
38 class BlobDataHandleShared 48 class BlobDataHandleShared
39 : public base::RefCountedThreadSafe<BlobDataHandleShared> { 49 : public base::RefCountedThreadSafe<BlobDataHandleShared> {
40 public: 50 public:
41 BlobDataHandleShared(BlobData* blob_data, 51 BlobDataHandleShared(const std::string& uuid,
42 BlobStorageContext* context, 52 BlobStorageContext* context,
43 base::SequencedTaskRunner* task_runner); 53 base::SequencedTaskRunner* task_runner);
44 54
45 BlobData* data() const; 55 scoped_ptr<BlobDataSnapshot> CreateSnapshot() const;
46 const std::string& uuid() const; 56 const std::string& uuid() const;
47 57
48 private: 58 private:
49 friend class base::DeleteHelper<BlobDataHandleShared>; 59 friend class base::DeleteHelper<BlobDataHandleShared>;
50 friend class base::RefCountedThreadSafe<BlobDataHandleShared>; 60 friend class base::RefCountedThreadSafe<BlobDataHandleShared>;
51 friend class BlobDataHandle; 61 friend class BlobDataHandle;
52 62
53 virtual ~BlobDataHandleShared(); 63 virtual ~BlobDataHandleShared();
54 64
55 scoped_refptr<BlobData> blob_data_; 65 const std::string uuid_;
56 base::WeakPtr<BlobStorageContext> context_; 66 base::WeakPtr<BlobStorageContext> context_;
57 67
58 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); 68 DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared);
59 }; 69 };
60 70
61 friend class BlobStorageContext; 71 friend class BlobStorageContext;
62 BlobDataHandle(BlobData* blob_data, BlobStorageContext* context, 72 BlobDataHandle(const std::string& uuid,
73 BlobStorageContext* context,
63 base::SequencedTaskRunner* task_runner); 74 base::SequencedTaskRunner* task_runner);
64 75
65 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; 76 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
66 scoped_refptr<BlobDataHandleShared> shared_; 77 scoped_refptr<BlobDataHandleShared> shared_;
67 }; 78 };
68 79
69 } // namespace storage 80 } // namespace storage
70 81
71 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_ 82 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698