diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-19 23:40:04 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-19 23:40:04 +0000 |
commit | 24c915e7d8204d061c62516da805416f21f88269 (patch) | |
tree | 29cb9640ae147d1ea85f7b4dd848ee02e1de958e /webkit | |
parent | 4a4512426f2c7224f3895d959e66ca1e8111a194 (diff) | |
download | chromium_src-24c915e7d8204d061c62516da805416f21f88269.zip chromium_src-24c915e7d8204d061c62516da805416f21f88269.tar.gz chromium_src-24c915e7d8204d061c62516da805416f21f88269.tar.bz2 |
DOMStorageContextImpl that's implemented in terms of the new dom_storage classes. Also compile out existing tests that no longer apply when ENABLE_NEW_DOM_STORAGE_BACKEND is defined.
BUG=106763
Review URL: https://chromiumcodereview.appspot.com/9695013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/dom_storage/dom_storage_area.cc | 21 | ||||
-rw-r--r-- | webkit/dom_storage/dom_storage_area.h | 5 | ||||
-rw-r--r-- | webkit/dom_storage/dom_storage_context.cc | 54 | ||||
-rw-r--r-- | webkit/dom_storage/dom_storage_context.h | 38 |
4 files changed, 106 insertions, 12 deletions
diff --git a/webkit/dom_storage/dom_storage_area.cc b/webkit/dom_storage/dom_storage_area.cc index 79de209..41325f7 100644 --- a/webkit/dom_storage/dom_storage_area.cc +++ b/webkit/dom_storage/dom_storage_area.cc @@ -16,6 +16,20 @@ namespace dom_storage { +// static +const FilePath::CharType DomStorageArea::kDatabaseFileExtension[] = + FILE_PATH_LITERAL(".localstorage"); + +// static +FilePath DomStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) { + std::string filename = fileapi::GetOriginIdentifierFromURL(origin); + // There is no FilePath.AppendExtension() method, so start with just the + // extension as the filename, and then InsertBeforeExtension the desired + // name. + return FilePath().Append(kDatabaseFileExtension). + InsertBeforeExtensionASCII(filename); +} + DomStorageArea::DomStorageArea( int64 namespace_id, const GURL& origin, const FilePath& directory, DomStorageTaskRunner* task_runner) @@ -164,11 +178,4 @@ void DomStorageArea::CommitChanges() { commit_in_flight_ = false; } -// static -FilePath DomStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) { - std::string filename = fileapi::GetOriginIdentifierFromURL(origin) - + ".localstorage"; - return FilePath().AppendASCII(filename); -} - } // namespace dom_storage diff --git a/webkit/dom_storage/dom_storage_area.h b/webkit/dom_storage/dom_storage_area.h index ba26d60..fba1a7f 100644 --- a/webkit/dom_storage/dom_storage_area.h +++ b/webkit/dom_storage/dom_storage_area.h @@ -27,6 +27,9 @@ class DomStorageArea : public base::RefCountedThreadSafe<DomStorageArea> { public: + static const FilePath::CharType kDatabaseFileExtension[]; + static FilePath DatabaseFileNameFromOrigin(const GURL& origin); + DomStorageArea(int64 namespace_id, const GURL& origin, const FilePath& directory, @@ -60,8 +63,6 @@ class DomStorageArea void ScheduleCommitChanges(); void CommitChanges(); - static FilePath DatabaseFileNameFromOrigin(const GURL& origin); - ~DomStorageArea(); int64 namespace_id_; diff --git a/webkit/dom_storage/dom_storage_context.cc b/webkit/dom_storage/dom_storage_context.cc index 21d2f8c..698f37b 100644 --- a/webkit/dom_storage/dom_storage_context.cc +++ b/webkit/dom_storage/dom_storage_context.cc @@ -6,20 +6,33 @@ #include "base/bind.h" #include "base/bind_helpers.h" +#include "base/file_util.h" #include "base/time.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" +#include "webkit/dom_storage/dom_storage_area.h" #include "webkit/dom_storage/dom_storage_namespace.h" #include "webkit/dom_storage/dom_storage_task_runner.h" #include "webkit/dom_storage/dom_storage_types.h" +#include "webkit/glue/webkit_glue.h" #include "webkit/quota/special_storage_policy.h" +using file_util::FileEnumerator; + namespace dom_storage { +DomStorageContext::UsageInfo::UsageInfo() {} +DomStorageContext::UsageInfo::~UsageInfo() {} + DomStorageContext::DomStorageContext( const FilePath& directory, quota::SpecialStoragePolicy* special_storage_policy, DomStorageTaskRunner* task_runner) : directory_(directory), - task_runner_(task_runner) { + task_runner_(task_runner), + clear_local_state_(false), + save_session_state_(false), + special_storage_policy_(special_storage_policy) { // AtomicSequenceNum starts at 0 but we want to start session // namespace ids at one since zero is reserved for the // kLocalStorageNamespaceId. @@ -44,6 +57,45 @@ DomStorageNamespace* DomStorageContext::GetStorageNamespace( return found->second; } +void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos) { + FileEnumerator enumerator(directory_, false, FileEnumerator::FILES); + for (FilePath path = enumerator.Next(); !path.empty(); + path = enumerator.Next()) { + if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { + UsageInfo info; + + // Extract origin id from the path and construct a GURL. + WebKit::WebString origin_id = webkit_glue::FilePathToWebString( + path.BaseName().RemoveExtension()); + info.origin = GURL(WebKit::WebSecurityOrigin:: + createFromDatabaseIdentifier(origin_id).toString()); + + FileEnumerator::FindInfo find_info; + enumerator.GetFindInfo(&find_info); + info.data_size = FileEnumerator::GetFilesize(find_info); + info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); + + infos->push_back(info); + } + } +} + +void DomStorageContext::DeleteOrigin(const GURL& origin) { + // TODO(michaeln): write me +} + +void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { + // TODO(michaeln): write me +} + +void DomStorageContext::PurgeMemory() { + // TODO(michaeln): write me +} + +void DomStorageContext::Shutdown() { + // TODO(michaeln): write me +} + void DomStorageContext::AddEventObserver(EventObserver* observer) { event_observers_.AddObserver(observer); } diff --git a/webkit/dom_storage/dom_storage_context.h b/webkit/dom_storage/dom_storage_context.h index fe17eec..484d8ac 100644 --- a/webkit/dom_storage/dom_storage_context.h +++ b/webkit/dom_storage/dom_storage_context.h @@ -7,15 +7,16 @@ #pragma once #include <map> +#include <vector> #include "base/atomic_sequence_num.h" #include "base/basictypes.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/observer_list.h" +#include "googleurl/src/gurl.h" class FilePath; -class GURL; class NullableString16; namespace base { @@ -55,6 +56,15 @@ class DomStorageTaskRunner; class DomStorageContext : public base::RefCountedThreadSafe<DomStorageContext> { public: + struct UsageInfo { + GURL origin; + size_t data_size; + base::Time last_modified; + + UsageInfo(); + ~UsageInfo(); + }; + // An interface for observing LocalStorage events on the // background thread. class EventObserver { @@ -79,9 +89,29 @@ class DomStorageContext DomStorageContext(const FilePath& directory, // empty for incognito profiles quota::SpecialStoragePolicy* special_storage_policy, DomStorageTaskRunner* task_runner); + const FilePath& directory() const { return directory_; } DomStorageTaskRunner* task_runner() const { return task_runner_; } DomStorageNamespace* GetStorageNamespace(int64 namespace_id); + void GetUsageInfo(std::vector<UsageInfo>* info); + void DeleteOrigin(const GURL& origin); + void DeleteDataModifiedSince(const base::Time& cutoff); + void PurgeMemory(); + + // Used by content settings to alter the behavior around + // what data to keep and what data to discard at shutdown. + // The policy is not so straight forward to describe, see + // the implementation for details. + void SetClearLocalState(bool clear_local_state) { + clear_local_state_ = clear_local_state; + } + void SaveSessionState() { + save_session_state_ = true; + } + + // Called when the BrowserContext/Profile is going away. + void Shutdown(); + // Methods to add, remove, and notify EventObservers. void AddEventObserver(EventObserver* observer); void RemoveEventObserver(EventObserver* observer); @@ -121,7 +151,7 @@ class DomStorageContext StorageNamespaceMap namespaces_; // Where localstorage data is stored, maybe empty for the incognito use case. - FilePath directory_; + const FilePath directory_; // Used to schedule sequenced background tasks. scoped_refptr<DomStorageTaskRunner> task_runner_; @@ -132,6 +162,10 @@ class DomStorageContext // We use a 32 bit identifier for per tab storage sessions. // At a tab per second, this range is large enough for 68 years. base::AtomicSequenceNumber session_id_sequence_; + + bool clear_local_state_; + bool save_session_state_; + scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy_; }; } // namespace dom_storage |