OLD | NEW |
---|---|
1 // Copyright (c) 2011 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 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 <string> | 9 #include <string> |
10 | 10 |
11 #include "base/hash_tables.h" | |
12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
13 #include "base/process.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | |
14 #include "webkit/blob/blob_data.h" | 14 #include "webkit/blob/blob_data.h" |
15 #include "webkit/storage/webkit_storage_export.h" | 15 #include "webkit/storage/webkit_storage_export.h" |
16 | 16 |
17 class GURL; | 17 class GURL; |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class FilePath; | 20 class FilePath; |
21 class Time; | 21 class Time; |
22 } | 22 } |
23 | 23 |
24 namespace webkit_blob { | 24 namespace webkit_blob { |
25 | 25 |
26 // This class handles the logistics of blob Storage within the browser process. | 26 class BlobDataHandle; |
27 class WEBKIT_STORAGE_EXPORT BlobStorageController { | 27 |
28 // This class handles the logistics of blob Storage within the browser process, | |
29 // and maintains a mapping from blob uuid to the data. The class is single | |
30 // threaded and should only be used on the IO thread. | |
kinuko
2013/04/30 15:13:27
nit: extra space between 'should' and 'only'
michaeln
2013/04/30 18:14:07
Done.
| |
31 // In chromium, there is one instance per profile. | |
32 class WEBKIT_STORAGE_EXPORT BlobStorageContext | |
33 : public base::SupportsWeakPtr<BlobStorageContext> { | |
28 public: | 34 public: |
29 BlobStorageController(); | 35 BlobStorageContext(); |
30 ~BlobStorageController(); | 36 ~BlobStorageContext(); |
31 | 37 |
32 void StartBuildingBlob(const GURL& url); | 38 scoped_ptr<BlobDataHandle> GetBlobDataFromUUID(const std::string& uuid); |
33 void AppendBlobDataItem(const GURL& url, const BlobData::Item& data_item); | 39 scoped_ptr<BlobDataHandle> GetBlobDataFromPublicURL(const GURL& url); |
34 void FinishBuildingBlob(const GURL& url, const std::string& content_type); | 40 |
35 void AddFinishedBlob(const GURL& url, const BlobData* blob_data); | 41 // Useful for coining blobs from within the browser process. If the |
36 void CloneBlob(const GURL& url, const GURL& src_url); | 42 // blob cannot be added due to memory consumption, returns NULL. |
37 void RemoveBlob(const GURL& url); | 43 scoped_ptr<BlobDataHandle> AddFinishedBlob(const BlobData* blob_data); |
38 BlobData* GetBlobDataFromUrl(const GURL& url); | |
39 | 44 |
40 private: | 45 private: |
41 friend class ViewBlobInternalsJob; | 46 friend class BlobDataHandle; |
47 friend class BlobStorageHost; | |
42 | 48 |
43 typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap; | 49 enum EntryFlags { |
44 typedef std::map<BlobData*, int> BlobDataUsageMap; | 50 BEING_BUILT = 1 << 0, |
51 EXCEEDED_MEMORY = 1 << 1, | |
52 }; | |
45 | 53 |
46 void AppendStorageItems(BlobData* target_blob_data, | 54 struct BlobMapEntry { |
55 int refcount; | |
56 int flags; | |
57 scoped_refptr<BlobData> data; | |
58 | |
59 BlobMapEntry(); | |
60 BlobMapEntry(int refcount, int flags, BlobData* data); | |
61 ~BlobMapEntry(); | |
62 }; | |
63 | |
64 typedef std::map<std::string, BlobMapEntry> | |
65 BlobMap; | |
66 typedef std::map<GURL, std::string> BlobURLMap; | |
67 | |
68 void StartBuildingBlob(const std::string& uuid); | |
69 void AppendBlobDataItem(const std::string& uuid, | |
70 const BlobData::Item& data_item); | |
71 void FinishBuildingBlob(const std::string& uuid, const std::string& type); | |
72 void CancelBuildingBlob(const std::string& uuid); | |
73 void IncrementBlobRefCount(const std::string& uuid); | |
74 void DecrementBlobRefCount(const std::string& uuid); | |
75 void RegisterPublicBlobURL(const GURL& url, const std::string& uuid); | |
76 void RevokePublicBlobURL(const GURL& url); | |
77 | |
78 bool ExpandStorageItems(BlobData* target_blob_data, | |
47 BlobData* src_blob_data, | 79 BlobData* src_blob_data, |
48 uint64 offset, | 80 uint64 offset, |
49 uint64 length); | 81 uint64 length); |
82 bool AppendBytesItem(BlobData* target_blob_data, | |
83 const char* data, int64 length); | |
50 void AppendFileItem(BlobData* target_blob_data, | 84 void AppendFileItem(BlobData* target_blob_data, |
51 const base::FilePath& file_path, uint64 offset, | 85 const base::FilePath& file_path, |
52 uint64 length, | 86 uint64 offset, uint64 length, |
53 const base::Time& expected_modification_time); | 87 const base::Time& expected_modification_time); |
54 void AppendFileSystemFileItem( | 88 void AppendFileSystemFileItem( |
55 BlobData* target_blob_data, | 89 BlobData* target_blob_data, |
56 const GURL& url, uint64 offset, uint64 length, | 90 const GURL& url, uint64 offset, uint64 length, |
57 const base::Time& expected_modification_time); | 91 const base::Time& expected_modification_time); |
58 | 92 |
59 bool RemoveFromMapHelper(BlobMap* map, const GURL& url); | 93 bool IsInUse(const std::string& uuid); |
60 | 94 bool IsBeingBuilt(const std::string& uuid); |
61 void IncrementBlobDataUsage(BlobData* blob_data); | 95 bool IsUrlRegistered(const GURL& blob_url); |
62 // Returns true if no longer in use. | |
63 bool DecrementBlobDataUsage(BlobData* blob_data); | |
64 | 96 |
65 BlobMap blob_map_; | 97 BlobMap blob_map_; |
66 BlobMap unfinalized_blob_map_; | 98 BlobURLMap public_blob_urls_; |
67 | 99 |
68 // Used to keep track of how much memory is being utitlized for blob data, | 100 // Used to keep track of how much memory is being utitlized for blob data, |
69 // we count only the items of TYPE_DATA which are held in memory and not | 101 // we count only the items of TYPE_DATA which are held in memory and not |
70 // items of TYPE_FILE. | 102 // items of TYPE_FILE. |
71 int64 memory_usage_; | 103 int64 memory_usage_; |
72 | 104 |
73 // Multiple urls can refer to the same blob data, this map keeps track of | 105 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext); |
74 // how many urls refer to a BlobData. | |
75 BlobDataUsageMap blob_data_usage_count_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(BlobStorageController); | |
78 }; | 106 }; |
79 | 107 |
80 } // namespace webkit_blob | 108 } // namespace webkit_blob |
81 | 109 |
82 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ | 110 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_ |
OLD | NEW |