| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 5 #ifndef CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
| 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 6 #define CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 class DOMStorageTaskRunner; | 27 class DOMStorageTaskRunner; |
| 28 class SessionStorageDatabase; | 28 class SessionStorageDatabase; |
| 29 | 29 |
| 30 // Container for the set of per-origin Areas. | 30 // Container for the set of per-origin Areas. |
| 31 // See class comments for DOMStorageContextImpl for a larger overview. | 31 // See class comments for DOMStorageContextImpl for a larger overview. |
| 32 class CONTENT_EXPORT DOMStorageNamespace | 32 class CONTENT_EXPORT DOMStorageNamespace |
| 33 : public base::RefCountedThreadSafe<DOMStorageNamespace> { | 33 : public base::RefCountedThreadSafe<DOMStorageNamespace> { |
| 34 public: | 34 public: |
| 35 // Option for PurgeMemory. | 35 // Option for PurgeMemory. |
| 36 enum PurgeOption { | 36 enum PurgeOption { |
| 37 // Determines is purging is required based on the usage and the platform. |
| 38 PURGE_IF_NEEDED, |
| 39 |
| 37 // Purge unopened areas only. | 40 // Purge unopened areas only. |
| 38 PURGE_UNOPENED, | 41 PURGE_UNOPENED, |
| 39 | 42 |
| 40 // Purge aggressively, i.e. discard cache even for areas that have | 43 // Purge aggressively, i.e. discard cache even for areas that have |
| 41 // non-zero open count. | 44 // non-zero open count. |
| 42 PURGE_AGGRESSIVE, | 45 PURGE_AGGRESSIVE, |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 // Constructor for a LocalStorage namespace with id of 0 | 48 // Constructor for a LocalStorage namespace with id of 0 |
| 46 // and an optional backing directory on disk. | 49 // and an optional backing directory on disk. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 73 // Should only be called for session storage namespaces. | 76 // Should only be called for session storage namespaces. |
| 74 DOMStorageNamespace* Clone(int64_t clone_namespace_id, | 77 DOMStorageNamespace* Clone(int64_t clone_namespace_id, |
| 75 const std::string& clone_persistent_namespace_id); | 78 const std::string& clone_persistent_namespace_id); |
| 76 | 79 |
| 77 void DeleteLocalStorageOrigin(const GURL& origin); | 80 void DeleteLocalStorageOrigin(const GURL& origin); |
| 78 void DeleteSessionStorageOrigin(const GURL& origin); | 81 void DeleteSessionStorageOrigin(const GURL& origin); |
| 79 void PurgeMemory(PurgeOption purge); | 82 void PurgeMemory(PurgeOption purge); |
| 80 void Shutdown(); | 83 void Shutdown(); |
| 81 void Flush(); | 84 void Flush(); |
| 82 | 85 |
| 83 unsigned int CountInMemoryAreas() const; | |
| 84 | |
| 85 // Adds memory statistics to |pmd| for chrome://tracing. | 86 // Adds memory statistics to |pmd| for chrome://tracing. |
| 86 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd); | 87 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd); |
| 87 | 88 |
| 88 void GetOriginsWithAreas(std::vector<GURL>* origins) const; | 89 void GetOriginsWithAreas(std::vector<GURL>* origins) const; |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 friend class base::RefCountedThreadSafe<DOMStorageNamespace>; | 92 friend class base::RefCountedThreadSafe<DOMStorageNamespace>; |
| 92 | 93 |
| 93 // Struct to hold references to our contained areas and | 94 // Struct to hold references to our contained areas and |
| 94 // to keep track of how many tabs have a given area open. | 95 // to keep track of how many tabs have a given area open. |
| 95 struct AreaHolder { | 96 struct AreaHolder { |
| 96 scoped_refptr<DOMStorageArea> area_; | 97 scoped_refptr<DOMStorageArea> area_; |
| 97 int open_count_; | 98 int open_count_; |
| 98 AreaHolder(); | 99 AreaHolder(); |
| 99 AreaHolder(DOMStorageArea* area, int count); | 100 AreaHolder(DOMStorageArea* area, int count); |
| 100 AreaHolder(const AreaHolder& other); | 101 AreaHolder(const AreaHolder& other); |
| 101 ~AreaHolder(); | 102 ~AreaHolder(); |
| 102 }; | 103 }; |
| 103 typedef std::map<GURL, AreaHolder> AreaMap; | 104 typedef std::map<GURL, AreaHolder> AreaMap; |
| 104 | 105 |
| 105 ~DOMStorageNamespace(); | 106 ~DOMStorageNamespace(); |
| 106 | 107 |
| 107 // Returns a pointer to the area holder in our map or NULL. | 108 // Returns a pointer to the area holder in our map or NULL. |
| 108 AreaHolder* GetAreaHolder(const GURL& origin); | 109 AreaHolder* GetAreaHolder(const GURL& origin); |
| 109 | 110 |
| 111 // Helper to determine is purging is needed based on the usage and the |
| 112 // platform. |
| 113 bool ShouldPurgeMemory(); |
| 114 |
| 110 int64_t namespace_id_; | 115 int64_t namespace_id_; |
| 111 std::string persistent_namespace_id_; | 116 std::string persistent_namespace_id_; |
| 112 base::FilePath directory_; | 117 base::FilePath directory_; |
| 113 AreaMap areas_; | 118 AreaMap areas_; |
| 114 scoped_refptr<DOMStorageTaskRunner> task_runner_; | 119 scoped_refptr<DOMStorageTaskRunner> task_runner_; |
| 115 scoped_refptr<SessionStorageDatabase> session_storage_database_; | 120 scoped_refptr<SessionStorageDatabase> session_storage_database_; |
| 121 bool is_low_end_device_; |
| 116 }; | 122 }; |
| 117 | 123 |
| 118 } // namespace content | 124 } // namespace content |
| 119 | 125 |
| 120 | 126 |
| 121 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ | 127 #endif // CONTENT_BROWSER_DOM_STORAGE_DOM_STORAGE_NAMESPACE_H_ |
| OLD | NEW |