Commit 36dcef3d authored by michaeln's avatar michaeln Committed by Commit bot

[DOMStorage] Offset the session storage namespace ids generated by different...

[DOMStorage] Offset the session storage namespace ids generated by different contexts to help identify when an id from one is mistakenly used in another.

Review URL: https://codereview.chromium.org/881253004

Cr-Commit-Position: refs/heads/master@{#314256}
parent a4ee44ef
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/browser/dom_storage/dom_storage_context_impl.h" #include "content/browser/dom_storage/dom_storage_context_impl.h"
#include <stdlib.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
...@@ -26,6 +28,10 @@ namespace content { ...@@ -26,6 +28,10 @@ namespace content {
static const int kSessionStoraceScavengingSeconds = 60; static const int kSessionStoraceScavengingSeconds = 60;
// Offset the session storage namespace ids generated by different contexts
// to help identify when an id from one is mistakenly used in another.
static int g_session_id_offset_sequence = 0;
DOMStorageContextImpl::DOMStorageContextImpl( DOMStorageContextImpl::DOMStorageContextImpl(
const base::FilePath& localstorage_directory, const base::FilePath& localstorage_directory,
const base::FilePath& sessionstorage_directory, const base::FilePath& sessionstorage_directory,
...@@ -34,6 +40,7 @@ DOMStorageContextImpl::DOMStorageContextImpl( ...@@ -34,6 +40,7 @@ DOMStorageContextImpl::DOMStorageContextImpl(
: localstorage_directory_(localstorage_directory), : localstorage_directory_(localstorage_directory),
sessionstorage_directory_(sessionstorage_directory), sessionstorage_directory_(sessionstorage_directory),
task_runner_(task_runner), task_runner_(task_runner),
session_id_offset_(abs((g_session_id_offset_sequence++ % 10)) * 1000),
is_shutdown_(false), is_shutdown_(false),
force_keep_session_state_(false), force_keep_session_state_(false),
special_storage_policy_(special_storage_policy), special_storage_policy_(special_storage_policy),
...@@ -227,6 +234,10 @@ void DOMStorageContextImpl::NotifyAreaCleared( ...@@ -227,6 +234,10 @@ void DOMStorageContextImpl::NotifyAreaCleared(
OnDOMStorageAreaCleared(area, page_url)); OnDOMStorageAreaCleared(area, page_url));
} }
int64 DOMStorageContextImpl::AllocateSessionId() {
return session_id_sequence_.GetNext() + session_id_offset_;
}
std::string DOMStorageContextImpl::AllocatePersistentSessionId() { std::string DOMStorageContextImpl::AllocatePersistentSessionId() {
std::string guid = base::GenerateGUID(); std::string guid = base::GenerateGUID();
std::replace(guid.begin(), guid.end(), '-', '_'); std::replace(guid.begin(), guid.end(), '-', '_');
......
...@@ -147,10 +147,7 @@ class CONTENT_EXPORT DOMStorageContextImpl ...@@ -147,10 +147,7 @@ class CONTENT_EXPORT DOMStorageContextImpl
const GURL& page_url); const GURL& page_url);
// May be called on any thread. // May be called on any thread.
int64 AllocateSessionId() { int64 AllocateSessionId();
return session_id_sequence_.GetNext();
}
std::string AllocatePersistentSessionId(); std::string AllocatePersistentSessionId();
// Must be called on the background thread. // Must be called on the background thread.
...@@ -207,7 +204,10 @@ class CONTENT_EXPORT DOMStorageContextImpl ...@@ -207,7 +204,10 @@ class CONTENT_EXPORT DOMStorageContextImpl
// We use a 32 bit identifier for per tab storage sessions. // We use a 32 bit identifier for per tab storage sessions.
// At a tab per second, this range is large enough for 68 years. // At a tab per second, this range is large enough for 68 years.
// The offset is to more quickly detect the error condition where
// an id related to one context is mistakenly used in another.
base::AtomicSequenceNumber session_id_sequence_; base::AtomicSequenceNumber session_id_sequence_;
const int session_id_offset_;
bool is_shutdown_; bool is_shutdown_;
bool force_keep_session_state_; bool force_keep_session_state_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment