| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ | 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ |
| 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ | 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/atomic_sequence_num.h" | 12 #include "base/atomic_sequence_num.h" |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
| 17 #include "googleurl/src/gurl.h" |
| 16 | 18 |
| 17 class FilePath; | 19 class FilePath; |
| 18 class GURL; | |
| 19 class NullableString16; | 20 class NullableString16; |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class Time; | 23 class Time; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace quota { | 26 namespace quota { |
| 26 class SpecialStoragePolicy; | 27 class SpecialStoragePolicy; |
| 27 } | 28 } |
| 28 | 29 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 48 // Session Namespaces are cloned by initially making a shallow copy of | 49 // Session Namespaces are cloned by initially making a shallow copy of |
| 49 // all contained Areas, the shallow copies refer to the same refcounted Map, | 50 // all contained Areas, the shallow copies refer to the same refcounted Map, |
| 50 // and does a deep copy-on-write if needed. | 51 // and does a deep copy-on-write if needed. |
| 51 // | 52 // |
| 52 // Classes intended to be used by an embedder are DomStorageContext, | 53 // Classes intended to be used by an embedder are DomStorageContext, |
| 53 // DomStorageHost, and DomStorageSession. The other classes are for | 54 // DomStorageHost, and DomStorageSession. The other classes are for |
| 54 // internal consumption. | 55 // internal consumption. |
| 55 class DomStorageContext | 56 class DomStorageContext |
| 56 : public base::RefCountedThreadSafe<DomStorageContext> { | 57 : public base::RefCountedThreadSafe<DomStorageContext> { |
| 57 public: | 58 public: |
| 59 struct UsageInfo { |
| 60 GURL origin; |
| 61 size_t data_size; |
| 62 base::Time last_modified; |
| 63 |
| 64 UsageInfo(); |
| 65 ~UsageInfo(); |
| 66 }; |
| 67 |
| 58 // An interface for observing LocalStorage events on the | 68 // An interface for observing LocalStorage events on the |
| 59 // background thread. | 69 // background thread. |
| 60 class EventObserver { | 70 class EventObserver { |
| 61 public: | 71 public: |
| 62 virtual void OnDomStorageItemSet( | 72 virtual void OnDomStorageItemSet( |
| 63 const DomStorageArea* area, | 73 const DomStorageArea* area, |
| 64 const string16& key, | 74 const string16& key, |
| 65 const string16& new_value, | 75 const string16& new_value, |
| 66 const NullableString16& old_value, // may be null on initial insert | 76 const NullableString16& old_value, // may be null on initial insert |
| 67 const GURL& page_url) = 0; | 77 const GURL& page_url) = 0; |
| 68 virtual void OnDomStorageItemRemoved( | 78 virtual void OnDomStorageItemRemoved( |
| 69 const DomStorageArea* area, | 79 const DomStorageArea* area, |
| 70 const string16& key, | 80 const string16& key, |
| 71 const string16& old_value, | 81 const string16& old_value, |
| 72 const GURL& page_url) = 0; | 82 const GURL& page_url) = 0; |
| 73 virtual void OnDomStorageAreaCleared( | 83 virtual void OnDomStorageAreaCleared( |
| 74 const DomStorageArea* area, | 84 const DomStorageArea* area, |
| 75 const GURL& page_url) = 0; | 85 const GURL& page_url) = 0; |
| 76 virtual ~EventObserver() {} | 86 virtual ~EventObserver() {} |
| 77 }; | 87 }; |
| 78 | 88 |
| 79 DomStorageContext(const FilePath& directory, // empty for incognito profiles | 89 DomStorageContext(const FilePath& directory, // empty for incognito profiles |
| 80 quota::SpecialStoragePolicy* special_storage_policy, | 90 quota::SpecialStoragePolicy* special_storage_policy, |
| 81 DomStorageTaskRunner* task_runner); | 91 DomStorageTaskRunner* task_runner); |
| 92 const FilePath& directory() const { return directory_; } |
| 82 DomStorageTaskRunner* task_runner() const { return task_runner_; } | 93 DomStorageTaskRunner* task_runner() const { return task_runner_; } |
| 83 DomStorageNamespace* GetStorageNamespace(int64 namespace_id); | 94 DomStorageNamespace* GetStorageNamespace(int64 namespace_id); |
| 84 | 95 |
| 96 void GetUsageInfo(std::vector<UsageInfo>* info); |
| 97 void DeleteOrigin(const GURL& origin); |
| 98 void DeleteDataModifiedSince(const base::Time& cutoff); |
| 99 void PurgeMemory(); |
| 100 |
| 101 // Used by content settings to alter the behavior around |
| 102 // what data to keep and what data to discard at shutdown. |
| 103 // The policy is not so straight forward to describe, see |
| 104 // the implementation for details. |
| 105 void SetClearLocalState(bool clear_local_state) { |
| 106 clear_local_state_ = clear_local_state; |
| 107 } |
| 108 void SaveSessionState() { |
| 109 save_session_state_ = true; |
| 110 } |
| 111 |
| 112 // Called when the BrowserContext/Profile is going away. |
| 113 void Shutdown(); |
| 114 |
| 85 // Methods to add, remove, and notify EventObservers. | 115 // Methods to add, remove, and notify EventObservers. |
| 86 void AddEventObserver(EventObserver* observer); | 116 void AddEventObserver(EventObserver* observer); |
| 87 void RemoveEventObserver(EventObserver* observer); | 117 void RemoveEventObserver(EventObserver* observer); |
| 88 void NotifyItemSet( | 118 void NotifyItemSet( |
| 89 const DomStorageArea* area, | 119 const DomStorageArea* area, |
| 90 const string16& key, | 120 const string16& key, |
| 91 const string16& new_value, | 121 const string16& new_value, |
| 92 const NullableString16& old_value, | 122 const NullableString16& old_value, |
| 93 const GURL& page_url); | 123 const GURL& page_url); |
| 94 void NotifyItemRemoved( | 124 void NotifyItemRemoved( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 114 friend class base::RefCountedThreadSafe<DomStorageContext>; | 144 friend class base::RefCountedThreadSafe<DomStorageContext>; |
| 115 typedef std::map<int64, scoped_refptr<DomStorageNamespace> > | 145 typedef std::map<int64, scoped_refptr<DomStorageNamespace> > |
| 116 StorageNamespaceMap; | 146 StorageNamespaceMap; |
| 117 | 147 |
| 118 ~DomStorageContext(); | 148 ~DomStorageContext(); |
| 119 | 149 |
| 120 // Collection of namespaces keyed by id. | 150 // Collection of namespaces keyed by id. |
| 121 StorageNamespaceMap namespaces_; | 151 StorageNamespaceMap namespaces_; |
| 122 | 152 |
| 123 // Where localstorage data is stored, maybe empty for the incognito use case. | 153 // Where localstorage data is stored, maybe empty for the incognito use case. |
| 124 FilePath directory_; | 154 const FilePath directory_; |
| 125 | 155 |
| 126 // Used to schedule sequenced background tasks. | 156 // Used to schedule sequenced background tasks. |
| 127 scoped_refptr<DomStorageTaskRunner> task_runner_; | 157 scoped_refptr<DomStorageTaskRunner> task_runner_; |
| 128 | 158 |
| 129 // List of objects observing local storage events. | 159 // List of objects observing local storage events. |
| 130 ObserverList<EventObserver> event_observers_; | 160 ObserverList<EventObserver> event_observers_; |
| 131 | 161 |
| 132 // We use a 32 bit identifier for per tab storage sessions. | 162 // We use a 32 bit identifier for per tab storage sessions. |
| 133 // At a tab per second, this range is large enough for 68 years. | 163 // At a tab per second, this range is large enough for 68 years. |
| 134 base::AtomicSequenceNumber session_id_sequence_; | 164 base::AtomicSequenceNumber session_id_sequence_; |
| 165 |
| 166 bool clear_local_state_; |
| 167 bool save_session_state_; |
| 168 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; |
| 135 }; | 169 }; |
| 136 | 170 |
| 137 } // namespace dom_storage | 171 } // namespace dom_storage |
| 138 | 172 |
| 139 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ | 173 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_CONTEXT_H_ |
| OLD | NEW |