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 #include "webkit/dom_storage/dom_storage_context.h" | 5 #include "webkit/dom_storage/dom_storage_context.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 DomStorageContext::UsageInfo::UsageInfo() {} | 24 DomStorageContext::UsageInfo::UsageInfo() {} |
25 DomStorageContext::UsageInfo::~UsageInfo() {} | 25 DomStorageContext::UsageInfo::~UsageInfo() {} |
26 | 26 |
27 DomStorageContext::DomStorageContext( | 27 DomStorageContext::DomStorageContext( |
28 const FilePath& directory, | 28 const FilePath& directory, |
29 quota::SpecialStoragePolicy* special_storage_policy, | 29 quota::SpecialStoragePolicy* special_storage_policy, |
30 DomStorageTaskRunner* task_runner) | 30 DomStorageTaskRunner* task_runner) |
31 : directory_(directory), | 31 : directory_(directory), |
32 task_runner_(task_runner), | 32 task_runner_(task_runner), |
| 33 is_shutdown_(false), |
33 clear_local_state_(false), | 34 clear_local_state_(false), |
34 save_session_state_(false), | 35 save_session_state_(false), |
35 special_storage_policy_(special_storage_policy) { | 36 special_storage_policy_(special_storage_policy) { |
36 // AtomicSequenceNum starts at 0 but we want to start session | 37 // AtomicSequenceNum starts at 0 but we want to start session |
37 // namespace ids at one since zero is reserved for the | 38 // namespace ids at one since zero is reserved for the |
38 // kLocalStorageNamespaceId. | 39 // kLocalStorageNamespaceId. |
39 session_id_sequence_.GetNext(); | 40 session_id_sequence_.GetNext(); |
40 } | 41 } |
41 | 42 |
42 DomStorageContext::~DomStorageContext() { | 43 DomStorageContext::~DomStorageContext() { |
43 } | 44 } |
44 | 45 |
45 DomStorageNamespace* DomStorageContext::GetStorageNamespace( | 46 DomStorageNamespace* DomStorageContext::GetStorageNamespace( |
46 int64 namespace_id) { | 47 int64 namespace_id) { |
| 48 if (is_shutdown_) |
| 49 return NULL; |
47 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); | 50 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); |
48 if (found == namespaces_.end()) { | 51 if (found == namespaces_.end()) { |
49 if (namespace_id == kLocalStorageNamespaceId) { | 52 if (namespace_id == kLocalStorageNamespaceId) { |
50 DomStorageNamespace* local = | 53 DomStorageNamespace* local = |
51 new DomStorageNamespace(directory_, task_runner_); | 54 new DomStorageNamespace(directory_, task_runner_); |
52 namespaces_[kLocalStorageNamespaceId] = local; | 55 namespaces_[kLocalStorageNamespaceId] = local; |
53 return local; | 56 return local; |
54 } | 57 } |
55 return NULL; | 58 return NULL; |
56 } | 59 } |
(...skipping 25 matching lines...) Expand all Loading... |
82 | 85 |
83 void DomStorageContext::DeleteOrigin(const GURL& origin) { | 86 void DomStorageContext::DeleteOrigin(const GURL& origin) { |
84 // TODO(michaeln): write me | 87 // TODO(michaeln): write me |
85 } | 88 } |
86 | 89 |
87 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { | 90 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { |
88 // TODO(michaeln): write me | 91 // TODO(michaeln): write me |
89 } | 92 } |
90 | 93 |
91 void DomStorageContext::PurgeMemory() { | 94 void DomStorageContext::PurgeMemory() { |
92 // TODO(michaeln): write me | 95 // We can only purge memory from the local storage namespace |
| 96 // which is backed by disk. |
| 97 StorageNamespaceMap::iterator found = |
| 98 namespaces_.find(kLocalStorageNamespaceId); |
| 99 if (found != namespaces_.end()) |
| 100 found->second->PurgeMemory(); |
93 } | 101 } |
94 | 102 |
95 void DomStorageContext::Shutdown() { | 103 void DomStorageContext::Shutdown() { |
96 // TODO(michaeln): write me | 104 is_shutdown_ = true; |
| 105 StorageNamespaceMap::const_iterator it = namespaces_.begin(); |
| 106 for (; it != namespaces_.end(); ++it) |
| 107 it->second->Shutdown(); |
97 } | 108 } |
98 | 109 |
99 void DomStorageContext::AddEventObserver(EventObserver* observer) { | 110 void DomStorageContext::AddEventObserver(EventObserver* observer) { |
100 event_observers_.AddObserver(observer); | 111 event_observers_.AddObserver(observer); |
101 } | 112 } |
102 | 113 |
103 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { | 114 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { |
104 event_observers_.RemoveObserver(observer); | 115 event_observers_.RemoveObserver(observer); |
105 } | 116 } |
106 | 117 |
(...skipping 21 matching lines...) Expand all Loading... |
128 void DomStorageContext::NotifyAreaCleared( | 139 void DomStorageContext::NotifyAreaCleared( |
129 const DomStorageArea* area, | 140 const DomStorageArea* area, |
130 const GURL& page_url) { | 141 const GURL& page_url) { |
131 FOR_EACH_OBSERVER( | 142 FOR_EACH_OBSERVER( |
132 EventObserver, event_observers_, | 143 EventObserver, event_observers_, |
133 OnDomStorageAreaCleared(area, page_url)); | 144 OnDomStorageAreaCleared(area, page_url)); |
134 } | 145 } |
135 | 146 |
136 void DomStorageContext::CreateSessionNamespace( | 147 void DomStorageContext::CreateSessionNamespace( |
137 int64 namespace_id) { | 148 int64 namespace_id) { |
| 149 if (is_shutdown_) |
| 150 return; |
138 DCHECK(namespace_id != kLocalStorageNamespaceId); | 151 DCHECK(namespace_id != kLocalStorageNamespaceId); |
139 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); | 152 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); |
140 namespaces_[namespace_id] = new DomStorageNamespace( | 153 namespaces_[namespace_id] = new DomStorageNamespace( |
141 namespace_id, task_runner_); | 154 namespace_id, task_runner_); |
142 } | 155 } |
143 | 156 |
144 void DomStorageContext::DeleteSessionNamespace( | 157 void DomStorageContext::DeleteSessionNamespace( |
145 int64 namespace_id) { | 158 int64 namespace_id) { |
146 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | 159 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
147 namespaces_.erase(namespace_id); | 160 namespaces_.erase(namespace_id); |
148 } | 161 } |
149 | 162 |
150 void DomStorageContext::CloneSessionNamespace( | 163 void DomStorageContext::CloneSessionNamespace( |
151 int64 existing_id, int64 new_id) { | 164 int64 existing_id, int64 new_id) { |
| 165 if (is_shutdown_) |
| 166 return; |
152 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 167 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
153 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 168 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
154 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 169 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
155 if (found != namespaces_.end()) | 170 if (found != namespaces_.end()) |
156 namespaces_[new_id] = found->second->Clone(new_id); | 171 namespaces_[new_id] = found->second->Clone(new_id); |
157 else | 172 else |
158 CreateSessionNamespace(new_id); | 173 CreateSessionNamespace(new_id); |
159 } | 174 } |
160 | 175 |
161 } // namespace dom_storage | 176 } // namespace dom_storage |
OLD | NEW |