OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/in_process_webkit/dom_storage_context.h" | 5 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 31 matching lines...) Loading... |
42 } | 42 } |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = | 46 const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = |
47 FILE_PATH_LITERAL("Local Storage"); | 47 FILE_PATH_LITERAL("Local Storage"); |
48 | 48 |
49 const FilePath::CharType DOMStorageContext::kLocalStorageExtension[] = | 49 const FilePath::CharType DOMStorageContext::kLocalStorageExtension[] = |
50 FILE_PATH_LITERAL(".localstorage"); | 50 FILE_PATH_LITERAL(".localstorage"); |
51 | 51 |
52 static const FilePath::CharType kLocalStorageOldPath[] = | |
53 FILE_PATH_LITERAL("localStorage"); | |
54 | |
55 // TODO(jorlow): Remove after Chrome 4 ships. | |
56 static void MigrateLocalStorageDirectory(const FilePath& data_path) { | |
57 FilePath new_path = data_path.Append( | |
58 DOMStorageContext::kLocalStorageDirectory); | |
59 FilePath old_path = data_path.Append(kLocalStorageOldPath); | |
60 if (!file_util::DirectoryExists(new_path) && | |
61 file_util::DirectoryExists(old_path)) { | |
62 file_util::Move(old_path, new_path); | |
63 } | |
64 } | |
65 | |
66 DOMStorageContext::DOMStorageContext(WebKitContext* webkit_context) | 52 DOMStorageContext::DOMStorageContext(WebKitContext* webkit_context) |
67 : last_storage_area_id_(0), | 53 : last_storage_area_id_(0), |
68 last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), | 54 last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), |
69 last_session_storage_namespace_id_on_io_thread_(kLocalStorageNamespaceId), | 55 last_session_storage_namespace_id_on_io_thread_(kLocalStorageNamespaceId), |
70 clear_local_state_on_exit_(false) { | 56 clear_local_state_on_exit_(false) { |
71 data_path_ = webkit_context->data_path(); | 57 data_path_ = webkit_context->data_path(); |
72 } | 58 } |
73 | 59 |
74 DOMStorageContext::~DOMStorageContext() { | 60 DOMStorageContext::~DOMStorageContext() { |
75 // This should not go away until all DOM Storage message filters have gone | 61 // This should not go away until all DOM Storage message filters have gone |
(...skipping 175 matching lines...) Loading... |
251 file_util::FileEnumerator::FILES); | 237 file_util::FileEnumerator::FILES); |
252 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); | 238 for (FilePath file_path = file_enumerator.Next(); !file_path.empty(); |
253 file_path = file_enumerator.Next()) { | 239 file_path = file_enumerator.Next()) { |
254 if (file_path.Extension() == kLocalStorageExtension) | 240 if (file_path.Extension() == kLocalStorageExtension) |
255 file_util::Delete(file_path, false); | 241 file_util::Delete(file_path, false); |
256 } | 242 } |
257 } | 243 } |
258 | 244 |
259 DOMStorageNamespace* DOMStorageContext::CreateLocalStorage() { | 245 DOMStorageNamespace* DOMStorageContext::CreateLocalStorage() { |
260 FilePath dir_path; | 246 FilePath dir_path; |
261 if (!data_path_.empty()) { | 247 if (!data_path_.empty()) |
262 MigrateLocalStorageDirectory(data_path_); | |
263 dir_path = data_path_.Append(kLocalStorageDirectory); | 248 dir_path = data_path_.Append(kLocalStorageDirectory); |
264 } | |
265 DOMStorageNamespace* new_namespace = | 249 DOMStorageNamespace* new_namespace = |
266 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); | 250 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); |
267 RegisterStorageNamespace(new_namespace); | 251 RegisterStorageNamespace(new_namespace); |
268 return new_namespace; | 252 return new_namespace; |
269 } | 253 } |
270 | 254 |
271 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( | 255 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( |
272 int64 namespace_id) { | 256 int64 namespace_id) { |
273 DOMStorageNamespace* new_namespace = | 257 DOMStorageNamespace* new_namespace = |
274 DOMStorageNamespace::CreateSessionStorageNamespace(this, namespace_id); | 258 DOMStorageNamespace::CreateSessionStorageNamespace(this, namespace_id); |
(...skipping 21 matching lines...) Loading... |
296 } | 280 } |
297 | 281 |
298 FilePath DOMStorageContext::GetLocalStorageFilePath( | 282 FilePath DOMStorageContext::GetLocalStorageFilePath( |
299 const string16& origin_id) const { | 283 const string16& origin_id) const { |
300 FilePath storageDir = data_path_.Append( | 284 FilePath storageDir = data_path_.Append( |
301 DOMStorageContext::kLocalStorageDirectory); | 285 DOMStorageContext::kLocalStorageDirectory); |
302 FilePath::StringType id = | 286 FilePath::StringType id = |
303 webkit_glue::WebStringToFilePathString(origin_id); | 287 webkit_glue::WebStringToFilePathString(origin_id); |
304 return storageDir.Append(id.append(kLocalStorageExtension)); | 288 return storageDir.Append(id.append(kLocalStorageExtension)); |
305 } | 289 } |
OLD | NEW |