| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 5 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
| 10 #include "chrome/browser/in_process_webkit/dom_storage_area.h" | 10 #include "chrome/browser/in_process_webkit/dom_storage_area.h" |
| 11 #include "chrome/browser/in_process_webkit/dom_storage_namespace.h" | 11 #include "chrome/browser/in_process_webkit/dom_storage_namespace.h" |
| 12 #include "chrome/browser/in_process_webkit/webkit_context.h" | 12 #include "chrome/browser/in_process_webkit/webkit_context.h" |
| 13 #include "chrome/common/dom_storage_common.h" | 13 #include "chrome/common/dom_storage_common.h" |
| 14 #include "webkit/glue/glue_util.h" |
| 14 | 15 |
| 15 static const char* kLocalStorageDirectory = "Local Storage"; | 16 const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = |
| 17 FILE_PATH_LITERAL("Local Storage"); |
| 18 |
| 19 const FilePath::CharType DOMStorageContext::kLocalStorageExtension[] = |
| 20 FILE_PATH_LITERAL(".localstorage"); |
| 21 |
| 22 static const FilePath::CharType kLocalStorageOldPath[] = |
| 23 FILE_PATH_LITERAL("localStorage"); |
| 16 | 24 |
| 17 // TODO(jorlow): Remove after Chrome 4 ships. | 25 // TODO(jorlow): Remove after Chrome 4 ships. |
| 18 static void MigrateLocalStorageDirectory(const FilePath& data_path) { | 26 static void MigrateLocalStorageDirectory(const FilePath& data_path) { |
| 19 FilePath new_path = data_path.AppendASCII(kLocalStorageDirectory); | 27 FilePath new_path = data_path.Append( |
| 20 FilePath old_path = data_path.AppendASCII("localStorage"); | 28 DOMStorageContext::kLocalStorageDirectory); |
| 29 FilePath old_path = data_path.Append(kLocalStorageOldPath); |
| 21 if (!file_util::DirectoryExists(new_path) && | 30 if (!file_util::DirectoryExists(new_path) && |
| 22 file_util::DirectoryExists(old_path)) { | 31 file_util::DirectoryExists(old_path)) { |
| 23 file_util::Move(old_path, new_path); | 32 file_util::Move(old_path, new_path); |
| 24 } | 33 } |
| 25 } | 34 } |
| 26 | 35 |
| 27 DOMStorageContext::DOMStorageContext(WebKitContext* webkit_context) | 36 DOMStorageContext::DOMStorageContext(WebKitContext* webkit_context) |
| 28 : last_storage_area_id_(0), | 37 : last_storage_area_id_(0), |
| 29 last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), | 38 last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), |
| 30 last_session_storage_namespace_id_on_io_thread_(kLocalStorageNamespaceId), | 39 last_session_storage_namespace_id_on_io_thread_(kLocalStorageNamespaceId), |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (local_storage) | 150 if (local_storage) |
| 142 local_storage->PurgeMemory(); | 151 local_storage->PurgeMemory(); |
| 143 } | 152 } |
| 144 | 153 |
| 145 void DOMStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { | 154 void DOMStorageContext::DeleteDataModifiedSince(const base::Time& cutoff) { |
| 146 // Make sure that we don't delete a database that's currently being accessed | 155 // Make sure that we don't delete a database that's currently being accessed |
| 147 // by unloading all of the databases temporarily. | 156 // by unloading all of the databases temporarily. |
| 148 PurgeMemory(); | 157 PurgeMemory(); |
| 149 | 158 |
| 150 file_util::FileEnumerator file_enumerator( | 159 file_util::FileEnumerator file_enumerator( |
| 151 webkit_context_->data_path().AppendASCII(kLocalStorageDirectory), false, | 160 webkit_context_->data_path().Append(kLocalStorageDirectory), false, |
| 152 file_util::FileEnumerator::FILES); | 161 file_util::FileEnumerator::FILES); |
| 153 for (FilePath path = file_enumerator.Next(); !path.value().empty(); | 162 for (FilePath path = file_enumerator.Next(); !path.value().empty(); |
| 154 path = file_enumerator.Next()) { | 163 path = file_enumerator.Next()) { |
| 155 file_util::FileEnumerator::FindInfo find_info; | 164 file_util::FileEnumerator::FindInfo find_info; |
| 156 file_enumerator.GetFindInfo(&find_info); | 165 file_enumerator.GetFindInfo(&find_info); |
| 157 if (file_util::HasFileBeenModifiedSince(find_info, cutoff)) | 166 if (file_util::HasFileBeenModifiedSince(find_info, cutoff)) |
| 158 file_util::Delete(path, false); | 167 file_util::Delete(path, false); |
| 159 } | 168 } |
| 160 } | 169 } |
| 161 | 170 |
| 171 void DOMStorageContext::DeleteLocalStorageFile(const FilePath& file_path) { |
| 172 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 173 |
| 174 // Make sure that we don't delete a database that's currently being accessed |
| 175 // by unloading all of the databases temporarily. |
| 176 // TODO(bulach): both this method and DeleteDataModifiedSince could purge |
| 177 // only the memory used by the specific file instead of all memory at once. |
| 178 // See http://code.google.com/p/chromium/issues/detail?id=32000 |
| 179 PurgeMemory(); |
| 180 file_util::Delete(file_path, false); |
| 181 } |
| 182 |
| 183 void DOMStorageContext::DeleteAllLocalStorageFiles() { |
| 184 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 185 |
| 186 // Make sure that we don't delete a database that's currently being accessed |
| 187 // by unloading all of the databases temporarily. |
| 188 PurgeMemory(); |
| 189 |
| 190 file_util::FileEnumerator file_enumerator( |
| 191 webkit_context_->data_path().Append(kLocalStorageDirectory), false, |
| 192 file_util::FileEnumerator::FILES); |
| 193 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
| 194 file_path = file_enumerator.Next()) { |
| 195 if (file_path.Extension() == kLocalStorageExtension) |
| 196 file_util::Delete(file_path, false); |
| 197 } |
| 198 } |
| 199 |
| 162 DOMStorageNamespace* DOMStorageContext::CreateLocalStorage() { | 200 DOMStorageNamespace* DOMStorageContext::CreateLocalStorage() { |
| 163 FilePath data_path = webkit_context_->data_path(); | 201 FilePath data_path = webkit_context_->data_path(); |
| 164 FilePath dir_path; | 202 FilePath dir_path; |
| 165 if (!data_path.empty()) { | 203 if (!data_path.empty()) { |
| 166 MigrateLocalStorageDirectory(data_path); | 204 MigrateLocalStorageDirectory(data_path); |
| 167 dir_path = data_path.AppendASCII(kLocalStorageDirectory); | 205 dir_path = data_path.Append(kLocalStorageDirectory); |
| 168 } | 206 } |
| 169 DOMStorageNamespace* new_namespace = | 207 DOMStorageNamespace* new_namespace = |
| 170 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); | 208 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); |
| 171 RegisterStorageNamespace(new_namespace); | 209 RegisterStorageNamespace(new_namespace); |
| 172 return new_namespace; | 210 return new_namespace; |
| 173 } | 211 } |
| 174 | 212 |
| 175 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( | 213 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( |
| 176 int64 namespace_id) { | 214 int64 namespace_id) { |
| 177 DOMStorageNamespace* new_namespace = | 215 DOMStorageNamespace* new_namespace = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 191 /* static */ | 229 /* static */ |
| 192 void DOMStorageContext::CompleteCloningSessionStorage( | 230 void DOMStorageContext::CompleteCloningSessionStorage( |
| 193 DOMStorageContext* context, int64 existing_id, int64 clone_id) { | 231 DOMStorageContext* context, int64 existing_id, int64 clone_id) { |
| 194 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); | 232 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT)); |
| 195 DOMStorageNamespace* existing_namespace = | 233 DOMStorageNamespace* existing_namespace = |
| 196 context->GetStorageNamespace(existing_id, false); | 234 context->GetStorageNamespace(existing_id, false); |
| 197 // If nothing exists, then there's nothing to clone. | 235 // If nothing exists, then there's nothing to clone. |
| 198 if (existing_namespace) | 236 if (existing_namespace) |
| 199 context->RegisterStorageNamespace(existing_namespace->Copy(clone_id)); | 237 context->RegisterStorageNamespace(existing_namespace->Copy(clone_id)); |
| 200 } | 238 } |
| OLD | NEW |