| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ | |
| 6 #define WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/hash_tables.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/process.h" | |
| 14 #include "webkit/blob/blob_data.h" | |
| 15 #include "webkit/storage/webkit_storage_export.h" | |
| 16 | |
| 17 class GURL; | |
| 18 | |
| 19 namespace base { | |
| 20 class FilePath; | |
| 21 class Time; | |
| 22 } | |
| 23 | |
| 24 namespace webkit_blob { | |
| 25 | |
| 26 // This class handles the logistics of blob Storage within the browser process. | |
| 27 class WEBKIT_STORAGE_EXPORT BlobStorageController { | |
| 28 public: | |
| 29 BlobStorageController(); | |
| 30 ~BlobStorageController(); | |
| 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 | |
| 40 private: | |
| 41 friend class ViewBlobInternalsJob; | |
| 42 | |
| 43 typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap; | |
| 44 typedef std::map<BlobData*, int> BlobDataUsageMap; | |
| 45 | |
| 46 void AppendStorageItems(BlobData* target_blob_data, | |
| 47 BlobData* src_blob_data, | |
| 48 uint64 offset, | |
| 49 uint64 length); | |
| 50 void AppendFileItem(BlobData* target_blob_data, | |
| 51 const base::FilePath& file_path, uint64 offset, | |
| 52 uint64 length, | |
| 53 const base::Time& expected_modification_time); | |
| 54 void AppendFileSystemFileItem( | |
| 55 BlobData* target_blob_data, | |
| 56 const GURL& url, uint64 offset, uint64 length, | |
| 57 const base::Time& expected_modification_time); | |
| 58 | |
| 59 bool RemoveFromMapHelper(BlobMap* map, const GURL& url); | |
| 60 | |
| 61 void IncrementBlobDataUsage(BlobData* blob_data); | |
| 62 // Returns true if no longer in use. | |
| 63 bool DecrementBlobDataUsage(BlobData* blob_data); | |
| 64 | |
| 65 BlobMap blob_map_; | |
| 66 BlobMap unfinalized_blob_map_; | |
| 67 | |
| 68 // 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 | |
| 70 // items of TYPE_FILE. | |
| 71 int64 memory_usage_; | |
| 72 | |
| 73 // Multiple urls can refer to the same blob data, this map keeps track of | |
| 74 // how many urls refer to a BlobData. | |
| 75 BlobDataUsageMap blob_data_usage_count_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(BlobStorageController); | |
| 78 }; | |
| 79 | |
| 80 } // namespace webkit_blob | |
| 81 | |
| 82 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ | |
| OLD | NEW |