| 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/guid.h" |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/time.h" | 12 #include "base/time.h" |
| 12 #include "webkit/dom_storage/dom_storage_area.h" | 13 #include "webkit/dom_storage/dom_storage_area.h" |
| 13 #include "webkit/dom_storage/dom_storage_namespace.h" | 14 #include "webkit/dom_storage/dom_storage_namespace.h" |
| 14 #include "webkit/dom_storage/dom_storage_task_runner.h" | 15 #include "webkit/dom_storage/dom_storage_task_runner.h" |
| 15 #include "webkit/dom_storage/dom_storage_types.h" | 16 #include "webkit/dom_storage/dom_storage_types.h" |
| 16 #include "webkit/quota/special_storage_policy.h" | 17 #include "webkit/quota/special_storage_policy.h" |
| 17 | 18 |
| 18 using file_util::FileEnumerator; | 19 using file_util::FileEnumerator; |
| 19 | 20 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } | 164 } |
| 164 | 165 |
| 165 void DomStorageContext::NotifyAreaCleared( | 166 void DomStorageContext::NotifyAreaCleared( |
| 166 const DomStorageArea* area, | 167 const DomStorageArea* area, |
| 167 const GURL& page_url) { | 168 const GURL& page_url) { |
| 168 FOR_EACH_OBSERVER( | 169 FOR_EACH_OBSERVER( |
| 169 EventObserver, event_observers_, | 170 EventObserver, event_observers_, |
| 170 OnDomStorageAreaCleared(area, page_url)); | 171 OnDomStorageAreaCleared(area, page_url)); |
| 171 } | 172 } |
| 172 | 173 |
| 174 std::string DomStorageContext::AllocatePersistentSessionId() { |
| 175 std::string guid = base::GenerateGUID(); |
| 176 std::replace(guid.begin(), guid.end(), '-', '_'); |
| 177 return guid; |
| 178 } |
| 179 |
| 173 void DomStorageContext::CreateSessionNamespace( | 180 void DomStorageContext::CreateSessionNamespace( |
| 174 int64 namespace_id) { | 181 int64 namespace_id, |
| 182 const std::string& persistent_namespace_id) { |
| 175 if (is_shutdown_) | 183 if (is_shutdown_) |
| 176 return; | 184 return; |
| 177 DCHECK(namespace_id != kLocalStorageNamespaceId); | 185 DCHECK(namespace_id != kLocalStorageNamespaceId); |
| 178 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); | 186 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); |
| 179 namespaces_[namespace_id] = new DomStorageNamespace( | 187 namespaces_[namespace_id] = new DomStorageNamespace( |
| 180 namespace_id, task_runner_); | 188 namespace_id, persistent_namespace_id, task_runner_); |
| 181 } | 189 } |
| 182 | 190 |
| 183 void DomStorageContext::DeleteSessionNamespace( | 191 void DomStorageContext::DeleteSessionNamespace( |
| 184 int64 namespace_id) { | 192 int64 namespace_id) { |
| 185 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | 193 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
| 186 namespaces_.erase(namespace_id); | 194 namespaces_.erase(namespace_id); |
| 187 } | 195 } |
| 188 | 196 |
| 189 void DomStorageContext::CloneSessionNamespace( | 197 void DomStorageContext::CloneSessionNamespace( |
| 190 int64 existing_id, int64 new_id) { | 198 int64 existing_id, int64 new_id, |
| 199 const std::string& new_persistent_id) { |
| 191 if (is_shutdown_) | 200 if (is_shutdown_) |
| 192 return; | 201 return; |
| 193 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 202 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
| 194 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 203 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
| 195 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 204 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
| 196 if (found != namespaces_.end()) | 205 if (found != namespaces_.end()) |
| 197 namespaces_[new_id] = found->second->Clone(new_id); | 206 namespaces_[new_id] = found->second->Clone(new_id, new_persistent_id); |
| 198 else | 207 else |
| 199 CreateSessionNamespace(new_id); | 208 CreateSessionNamespace(new_id, new_persistent_id); |
| 200 } | 209 } |
| 201 | 210 |
| 202 void DomStorageContext::ClearSessionOnlyOrigins() { | 211 void DomStorageContext::ClearSessionOnlyOrigins() { |
| 203 std::vector<UsageInfo> infos; | 212 std::vector<UsageInfo> infos; |
| 204 const bool kDontIncludeFileInfo = false; | 213 const bool kDontIncludeFileInfo = false; |
| 205 GetUsageInfo(&infos, kDontIncludeFileInfo); | 214 GetUsageInfo(&infos, kDontIncludeFileInfo); |
| 206 for (size_t i = 0; i < infos.size(); ++i) { | 215 for (size_t i = 0; i < infos.size(); ++i) { |
| 207 const GURL& origin = infos[i].origin; | 216 const GURL& origin = infos[i].origin; |
| 208 if (special_storage_policy_->IsStorageProtected(origin)) | 217 if (special_storage_policy_->IsStorageProtected(origin)) |
| 209 continue; | 218 continue; |
| 210 if (!special_storage_policy_->IsStorageSessionOnly(origin)) | 219 if (!special_storage_policy_->IsStorageSessionOnly(origin)) |
| 211 continue; | 220 continue; |
| 212 | 221 |
| 213 const bool kNotRecursive = false; | 222 const bool kNotRecursive = false; |
| 214 FilePath database_file_path = localstorage_directory_.Append( | 223 FilePath database_file_path = localstorage_directory_.Append( |
| 215 DomStorageArea::DatabaseFileNameFromOrigin(origin)); | 224 DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
| 216 file_util::Delete(database_file_path, kNotRecursive); | 225 file_util::Delete(database_file_path, kNotRecursive); |
| 217 file_util::Delete( | 226 file_util::Delete( |
| 218 DomStorageDatabase::GetJournalFilePath(database_file_path), | 227 DomStorageDatabase::GetJournalFilePath(database_file_path), |
| 219 kNotRecursive); | 228 kNotRecursive); |
| 220 } | 229 } |
| 221 } | 230 } |
| 222 | 231 |
| 223 } // namespace dom_storage | 232 } // namespace dom_storage |
| OLD | NEW |