Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(719)

Side by Side Diff: content/browser/dom_storage/dom_storage_context_impl.cc

Issue 881253004: offset namespace ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
28 30
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 = 1;
34
29 DOMStorageContextImpl::DOMStorageContextImpl( 35 DOMStorageContextImpl::DOMStorageContextImpl(
30 const base::FilePath& localstorage_directory, 36 const base::FilePath& localstorage_directory,
31 const base::FilePath& sessionstorage_directory, 37 const base::FilePath& sessionstorage_directory,
32 storage::SpecialStoragePolicy* special_storage_policy, 38 storage::SpecialStoragePolicy* special_storage_policy,
33 DOMStorageTaskRunner* task_runner) 39 DOMStorageTaskRunner* task_runner)
34 : localstorage_directory_(localstorage_directory), 40 : localstorage_directory_(localstorage_directory),
35 sessionstorage_directory_(sessionstorage_directory), 41 sessionstorage_directory_(sessionstorage_directory),
36 task_runner_(task_runner), 42 task_runner_(task_runner),
43 session_id_offset_(abs((g_session_id_offset_sequence++ % 10)) * 1000),
37 is_shutdown_(false), 44 is_shutdown_(false),
38 force_keep_session_state_(false), 45 force_keep_session_state_(false),
39 special_storage_policy_(special_storage_policy), 46 special_storage_policy_(special_storage_policy),
40 scavenging_started_(false) { 47 scavenging_started_(false) {
41 // AtomicSequenceNum starts at 0 but we want to start session 48 // AtomicSequenceNum starts at 0 but we want to start session
42 // namespace ids at one since zero is reserved for the 49 // namespace ids at one since zero is reserved for the
43 // kLocalStorageNamespaceId. 50 // kLocalStorageNamespaceId.
44 session_id_sequence_.GetNext(); 51 session_id_sequence_.GetNext();
45 } 52 }
46 53
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 227 }
221 228
222 void DOMStorageContextImpl::NotifyAreaCleared( 229 void DOMStorageContextImpl::NotifyAreaCleared(
223 const DOMStorageArea* area, 230 const DOMStorageArea* area,
224 const GURL& page_url) { 231 const GURL& page_url) {
225 FOR_EACH_OBSERVER( 232 FOR_EACH_OBSERVER(
226 EventObserver, event_observers_, 233 EventObserver, event_observers_,
227 OnDOMStorageAreaCleared(area, page_url)); 234 OnDOMStorageAreaCleared(area, page_url));
228 } 235 }
229 236
237 int64 DOMStorageContextImpl::AllocateSessionId() {
238 return session_id_sequence_.GetNext() + session_id_offset_;
239 }
240
230 std::string DOMStorageContextImpl::AllocatePersistentSessionId() { 241 std::string DOMStorageContextImpl::AllocatePersistentSessionId() {
231 std::string guid = base::GenerateGUID(); 242 std::string guid = base::GenerateGUID();
232 std::replace(guid.begin(), guid.end(), '-', '_'); 243 std::replace(guid.begin(), guid.end(), '-', '_');
233 return guid; 244 return guid;
234 } 245 }
235 246
236 void DOMStorageContextImpl::CreateSessionNamespace( 247 void DOMStorageContextImpl::CreateSessionNamespace(
237 int64 namespace_id, 248 int64 namespace_id,
238 const std::string& persistent_namespace_id) { 249 const std::string& persistent_namespace_id) {
239 if (is_shutdown_) 250 if (is_shutdown_)
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (!deletable_persistent_namespace_ids_.empty()) { 413 if (!deletable_persistent_namespace_ids_.empty()) {
403 task_runner_->PostDelayedTask( 414 task_runner_->PostDelayedTask(
404 FROM_HERE, base::Bind( 415 FROM_HERE, base::Bind(
405 &DOMStorageContextImpl::DeleteNextUnusedNamespace, 416 &DOMStorageContextImpl::DeleteNextUnusedNamespace,
406 this), 417 this),
407 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); 418 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds));
408 } 419 }
409 } 420 }
410 421
411 } // namespace content 422 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698