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/location.h" | 10 #include "base/location.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 DomStorageContext::DomStorageContext( | 25 DomStorageContext::DomStorageContext( |
26 const FilePath& localstorage_directory, | 26 const FilePath& localstorage_directory, |
27 const FilePath& sessionstorage_directory, | 27 const FilePath& sessionstorage_directory, |
28 quota::SpecialStoragePolicy* special_storage_policy, | 28 quota::SpecialStoragePolicy* special_storage_policy, |
29 DomStorageTaskRunner* task_runner) | 29 DomStorageTaskRunner* task_runner) |
30 : localstorage_directory_(localstorage_directory), | 30 : localstorage_directory_(localstorage_directory), |
31 sessionstorage_directory_(sessionstorage_directory), | 31 sessionstorage_directory_(sessionstorage_directory), |
32 task_runner_(task_runner), | 32 task_runner_(task_runner), |
33 is_shutdown_(false), | 33 is_shutdown_(false), |
34 clear_local_state_(false), | 34 force_keep_session_state_(false), |
35 save_session_state_(false), | |
36 special_storage_policy_(special_storage_policy) { | 35 special_storage_policy_(special_storage_policy) { |
37 // AtomicSequenceNum starts at 0 but we want to start session | 36 // AtomicSequenceNum starts at 0 but we want to start session |
38 // namespace ids at one since zero is reserved for the | 37 // namespace ids at one since zero is reserved for the |
39 // kLocalStorageNamespaceId. | 38 // kLocalStorageNamespaceId. |
40 session_id_sequence_.GetNext(); | 39 session_id_sequence_.GetNext(); |
41 } | 40 } |
42 | 41 |
43 DomStorageContext::~DomStorageContext() { | 42 DomStorageContext::~DomStorageContext() { |
44 } | 43 } |
45 | 44 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 is_shutdown_ = true; | 121 is_shutdown_ = true; |
123 StorageNamespaceMap::const_iterator it = namespaces_.begin(); | 122 StorageNamespaceMap::const_iterator it = namespaces_.begin(); |
124 for (; it != namespaces_.end(); ++it) | 123 for (; it != namespaces_.end(); ++it) |
125 it->second->Shutdown(); | 124 it->second->Shutdown(); |
126 | 125 |
127 if (localstorage_directory_.empty()) | 126 if (localstorage_directory_.empty()) |
128 return; | 127 return; |
129 | 128 |
130 // Respect the content policy settings about what to | 129 // Respect the content policy settings about what to |
131 // keep and what to discard. | 130 // keep and what to discard. |
132 if (save_session_state_) | 131 if (force_keep_session_state_) |
133 return; // Keep everything. | 132 return; // Keep everything. |
134 | 133 |
135 bool has_session_only_origins = | 134 bool has_session_only_origins = |
136 special_storage_policy_.get() && | 135 special_storage_policy_.get() && |
137 special_storage_policy_->HasSessionOnlyOrigins(); | 136 special_storage_policy_->HasSessionOnlyOrigins(); |
138 | 137 |
139 if (clear_local_state_ || has_session_only_origins) { | 138 if (has_session_only_origins) { |
140 // We may have to delete something. We continue on the | 139 // We may have to delete something. We continue on the |
141 // commit sequence after area shutdown tasks have cycled | 140 // commit sequence after area shutdown tasks have cycled |
142 // thru that sequence (and closed their database files). | 141 // thru that sequence (and closed their database files). |
143 bool success = task_runner_->PostShutdownBlockingTask( | 142 bool success = task_runner_->PostShutdownBlockingTask( |
144 FROM_HERE, | 143 FROM_HERE, |
145 DomStorageTaskRunner::COMMIT_SEQUENCE, | 144 DomStorageTaskRunner::COMMIT_SEQUENCE, |
146 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this)); | 145 base::Bind(&DomStorageContext::ClearSessionOnlyOrigins, this)); |
147 DCHECK(success); | 146 DCHECK(success); |
148 } | 147 } |
149 } | 148 } |
150 | 149 |
151 void DomStorageContext::AddEventObserver(EventObserver* observer) { | 150 void DomStorageContext::AddEventObserver(EventObserver* observer) { |
152 event_observers_.AddObserver(observer); | 151 event_observers_.AddObserver(observer); |
153 } | 152 } |
154 | 153 |
155 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { | 154 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { |
156 event_observers_.RemoveObserver(observer); | 155 event_observers_.RemoveObserver(observer); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return; | 206 return; |
208 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 207 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
209 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 208 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
210 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 209 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
211 if (found != namespaces_.end()) | 210 if (found != namespaces_.end()) |
212 namespaces_[new_id] = found->second->Clone(new_id); | 211 namespaces_[new_id] = found->second->Clone(new_id); |
213 else | 212 else |
214 CreateSessionNamespace(new_id); | 213 CreateSessionNamespace(new_id); |
215 } | 214 } |
216 | 215 |
217 void DomStorageContext::ClearLocalStateInCommitSequence() { | 216 void DomStorageContext::ClearSessionOnlyOrigins() { |
218 std::vector<UsageInfo> infos; | 217 std::vector<UsageInfo> infos; |
219 const bool kDontIncludeFileInfo = false; | 218 const bool kDontIncludeFileInfo = false; |
220 GetUsageInfo(&infos, kDontIncludeFileInfo); | 219 GetUsageInfo(&infos, kDontIncludeFileInfo); |
221 for (size_t i = 0; i < infos.size(); ++i) { | 220 for (size_t i = 0; i < infos.size(); ++i) { |
222 const GURL& origin = infos[i].origin; | 221 const GURL& origin = infos[i].origin; |
223 if (special_storage_policy_ && | 222 if (special_storage_policy_->IsStorageProtected(origin)) |
224 special_storage_policy_->IsStorageProtected(origin)) | |
225 continue; | 223 continue; |
226 if (!clear_local_state_ && | 224 if (!special_storage_policy_->IsStorageSessionOnly(origin)) |
227 !special_storage_policy_->IsStorageSessionOnly(origin)) | |
228 continue; | 225 continue; |
229 | 226 |
230 const bool kNotRecursive = false; | 227 const bool kNotRecursive = false; |
231 FilePath database_file_path = localstorage_directory_.Append( | 228 FilePath database_file_path = localstorage_directory_.Append( |
232 DomStorageArea::DatabaseFileNameFromOrigin(origin)); | 229 DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
233 file_util::Delete(database_file_path, kNotRecursive); | 230 file_util::Delete(database_file_path, kNotRecursive); |
234 file_util::Delete( | 231 file_util::Delete( |
235 DomStorageDatabase::GetJournalFilePath(database_file_path), | 232 DomStorageDatabase::GetJournalFilePath(database_file_path), |
236 kNotRecursive); | 233 kNotRecursive); |
237 } | 234 } |
238 } | 235 } |
239 | 236 |
240 } // namespace dom_storage | 237 } // namespace dom_storage |
OLD | NEW |