| 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 CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ |
| 6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ | 6 #define CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 | 11 |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "content/browser/resource_context.h" |
| 16 | 17 |
| 17 class DOMStorageArea; | 18 class DOMStorageArea; |
| 18 class DOMStorageMessageFilter; | 19 class DOMStorageMessageFilter; |
| 19 class DOMStorageNamespace; | 20 class DOMStorageNamespace; |
| 20 class WebKitContext; | 21 class WebKitContext; |
| 21 | 22 |
| 22 namespace quota { | 23 namespace quota { |
| 23 class SpecialStoragePolicy; | 24 class SpecialStoragePolicy; |
| 24 } | 25 } |
| 25 | 26 |
| 26 // This is owned by WebKitContext and is all the dom storage information that's | 27 // This is owned by WebKitContext and is all the dom storage information that's |
| 27 // shared by all the DOMStorageMessageFilters that share the same profile. The | 28 // shared by all the DOMStorageMessageFilters that share the same profile. The |
| 28 // specifics of responsibilities are fairly well documented here and in | 29 // specifics of responsibilities are fairly well documented here and in |
| 29 // StorageNamespace and StorageArea. Everything is only to be accessed on the | 30 // StorageNamespace and StorageArea. Everything is only to be accessed on the |
| 30 // WebKit thread unless noted otherwise. | 31 // WebKit thread unless noted otherwise. |
| 31 // | 32 // |
| 32 // NOTE: Virtual methods facilitate mocking functions for testing. | 33 // NOTE: Virtual methods facilitate mocking functions for testing. |
| 33 class DOMStorageContext { | 34 class DOMStorageContext { |
| 34 public: | 35 public: |
| 35 DOMStorageContext(WebKitContext* webkit_context, | 36 DOMStorageContext(WebKitContext* webkit_context, |
| 36 quota::SpecialStoragePolicy* special_storage_policy); | 37 quota::SpecialStoragePolicy* special_storage_policy, |
| 38 const content::ResourceContext& resource_context); |
| 37 virtual ~DOMStorageContext(); | 39 virtual ~DOMStorageContext(); |
| 38 | 40 |
| 39 // Invalid storage id. No storage session will ever report this value. | 41 // Invalid storage id. No storage session will ever report this value. |
| 40 // Used in DOMStorageMessageFilter::OnStorageAreaId when coping with | 42 // Used in DOMStorageMessageFilter::OnStorageAreaId when coping with |
| 41 // interactions with non-existent storage sessions. | 43 // interactions with non-existent storage sessions. |
| 42 static const int64 kInvalidStorageId = -1; | 44 static const int64 kInvalidStorageId = -1; |
| 43 | 45 |
| 44 // Allocate a new storage area id. Only call on the WebKit thread. | 46 // Allocate a new storage area id. Only call on the WebKit thread. |
| 45 int64 AllocateStorageAreaId(); | 47 int64 AllocateStorageAreaId(); |
| 46 | 48 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 102 |
| 101 void set_clear_local_state_on_exit_(bool clear_local_state) { | 103 void set_clear_local_state_on_exit_(bool clear_local_state) { |
| 102 clear_local_state_on_exit_ = clear_local_state; | 104 clear_local_state_on_exit_ = clear_local_state; |
| 103 } | 105 } |
| 104 | 106 |
| 105 #ifdef UNIT_TEST | 107 #ifdef UNIT_TEST |
| 106 // For unit tests allow to override the |data_path_|. | 108 // For unit tests allow to override the |data_path_|. |
| 107 void set_data_path(const FilePath& data_path) { data_path_ = data_path; } | 109 void set_data_path(const FilePath& data_path) { data_path_ = data_path; } |
| 108 #endif | 110 #endif |
| 109 | 111 |
| 112 const content::ResourceContext& GetResourceContext() const { |
| 113 return resource_context_; |
| 114 } |
| 115 |
| 110 private: | 116 private: |
| 111 // Get the local storage instance. The object is owned by this class. | 117 // Get the local storage instance. The object is owned by this class. |
| 112 DOMStorageNamespace* CreateLocalStorage(); | 118 DOMStorageNamespace* CreateLocalStorage(); |
| 113 | 119 |
| 114 // Get a new session storage namespace. The object is owned by this class. | 120 // Get a new session storage namespace. The object is owned by this class. |
| 115 DOMStorageNamespace* CreateSessionStorage(int64 namespace_id); | 121 DOMStorageNamespace* CreateSessionStorage(int64 namespace_id); |
| 116 | 122 |
| 117 // Used internally to register storage namespaces we create. | 123 // Used internally to register storage namespaces we create. |
| 118 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); | 124 void RegisterStorageNamespace(DOMStorageNamespace* storage_namespace); |
| 119 | 125 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 150 // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace | 156 // Maps ids to StorageAreas. We do NOT own these objects. StorageNamespace |
| 151 // (which does own them) will notify us when we should remove the entries. | 157 // (which does own them) will notify us when we should remove the entries. |
| 152 typedef std::map<int64, DOMStorageArea*> StorageAreaMap; | 158 typedef std::map<int64, DOMStorageArea*> StorageAreaMap; |
| 153 StorageAreaMap storage_area_map_; | 159 StorageAreaMap storage_area_map_; |
| 154 | 160 |
| 155 // Maps ids to StorageNamespaces. We own these objects. | 161 // Maps ids to StorageNamespaces. We own these objects. |
| 156 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap; | 162 typedef std::map<int64, DOMStorageNamespace*> StorageNamespaceMap; |
| 157 StorageNamespaceMap storage_namespace_map_; | 163 StorageNamespaceMap storage_namespace_map_; |
| 158 | 164 |
| 159 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; | 165 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
| 166 const content::ResourceContext& resource_context_; |
| 160 | 167 |
| 161 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContext); | 168 DISALLOW_IMPLICIT_CONSTRUCTORS(DOMStorageContext); |
| 162 }; | 169 }; |
| 163 | 170 |
| 164 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ | 171 #endif // CONTENT_BROWSER_IN_PROCESS_WEBKIT_DOM_STORAGE_CONTEXT_H_ |
| OLD | NEW |