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

Side by Side Diff: webkit/blob/blob_storage_context.h

Issue 11410019: ********** Chromium Blob hacking (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ 5 #ifndef WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_
6 #define WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ 6 #define WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set>
9 #include <string> 10 #include <string>
11 #include <utility>
10 12
11 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/gtest_prod_util.h"
12 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
13 #include "base/process.h" 16 #include "base/process.h"
17 #include "base/shared_memory.h"
18 #include "base/supports_user_data.h"
14 #include "webkit/blob/blob_data.h" 19 #include "webkit/blob/blob_data.h"
15 #include "webkit/storage/webkit_storage_export.h" 20 #include "webkit/storage/webkit_storage_export.h"
16 21
17 class GURL; 22 class GURL;
18 class FilePath; 23 class FilePath;
19 24
20 namespace base { 25 namespace base {
26 class SequencedTaskRunner;
21 class Time; 27 class Time;
22 } 28 }
23 29
30 namespace webkit_glue {
31 FORWARD_DECLARE_TEST(ResourceRequestBodyTest, ResolveBlobAndCreateUploadData);
32 }
33
24 namespace webkit_blob { 34 namespace webkit_blob {
25 35
26 // This class handles the logistics of blob Storage within the browser process. 36 class BlobDataHandle;
27 class WEBKIT_STORAGE_EXPORT BlobStorageController { 37 class BlobStorageConsumer;
38 class BlobStorageContext;
39
40 class WEBKIT_STORAGE_EXPORT BlobDataHandle
41 : public base::SupportsUserData::Data {
28 public: 42 public:
29 BlobStorageController(); 43 virtual ~BlobDataHandle(); // Maybe be deleted on any thread.
30 ~BlobStorageController(); 44 BlobData* data() const; // May only be accessed on the IO thread.
31
32 void StartBuildingBlob(const GURL& url);
33 void AppendBlobDataItem(const GURL& url, const BlobData::Item& data_item);
34 void FinishBuildingBlob(const GURL& url, const std::string& content_type);
35 void AddFinishedBlob(const GURL& url, const BlobData* blob_data);
36 void CloneBlob(const GURL& url, const GURL& src_url);
37 void RemoveBlob(const GURL& url);
38 BlobData* GetBlobDataFromUrl(const GURL& url);
39 45
40 private: 46 private:
47 friend class BlobStorageContext;
48 BlobDataHandle(BlobData* blob_data, BlobStorageContext* context,
49 base::SequencedTaskRunner* task_runner);
50
51 scoped_refptr<BlobData> blob_data_;
52 BlobStorageContext* context_; // weakptr | refptr?
53 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
54 };
55
56 // This class handles the logistics of blob storage for a single child process.
57 // There is one generally instance per child process. When the child process
58 // terminates all blob references attibutable to that process go away upon
59 // destruction of the instance.
60 class WEBKIT_STORAGE_EXPORT BlobStorageConsumer {
61 public:
62 explicit BlobStorageConsumer(BlobStorageContext* context);
63 ~BlobStorageConsumer();
64
65 // Methods to support the IPC message protocol.
66 void StartBuildingBlob(const std::string& uuid);
67 void AppendBlobDataItem(const std::string& uuid,
68 const BlobData::Item& data_item);
69 void CancelBuildingBlob(const std::string& uuid);
70 void FinishBuildingBlob(const std::string& uuid, const std::string& type);
71 void IncrementBlobRefCount(const std::string& uuid);
72 void DecrementBlobRefCount(const std::string& uuid);
73 void RegisterPublicBlobURL(const GURL& blob_url, const std::string& uuid);
74 void RevokePublicBlobURL(const GURL& blob_url);
75
76 private:
77 typedef std::map<std::string, int> BlobReferenceMap;
78
79 // Collection of blob ids and a count of how many usages
80 // of that id are attributable to this consumer.
81 BlobReferenceMap blobs_inuse_map_;
82
83 // The set of public blob urls coined by this consumer.
84 std::set<GURL> public_blob_urls_;
85
86 BlobStorageContext* context_; // weakptr | refptr?
87 };
88
89 // This class handles the logistics of blob Storage within the browser process,
90 // and mapping from blob uuid to the data.
91 // In chromium, there is one instance per storage-partition.
92 class WEBKIT_STORAGE_EXPORT BlobStorageContext {
93 public:
94 BlobStorageContext();
95 ~BlobStorageContext();
96
97 scoped_ptr<BlobDataHandle> GetBlobDataFromUUID(const std::string& uuid);
98 scoped_ptr<BlobDataHandle> GetBlobDataFromPublicUrl(const GURL& url);
99
100 private:
101 friend class BlobDataHandle;
102 friend class BlobStorageConsumer;
41 friend class ViewBlobInternalsJob; 103 friend class ViewBlobInternalsJob;
104 friend class TestShellWebBlobRegistryImpl;
105 friend class ScopedTextBlob;
106 FRIEND_TEST_ALL_PREFIXES(webkit_glue::ResourceRequestBodyTest, ResolveBlobAndC reateUploadData);
42 107
43 typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap; 108 typedef std::map<std::string, std::pair<int, scoped_refptr<BlobData> > >
44 typedef std::map<BlobData*, int> BlobDataUsageMap; 109 BlobMap;
110 typedef std::map<GURL, std::string> BlobURLMap;
111
112 void StartBuildingBlob(const std::string& uuid);
113 void AppendBlobDataItem(const std::string& uuid,
114 const BlobData::Item& data_item);
115 void FinishBuildingBlob(const std::string& uuid, const std::string& type);
116 void CancelBuildingBlob(const std::string& uuid);
117 void AddFinishedBlob(const BlobData* blob_data);
118 void IncrementBlobRefCount(const std::string& uuid);
119 void DecrementBlobRefCount(const std::string& uuid);
120 void RegisterPublicBlobURL(const GURL& url, const std::string& uuid);
121 void RevokePublicBlobURL(const GURL& url);
45 122
46 void AppendStorageItems(BlobData* target_blob_data, 123 void AppendStorageItems(BlobData* target_blob_data,
47 BlobData* src_blob_data, 124 BlobData* src_blob_data,
48 uint64 offset, 125 uint64 offset,
49 uint64 length); 126 uint64 length);
50 void AppendFileItem(BlobData* target_blob_data, 127 void AppendFileItem(BlobData* target_blob_data,
51 const FilePath& file_path, uint64 offset, uint64 length, 128 const FilePath& file_path, uint64 offset, uint64 length,
52 const base::Time& expected_modification_time); 129 const base::Time& expected_modification_time);
53 void AppendFileSystemFileItem( 130 void AppendFileSystemFileItem(
54 BlobData* target_blob_data, 131 BlobData* target_blob_data,
55 const GURL& url, uint64 offset, uint64 length, 132 const GURL& url, uint64 offset, uint64 length,
56 const base::Time& expected_modification_time); 133 const base::Time& expected_modification_time);
57 134
58 bool RemoveFromMapHelper(BlobMap* map, const GURL& url); 135 bool DecrementBlobRefCountHelper(BlobMap* map, const std::string& uuid);
59
60 void IncrementBlobDataUsage(BlobData* blob_data);
61 // Returns true if no longer in use.
62 bool DecrementBlobDataUsage(BlobData* blob_data);
63 136
64 BlobMap blob_map_; 137 BlobMap blob_map_;
65 BlobMap unfinalized_blob_map_; 138 BlobMap unfinalized_blob_map_;
139 BlobURLMap public_blob_urls_;
66 140
67 // Used to keep track of how much memory is being utitlized for blob data, 141 // Used to keep track of how much memory is being utitlized for blob data,
68 // we count only the items of TYPE_DATA which are held in memory and not 142 // we count only the items of TYPE_DATA which are held in memory and not
69 // items of TYPE_FILE. 143 // items of TYPE_FILE.
70 int64 memory_usage_; 144 int64 memory_usage_;
71 145
72 // Multiple urls can refer to the same blob data, this map keeps track of 146 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext);
73 // how many urls refer to a BlobData.
74 BlobDataUsageMap blob_data_usage_count_;
75
76 DISALLOW_COPY_AND_ASSIGN(BlobStorageController);
77 }; 147 };
78 148
79 } // namespace webkit_blob 149 } // namespace webkit_blob
80 150
81 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ 151 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698