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