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 "content/browser/dom_storage/dom_storage_context_impl.h" | 5 #include "content/browser/dom_storage/dom_storage_context_impl.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/files/file_enumerator.h" | 9 #include "base/files/file_enumerator.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 220 } |
221 | 221 |
222 void DOMStorageContextImpl::NotifyAreaCleared( | 222 void DOMStorageContextImpl::NotifyAreaCleared( |
223 const DOMStorageArea* area, | 223 const DOMStorageArea* area, |
224 const GURL& page_url) { | 224 const GURL& page_url) { |
225 FOR_EACH_OBSERVER( | 225 FOR_EACH_OBSERVER( |
226 EventObserver, event_observers_, | 226 EventObserver, event_observers_, |
227 OnDOMStorageAreaCleared(area, page_url)); | 227 OnDOMStorageAreaCleared(area, page_url)); |
228 } | 228 } |
229 | 229 |
230 void DOMStorageContextImpl::NotifyAliasSessionMerged( | |
231 int64 namespace_id, | |
232 DOMStorageNamespace* old_alias_master_namespace) { | |
233 FOR_EACH_OBSERVER( | |
234 EventObserver, event_observers_, | |
235 OnDOMSessionStorageReset(namespace_id)); | |
236 if (old_alias_master_namespace) | |
237 MaybeShutdownSessionNamespace(old_alias_master_namespace); | |
238 } | |
239 | |
240 std::string DOMStorageContextImpl::AllocatePersistentSessionId() { | 230 std::string DOMStorageContextImpl::AllocatePersistentSessionId() { |
241 std::string guid = base::GenerateGUID(); | 231 std::string guid = base::GenerateGUID(); |
242 std::replace(guid.begin(), guid.end(), '-', '_'); | 232 std::replace(guid.begin(), guid.end(), '-', '_'); |
243 return guid; | 233 return guid; |
244 } | 234 } |
245 | 235 |
246 void DOMStorageContextImpl::CreateSessionNamespace( | 236 void DOMStorageContextImpl::CreateSessionNamespace( |
247 int64 namespace_id, | 237 int64 namespace_id, |
248 const std::string& persistent_namespace_id) { | 238 const std::string& persistent_namespace_id) { |
249 if (is_shutdown_) | 239 if (is_shutdown_) |
250 return; | 240 return; |
251 DCHECK(namespace_id != kLocalStorageNamespaceId); | 241 DCHECK(namespace_id != kLocalStorageNamespaceId); |
252 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); | 242 DCHECK(namespaces_.find(namespace_id) == namespaces_.end()); |
253 namespaces_[namespace_id] = new DOMStorageNamespace( | 243 namespaces_[namespace_id] = new DOMStorageNamespace( |
254 namespace_id, persistent_namespace_id, session_storage_database_.get(), | 244 namespace_id, persistent_namespace_id, session_storage_database_.get(), |
255 task_runner_.get()); | 245 task_runner_.get()); |
256 persistent_namespace_id_to_namespace_id_[persistent_namespace_id] = | 246 persistent_namespace_id_to_namespace_id_[persistent_namespace_id] = |
257 namespace_id; | 247 namespace_id; |
258 } | 248 } |
259 | 249 |
260 void DOMStorageContextImpl::DeleteSessionNamespace( | 250 void DOMStorageContextImpl::DeleteSessionNamespace( |
261 int64 namespace_id, bool should_persist_data) { | 251 int64 namespace_id, bool should_persist_data) { |
262 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | 252 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); |
263 StorageNamespaceMap::const_iterator it = namespaces_.find(namespace_id); | 253 StorageNamespaceMap::const_iterator it = namespaces_.find(namespace_id); |
264 if (it == namespaces_.end() || | 254 if (it == namespaces_.end()) |
265 it->second->ready_for_deletion_pending_aliases()) { | |
266 return; | 255 return; |
267 } | 256 std::string persistent_namespace_id = it->second->persistent_namespace_id(); |
268 it->second->set_ready_for_deletion_pending_aliases(true); | |
269 DOMStorageNamespace* alias_master = it->second->alias_master_namespace(); | |
270 if (alias_master) { | |
271 DCHECK(it->second->num_aliases() == 0); | |
272 DCHECK(alias_master->alias_master_namespace() == NULL); | |
273 if (should_persist_data) | |
274 alias_master->set_must_persist_at_shutdown(true); | |
275 if (it->second->DecrementMasterAliasCount()) | |
276 MaybeShutdownSessionNamespace(alias_master); | |
277 namespaces_.erase(namespace_id); | |
278 } else { | |
279 if (should_persist_data) | |
280 it->second->set_must_persist_at_shutdown(true); | |
281 MaybeShutdownSessionNamespace(it->second.get()); | |
282 } | |
283 } | |
284 | |
285 void DOMStorageContextImpl::MaybeShutdownSessionNamespace( | |
286 DOMStorageNamespace* ns) { | |
287 if (ns->num_aliases() > 0 || !ns->ready_for_deletion_pending_aliases()) | |
288 return; | |
289 DCHECK_EQ(ns->num_aliases(), 0); | |
290 DCHECK(ns->alias_master_namespace() == NULL); | |
291 std::string persistent_namespace_id = ns->persistent_namespace_id(); | |
292 if (session_storage_database_.get()) { | 257 if (session_storage_database_.get()) { |
293 if (!ns->must_persist_at_shutdown()) { | 258 if (!should_persist_data) { |
294 task_runner_->PostShutdownBlockingTask( | 259 task_runner_->PostShutdownBlockingTask( |
295 FROM_HERE, | 260 FROM_HERE, |
296 DOMStorageTaskRunner::COMMIT_SEQUENCE, | 261 DOMStorageTaskRunner::COMMIT_SEQUENCE, |
297 base::Bind( | 262 base::Bind( |
298 base::IgnoreResult(&SessionStorageDatabase::DeleteNamespace), | 263 base::IgnoreResult(&SessionStorageDatabase::DeleteNamespace), |
299 session_storage_database_, | 264 session_storage_database_, |
300 persistent_namespace_id)); | 265 persistent_namespace_id)); |
301 } else { | 266 } else { |
302 // Ensure that the data gets committed before we shut down. | 267 // Ensure that the data gets committed before we shut down. |
303 ns->Shutdown(); | 268 it->second->Shutdown(); |
304 if (!scavenging_started_) { | 269 if (!scavenging_started_) { |
305 // Protect the persistent namespace ID from scavenging. | 270 // Protect the persistent namespace ID from scavenging. |
306 protected_persistent_session_ids_.insert(persistent_namespace_id); | 271 protected_persistent_session_ids_.insert(persistent_namespace_id); |
307 } | 272 } |
308 } | 273 } |
309 } | 274 } |
310 persistent_namespace_id_to_namespace_id_.erase(persistent_namespace_id); | 275 persistent_namespace_id_to_namespace_id_.erase(persistent_namespace_id); |
311 namespaces_.erase(ns->namespace_id()); | 276 namespaces_.erase(namespace_id); |
312 } | 277 } |
313 | 278 |
314 void DOMStorageContextImpl::CloneSessionNamespace( | 279 void DOMStorageContextImpl::CloneSessionNamespace( |
315 int64 existing_id, int64 new_id, | 280 int64 existing_id, int64 new_id, |
316 const std::string& new_persistent_id) { | 281 const std::string& new_persistent_id) { |
317 if (is_shutdown_) | 282 if (is_shutdown_) |
318 return; | 283 return; |
319 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 284 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
320 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 285 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
321 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 286 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
322 if (found != namespaces_.end()) | 287 if (found != namespaces_.end()) |
323 namespaces_[new_id] = found->second->Clone(new_id, new_persistent_id); | 288 namespaces_[new_id] = found->second->Clone(new_id, new_persistent_id); |
324 else | 289 else |
325 CreateSessionNamespace(new_id, new_persistent_id); | 290 CreateSessionNamespace(new_id, new_persistent_id); |
326 } | 291 } |
327 | 292 |
328 void DOMStorageContextImpl::CreateAliasSessionNamespace( | |
329 int64 existing_id, int64 new_id, | |
330 const std::string& persistent_id) { | |
331 if (is_shutdown_) | |
332 return; | |
333 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | |
334 DCHECK_NE(kLocalStorageNamespaceId, new_id); | |
335 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | |
336 if (found != namespaces_.end()) { | |
337 namespaces_[new_id] = found->second->CreateAlias(new_id); | |
338 } else { | |
339 CreateSessionNamespace(new_id, persistent_id); | |
340 } | |
341 } | |
342 | |
343 void DOMStorageContextImpl::ClearSessionOnlyOrigins() { | 293 void DOMStorageContextImpl::ClearSessionOnlyOrigins() { |
344 if (!localstorage_directory_.empty()) { | 294 if (!localstorage_directory_.empty()) { |
345 std::vector<LocalStorageUsageInfo> infos; | 295 std::vector<LocalStorageUsageInfo> infos; |
346 const bool kDontIncludeFileInfo = false; | 296 const bool kDontIncludeFileInfo = false; |
347 GetLocalStorageUsage(&infos, kDontIncludeFileInfo); | 297 GetLocalStorageUsage(&infos, kDontIncludeFileInfo); |
348 for (size_t i = 0; i < infos.size(); ++i) { | 298 for (size_t i = 0; i < infos.size(); ++i) { |
349 const GURL& origin = infos[i].origin; | 299 const GURL& origin = infos[i].origin; |
350 if (special_storage_policy_->IsStorageProtected(origin)) | 300 if (special_storage_policy_->IsStorageProtected(origin)) |
351 continue; | 301 continue; |
352 if (!special_storage_policy_->IsStorageSessionOnly(origin)) | 302 if (!special_storage_policy_->IsStorageSessionOnly(origin)) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 deletable_persistent_namespace_ids_.pop_back(); | 401 deletable_persistent_namespace_ids_.pop_back(); |
452 if (!deletable_persistent_namespace_ids_.empty()) { | 402 if (!deletable_persistent_namespace_ids_.empty()) { |
453 task_runner_->PostDelayedTask( | 403 task_runner_->PostDelayedTask( |
454 FROM_HERE, base::Bind( | 404 FROM_HERE, base::Bind( |
455 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 405 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
456 this), | 406 this), |
457 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 407 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
458 } | 408 } |
459 } | 409 } |
460 | 410 |
461 void DOMStorageContextImpl::AddTransactionLogProcessId(int64 namespace_id, | |
462 int process_id) { | |
463 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | |
464 StorageNamespaceMap::const_iterator it = namespaces_.find(namespace_id); | |
465 if (it == namespaces_.end()) | |
466 return; | |
467 it->second->AddTransactionLogProcessId(process_id); | |
468 } | |
469 | |
470 void DOMStorageContextImpl::RemoveTransactionLogProcessId(int64 namespace_id, | |
471 int process_id) { | |
472 DCHECK_NE(kLocalStorageNamespaceId, namespace_id); | |
473 StorageNamespaceMap::const_iterator it = namespaces_.find(namespace_id); | |
474 if (it == namespaces_.end()) | |
475 return; | |
476 it->second->RemoveTransactionLogProcessId(process_id); | |
477 } | |
478 | |
479 SessionStorageNamespace::MergeResult | |
480 DOMStorageContextImpl::MergeSessionStorage( | |
481 int64 namespace1_id, bool actually_merge, int process_id, | |
482 int64 namespace2_id) { | |
483 DCHECK_NE(kLocalStorageNamespaceId, namespace1_id); | |
484 DCHECK_NE(kLocalStorageNamespaceId, namespace2_id); | |
485 StorageNamespaceMap::const_iterator it = namespaces_.find(namespace1_id); | |
486 if (it == namespaces_.end()) | |
487 return SessionStorageNamespace::MERGE_RESULT_NAMESPACE_NOT_FOUND; | |
488 DOMStorageNamespace* ns1 = it->second.get(); | |
489 it = namespaces_.find(namespace2_id); | |
490 if (it == namespaces_.end()) | |
491 return SessionStorageNamespace::MERGE_RESULT_NAMESPACE_NOT_FOUND; | |
492 DOMStorageNamespace* ns2 = it->second.get(); | |
493 return ns1->Merge(actually_merge, process_id, ns2, this); | |
494 } | |
495 | |
496 } // namespace content | 411 } // namespace content |
OLD | NEW |