| OLD | NEW |
| 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_CONTROLLER_H_ |
| 6 #define WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ | 6 #define WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 8 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 9 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 10 #include "base/process.h" | 13 #include "base/process.h" |
| 14 #include "webkit/blob/blob_data.h" |
| 11 | 15 |
| 12 class GURL; | 16 class GURL; |
| 13 class FilePath; | 17 class FilePath; |
| 14 | 18 |
| 15 namespace base { | 19 namespace base { |
| 16 class Time; | 20 class Time; |
| 17 } | 21 } |
| 18 namespace net { | 22 namespace net { |
| 19 class UploadData; | 23 class UploadData; |
| 20 } | 24 } |
| 21 | 25 |
| 22 namespace webkit_blob { | 26 namespace webkit_blob { |
| 23 | 27 |
| 24 class BlobData; | |
| 25 | |
| 26 // This class handles the logistics of blob Storage within the browser process. | 28 // This class handles the logistics of blob Storage within the browser process. |
| 27 class BlobStorageController { | 29 class BlobStorageController { |
| 28 public: | 30 public: |
| 29 BlobStorageController(); | 31 BlobStorageController(); |
| 30 ~BlobStorageController(); | 32 ~BlobStorageController(); |
| 31 | 33 |
| 32 void RegisterBlobUrl(const GURL& url, const BlobData* blob_data); | 34 void StartBuildingBlob(const GURL& url); |
| 33 void RegisterBlobUrlFrom(const GURL& url, const GURL& src_url); | 35 void AppendBlobDataItem(const GURL& url, const BlobData::Item& data_item); |
| 34 void UnregisterBlobUrl(const GURL& url); | 36 void FinishBuildingBlob(const GURL& url, const std::string& content_type); |
| 37 void AddFinishedBlob(const GURL& url, const BlobData* blob_data); |
| 38 void CloneBlob(const GURL& url, const GURL& src_url); |
| 39 void RemoveBlob(const GURL& url); |
| 35 BlobData* GetBlobDataFromUrl(const GURL& url); | 40 BlobData* GetBlobDataFromUrl(const GURL& url); |
| 36 | 41 |
| 37 // If there is any blob reference in the upload data, it will get resolved | 42 // If there is any blob reference in the upload data, it will get resolved |
| 38 // and updated in place. | 43 // and updated in place. |
| 39 void ResolveBlobReferencesInUploadData(net::UploadData* upload_data); | 44 void ResolveBlobReferencesInUploadData(net::UploadData* upload_data); |
| 40 | 45 |
| 41 private: | 46 private: |
| 42 friend class ViewBlobInternalsJob; | 47 friend class ViewBlobInternalsJob; |
| 43 | 48 |
| 49 typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap; |
| 50 typedef std::map<BlobData*, int> BlobDataUsageMap; |
| 51 |
| 44 void AppendStorageItems(BlobData* target_blob_data, | 52 void AppendStorageItems(BlobData* target_blob_data, |
| 45 BlobData* src_blob_data, | 53 BlobData* src_blob_data, |
| 46 uint64 offset, | 54 uint64 offset, |
| 47 uint64 length); | 55 uint64 length); |
| 48 void AppendFileItem(BlobData* target_blob_data, | 56 void AppendFileItem(BlobData* target_blob_data, |
| 49 const FilePath& file_path, uint64 offset, uint64 length, | 57 const FilePath& file_path, uint64 offset, uint64 length, |
| 50 const base::Time& expected_modification_time); | 58 const base::Time& expected_modification_time); |
| 51 | 59 |
| 52 typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap; | 60 bool RemoveFromMapHelper(BlobMap* map, const GURL& url); |
| 61 |
| 62 void IncrementBlobDataUsage(BlobData* blob_data); |
| 63 // Returns true if no longer in use. |
| 64 bool DecrementBlobDataUsage(BlobData* blob_data); |
| 65 |
| 53 BlobMap blob_map_; | 66 BlobMap blob_map_; |
| 67 BlobMap unfinalized_blob_map_; |
| 68 |
| 69 // Used to keep track of how much memory is being utitlized for blob data, |
| 70 // we count only the items of TYPE_DATA which are held in memory and not |
| 71 // items of TYPE_FILE. |
| 72 int64 memory_usage_; |
| 73 |
| 74 // Multiple urls can refer to the same blob data, this map keeps track of |
| 75 // how many urls refer to a BlobData. |
| 76 BlobDataUsageMap blob_data_usage_count_; |
| 54 | 77 |
| 55 DISALLOW_COPY_AND_ASSIGN(BlobStorageController); | 78 DISALLOW_COPY_AND_ASSIGN(BlobStorageController); |
| 56 }; | 79 }; |
| 57 | 80 |
| 58 } // namespace webkit_blob | 81 } // namespace webkit_blob |
| 59 | 82 |
| 60 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ | 83 #endif // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_ |
| OLD | NEW |