Chromium Code Reviews| 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 <stdlib.h> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 10 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 11 #include "base/guid.h" | 13 #include "base/guid.h" |
| 12 #include "base/location.h" | 14 #include "base/location.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "content/browser/dom_storage/dom_storage_area.h" | 16 #include "content/browser/dom_storage/dom_storage_area.h" |
| 15 #include "content/browser/dom_storage/dom_storage_database.h" | 17 #include "content/browser/dom_storage/dom_storage_database.h" |
| 16 #include "content/browser/dom_storage/dom_storage_namespace.h" | 18 #include "content/browser/dom_storage/dom_storage_namespace.h" |
| 17 #include "content/browser/dom_storage/dom_storage_task_runner.h" | 19 #include "content/browser/dom_storage/dom_storage_task_runner.h" |
| 18 #include "content/browser/dom_storage/session_storage_database.h" | 20 #include "content/browser/dom_storage/session_storage_database.h" |
| 19 #include "content/common/dom_storage/dom_storage_types.h" | 21 #include "content/common/dom_storage/dom_storage_types.h" |
| 20 #include "content/public/browser/dom_storage_context.h" | 22 #include "content/public/browser/dom_storage_context.h" |
| 21 #include "content/public/browser/local_storage_usage_info.h" | 23 #include "content/public/browser/local_storage_usage_info.h" |
| 22 #include "content/public/browser/session_storage_usage_info.h" | 24 #include "content/public/browser/session_storage_usage_info.h" |
| 23 #include "storage/browser/quota/special_storage_policy.h" | 25 #include "storage/browser/quota/special_storage_policy.h" |
| 24 | 26 |
| 25 namespace content { | 27 namespace content { |
| 26 | 28 |
| 27 static const int kSessionStoraceScavengingSeconds = 60; | 29 static const int kSessionStoraceScavengingSeconds = 60; |
| 30 static int g_session_id_offset_sequence; | |
|
jsbell
2015/01/30 18:10:16
explicitly initialize to 0?
(just for readability
| |
| 28 | 31 |
| 29 DOMStorageContextImpl::DOMStorageContextImpl( | 32 DOMStorageContextImpl::DOMStorageContextImpl( |
| 30 const base::FilePath& localstorage_directory, | 33 const base::FilePath& localstorage_directory, |
| 31 const base::FilePath& sessionstorage_directory, | 34 const base::FilePath& sessionstorage_directory, |
| 32 storage::SpecialStoragePolicy* special_storage_policy, | 35 storage::SpecialStoragePolicy* special_storage_policy, |
| 33 DOMStorageTaskRunner* task_runner) | 36 DOMStorageTaskRunner* task_runner) |
| 34 : localstorage_directory_(localstorage_directory), | 37 : localstorage_directory_(localstorage_directory), |
| 35 sessionstorage_directory_(sessionstorage_directory), | 38 sessionstorage_directory_(sessionstorage_directory), |
| 36 task_runner_(task_runner), | 39 task_runner_(task_runner), |
| 40 session_id_offset_(abs((g_session_id_offset_sequence++ % 10)) * 1000), | |
| 37 is_shutdown_(false), | 41 is_shutdown_(false), |
| 38 force_keep_session_state_(false), | 42 force_keep_session_state_(false), |
| 39 special_storage_policy_(special_storage_policy), | 43 special_storage_policy_(special_storage_policy), |
| 40 scavenging_started_(false) { | 44 scavenging_started_(false) { |
| 41 // AtomicSequenceNum starts at 0 but we want to start session | 45 // AtomicSequenceNum starts at 0 but we want to start session |
| 42 // namespace ids at one since zero is reserved for the | 46 // namespace ids at one since zero is reserved for the |
| 43 // kLocalStorageNamespaceId. | 47 // kLocalStorageNamespaceId. |
| 44 session_id_sequence_.GetNext(); | 48 session_id_sequence_.GetNext(); |
| 45 } | 49 } |
| 46 | 50 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 } | 224 } |
| 221 | 225 |
| 222 void DOMStorageContextImpl::NotifyAreaCleared( | 226 void DOMStorageContextImpl::NotifyAreaCleared( |
| 223 const DOMStorageArea* area, | 227 const DOMStorageArea* area, |
| 224 const GURL& page_url) { | 228 const GURL& page_url) { |
| 225 FOR_EACH_OBSERVER( | 229 FOR_EACH_OBSERVER( |
| 226 EventObserver, event_observers_, | 230 EventObserver, event_observers_, |
| 227 OnDOMStorageAreaCleared(area, page_url)); | 231 OnDOMStorageAreaCleared(area, page_url)); |
| 228 } | 232 } |
| 229 | 233 |
| 234 int64 DOMStorageContextImpl::AllocateSessionId() { | |
| 235 return session_id_sequence_.GetNext() + session_id_offset_; | |
| 236 } | |
| 237 | |
| 230 std::string DOMStorageContextImpl::AllocatePersistentSessionId() { | 238 std::string DOMStorageContextImpl::AllocatePersistentSessionId() { |
| 231 std::string guid = base::GenerateGUID(); | 239 std::string guid = base::GenerateGUID(); |
| 232 std::replace(guid.begin(), guid.end(), '-', '_'); | 240 std::replace(guid.begin(), guid.end(), '-', '_'); |
| 233 return guid; | 241 return guid; |
| 234 } | 242 } |
| 235 | 243 |
| 236 void DOMStorageContextImpl::CreateSessionNamespace( | 244 void DOMStorageContextImpl::CreateSessionNamespace( |
| 237 int64 namespace_id, | 245 int64 namespace_id, |
| 238 const std::string& persistent_namespace_id) { | 246 const std::string& persistent_namespace_id) { |
| 239 if (is_shutdown_) | 247 if (is_shutdown_) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 if (!deletable_persistent_namespace_ids_.empty()) { | 410 if (!deletable_persistent_namespace_ids_.empty()) { |
| 403 task_runner_->PostDelayedTask( | 411 task_runner_->PostDelayedTask( |
| 404 FROM_HERE, base::Bind( | 412 FROM_HERE, base::Bind( |
| 405 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 413 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
| 406 this), | 414 this), |
| 407 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 415 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
| 408 } | 416 } |
| 409 } | 417 } |
| 410 | 418 |
| 411 } // namespace content | 419 } // namespace content |
| OLD | NEW |