Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "webkit/dom_storage/dom_storage_context.h" | 5 #include "webkit/dom_storage/dom_storage_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | |
| 13 #include "webkit/dom_storage/dom_storage_area.h" | 11 #include "webkit/dom_storage/dom_storage_area.h" |
| 14 #include "webkit/dom_storage/dom_storage_namespace.h" | 12 #include "webkit/dom_storage/dom_storage_namespace.h" |
| 15 #include "webkit/dom_storage/dom_storage_task_runner.h" | 13 #include "webkit/dom_storage/dom_storage_task_runner.h" |
| 16 #include "webkit/dom_storage/dom_storage_types.h" | 14 #include "webkit/dom_storage/dom_storage_types.h" |
| 17 #include "webkit/glue/webkit_glue.h" | |
| 18 #include "webkit/quota/special_storage_policy.h" | 15 #include "webkit/quota/special_storage_policy.h" |
| 19 | 16 |
| 20 using file_util::FileEnumerator; | 17 using file_util::FileEnumerator; |
| 21 | 18 |
| 22 namespace dom_storage { | 19 namespace dom_storage { |
| 23 | 20 |
| 24 DomStorageContext::UsageInfo::UsageInfo() {} | 21 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {} |
| 25 DomStorageContext::UsageInfo::~UsageInfo() {} | 22 DomStorageContext::UsageInfo::~UsageInfo() {} |
| 26 | 23 |
| 27 DomStorageContext::DomStorageContext( | 24 DomStorageContext::DomStorageContext( |
| 28 const FilePath& directory, | 25 const FilePath& directory, |
| 29 quota::SpecialStoragePolicy* special_storage_policy, | 26 quota::SpecialStoragePolicy* special_storage_policy, |
| 30 DomStorageTaskRunner* task_runner) | 27 DomStorageTaskRunner* task_runner) |
| 31 : directory_(directory), | 28 : directory_(directory), |
| 32 task_runner_(task_runner), | 29 task_runner_(task_runner), |
| 33 is_shutdown_(false), | 30 is_shutdown_(false), |
| 34 clear_local_state_(false), | 31 clear_local_state_(false), |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 53 DomStorageNamespace* local = | 50 DomStorageNamespace* local = |
| 54 new DomStorageNamespace(directory_, task_runner_); | 51 new DomStorageNamespace(directory_, task_runner_); |
| 55 namespaces_[kLocalStorageNamespaceId] = local; | 52 namespaces_[kLocalStorageNamespaceId] = local; |
| 56 return local; | 53 return local; |
| 57 } | 54 } |
| 58 return NULL; | 55 return NULL; |
| 59 } | 56 } |
| 60 return found->second; | 57 return found->second; |
| 61 } | 58 } |
| 62 | 59 |
| 63 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos) { | 60 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos, |
| 61 bool include_file_info) { | |
| 62 if (directory_.empty()) | |
| 63 return; | |
| 64 FileEnumerator enumerator(directory_, false, FileEnumerator::FILES); | 64 FileEnumerator enumerator(directory_, false, FileEnumerator::FILES); |
| 65 for (FilePath path = enumerator.Next(); !path.empty(); | 65 for (FilePath path = enumerator.Next(); !path.empty(); |
| 66 path = enumerator.Next()) { | 66 path = enumerator.Next()) { |
| 67 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { | 67 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { |
| 68 UsageInfo info; | 68 UsageInfo info; |
| 69 | 69 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); |
| 70 // Extract origin id from the path and construct a GURL. | 70 if (include_file_info) { |
| 71 WebKit::WebString origin_id = webkit_glue::FilePathToWebString( | 71 FileEnumerator::FindInfo find_info; |
| 72 path.BaseName().RemoveExtension()); | 72 enumerator.GetFindInfo(&find_info); |
| 73 info.origin = GURL(WebKit::WebSecurityOrigin:: | 73 info.data_size = FileEnumerator::GetFilesize(find_info); |
| 74 createFromDatabaseIdentifier(origin_id).toString()); | 74 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); |
| 75 | 75 } |
| 76 FileEnumerator::FindInfo find_info; | |
| 77 enumerator.GetFindInfo(&find_info); | |
| 78 info.data_size = FileEnumerator::GetFilesize(find_info); | |
| 79 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); | |
| 80 | |
| 81 infos->push_back(info); | 76 infos->push_back(info); |
| 82 } | 77 } |
| 83 } | 78 } |
| 84 } | 79 } |
| 85 | 80 |
| 86 void DomStorageContext::DeleteOrigin(const GURL& origin) { | 81 void DomStorageContext::DeleteOrigin(const GURL& origin) { |
|
michaeln
2012/03/21 23:22:02
fyi: When this DeleteOrigin() method is invoked, n
| |
| 87 // TODO(michaeln): write me | 82 DCHECK(!is_shutdown_); |
| 83 DomStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); | |
| 84 local->DeleteOrigin(origin); | |
| 88 } | 85 } |
| 89 | 86 |
| 90 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { | 87 void DomStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { |
| 91 // TODO(michaeln): write me | 88 std::vector<UsageInfo> infos; |
| 89 GetUsageInfo(&infos, true); | |
| 90 for (size_t i = 0; i < infos.size(); ++i) { | |
| 91 if (infos[i].last_modified > cutoff) | |
| 92 DeleteOrigin(infos[i].origin); | |
| 93 } | |
| 92 } | 94 } |
| 93 | 95 |
| 94 void DomStorageContext::PurgeMemory() { | 96 void DomStorageContext::PurgeMemory() { |
| 95 // We can only purge memory from the local storage namespace | 97 // We can only purge memory from the local storage namespace |
| 96 // which is backed by disk. | 98 // which is backed by disk. |
| 97 StorageNamespaceMap::iterator found = | 99 StorageNamespaceMap::iterator found = |
| 98 namespaces_.find(kLocalStorageNamespaceId); | 100 namespaces_.find(kLocalStorageNamespaceId); |
| 99 if (found != namespaces_.end()) | 101 if (found != namespaces_.end()) |
| 100 found->second->PurgeMemory(); | 102 found->second->PurgeMemory(); |
| 101 } | 103 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 DCHECK_NE(kLocalStorageNamespaceId, existing_id); | 169 DCHECK_NE(kLocalStorageNamespaceId, existing_id); |
| 168 DCHECK_NE(kLocalStorageNamespaceId, new_id); | 170 DCHECK_NE(kLocalStorageNamespaceId, new_id); |
| 169 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); | 171 StorageNamespaceMap::iterator found = namespaces_.find(existing_id); |
| 170 if (found != namespaces_.end()) | 172 if (found != namespaces_.end()) |
| 171 namespaces_[new_id] = found->second->Clone(new_id); | 173 namespaces_[new_id] = found->second->Clone(new_id); |
| 172 else | 174 else |
| 173 CreateSessionNamespace(new_id); | 175 CreateSessionNamespace(new_id); |
| 174 } | 176 } |
| 175 | 177 |
| 176 } // namespace dom_storage | 178 } // namespace dom_storage |
| OLD | NEW |