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,41 @@ |
| 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; |
| + const bool kIncludeFileInfo = true; |
| + GetUsageInfo(&infos, kIncludeFileInfo); |
| + for (size_t i = 0; i < infos.size(); ++i) { |
| + if (infos[i].last_modified > cutoff) |
|
michaeln
2012/03/22 05:34:40
ooops... i have to consult policy->IsStorageProtec
michaeln
2012/03/22 19:00:57
Done.
|
| + DeleteOrigin(infos[i].origin); |
| + } |
| } |
| void DomStorageContext::PurgeMemory() { |
| @@ -105,6 +109,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) { |
| + // We may have to delete something. We continue on the |
| + // commit sequence after area shutdown tasks have cycled |
| + // thru that sequence (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 +200,27 @@ |
| CreateSessionNamespace(new_id); |
| } |
| +void DomStorageContext::ClearLocalStateInCommitSequence() { |
| + std::vector<UsageInfo> infos; |
| + const bool kDontIncludeFileInfo = false; |
| + GetUsageInfo(&infos, kDontIncludeFileInfo); |
| + 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; |
| + |
| + const bool kNotRecursive = false; |
| + FilePath database_file_path = directory_.Append( |
| + DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
| + file_util::Delete(database_file_path, kNotRecursive); |
| + file_util::Delete( |
| + DomStorageDatabase::GetJournalFilePath(database_file_path), |
| + kNotRecursive); |
| + } |
| +} |
| + |
| } // namespace dom_storage |