Chromium Code Reviews| Index: webkit/dom_storage/dom_storage_context.cc |
| =================================================================== |
| --- webkit/dom_storage/dom_storage_context.cc (revision 127981) |
| +++ webkit/dom_storage/dom_storage_context.cc (working copy) |
| @@ -7,21 +7,19 @@ |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| #include "base/file_util.h" |
| +#include "base/location.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() : data_size(0) {} |
| DomStorageContext::UsageInfo::~UsageInfo() {} |
| DomStorageContext::DomStorageContext( |
| @@ -60,35 +58,40 @@ |
| return found->second; |
| } |
| -void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos) { |
| +void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos, |
| + bool include_file_info) { |
| + if (directory_.empty()) |
| + return; |
| 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); |
| - |
| + info.origin = DomStorageArea::OriginFromDatabaseFileName(path); |
| + if (include_file_info) { |
| + 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 |
| + DCHECK(!is_shutdown_); |
| + DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
| + local->DeleteOrigin(origin); |
| } |
| void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { |
| - // TODO(michaeln): write me |
| + std::vector<UsageInfo> infos; |
| + GetUsageInfo(&infos, true); |
| + for (size_t i = 0; i < infos.size(); ++i) { |
| + if (infos[i].last_modified > cutoff) |
| + DeleteOrigin(infos[i].origin); |
| + } |
| } |
| void DomStorageContext::PurgeMemory() { |
| @@ -105,6 +108,29 @@ |
| StorageNamespaceMap::const_iterator it = namespaces_.begin(); |
| for (; it != namespaces_.end(); ++it) |
| it->second->Shutdown(); |
| + |
| + if (directory_.empty()) |
| + return; |
| + |
| + // Respect the content policy settings about what to |
| + // keep and what to discard. |
| + if (save_session_state_) |
| + return; // Keep everything. |
| + |
| + bool has_session_only_origins = |
| + special_storage_policy_.get() && |
| + special_storage_policy_->HasSessionOnlyOrigins(); |
| + if (!clear_local_state_ && !has_session_only_origins) |
|
jsbell
2012/03/22 00:27:46
Just for readability, perhaps change this to:
if
michaeln
2012/03/22 00:53:17
Done.
|
| + return; // Only clearing session-only origins and there are none. |
| + |
| + // We continue on the commit sequence so our ClearLocalState |
| + // task executes after all areas have been shutdown (and closed |
| + // their database files). |
| + bool success = task_runner_->PostShutdownBlockingTask( |
| + FROM_HERE, |
| + DomStorageTaskRunner::COMMIT_SEQUENCE, |
| + base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this)); |
| + DCHECK(success); |
| } |
| void DomStorageContext::AddEventObserver(EventObserver* observer) { |
| @@ -173,4 +199,24 @@ |
| CreateSessionNamespace(new_id); |
| } |
| +void DomStorageContext::ClearLocalStateInCommitSequence() { |
| + std::vector<UsageInfo> infos; |
| + GetUsageInfo(&infos, false); |
|
jsbell
2012/03/22 00:27:46
nit: named constant here?
michaeln
2012/03/22 00:53:17
Done.
|
| + for (size_t i = 0; i < infos.size(); ++i) { |
| + const GURL& origin = infos[i].origin; |
| + if (special_storage_policy_ && |
| + special_storage_policy_->IsStorageProtected(origin)) |
| + continue; |
| + if (!clear_local_state_ && |
| + !special_storage_policy_->IsStorageSessionOnly(origin)) |
| + continue; |
| + |
| + FilePath database_file_path = directory_.Append( |
| + DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
| + file_util::Delete(database_file_path, false); |
|
jsbell
2012/03/22 00:27:46
nit: and here?
michaeln
2012/03/22 00:53:17
Done.
|
| + file_util::Delete( |
| + DomStorageDatabase::GetJournalFilePath(database_file_path), false); |
| + } |
| +} |
| + |
| } // namespace dom_storage |