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/location.h" | 10 #include "base/location.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "webkit/dom_storage/dom_storage_area.h" | 12 #include "webkit/dom_storage/dom_storage_area.h" |
13 #include "webkit/dom_storage/dom_storage_namespace.h" | 13 #include "webkit/dom_storage/dom_storage_namespace.h" |
14 #include "webkit/dom_storage/dom_storage_task_runner.h" | 14 #include "webkit/dom_storage/dom_storage_task_runner.h" |
15 #include "webkit/dom_storage/dom_storage_types.h" | 15 #include "webkit/dom_storage/dom_storage_types.h" |
16 #include "webkit/quota/special_storage_policy.h" | 16 #include "webkit/quota/special_storage_policy.h" |
17 | 17 |
18 using file_util::FileEnumerator; | 18 using file_util::FileEnumerator; |
19 | 19 |
| 20 namespace { |
| 21 |
| 22 const char kLocalStorageDirectory[] = "Local Storage"; |
| 23 |
| 24 } // namespace |
| 25 |
20 namespace dom_storage { | 26 namespace dom_storage { |
21 | 27 |
22 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {} | 28 DomStorageContext::UsageInfo::UsageInfo() : data_size(0) {} |
23 DomStorageContext::UsageInfo::~UsageInfo() {} | 29 DomStorageContext::UsageInfo::~UsageInfo() {} |
24 | 30 |
25 DomStorageContext::DomStorageContext( | 31 DomStorageContext::DomStorageContext( |
26 const FilePath& directory, | 32 const FilePath& directory, |
27 quota::SpecialStoragePolicy* special_storage_policy, | 33 quota::SpecialStoragePolicy* special_storage_policy, |
28 DomStorageTaskRunner* task_runner) | 34 DomStorageTaskRunner* task_runner) |
29 : directory_(directory), | 35 : directory_(directory), |
(...skipping 11 matching lines...) Expand all Loading... |
41 DomStorageContext::~DomStorageContext() { | 47 DomStorageContext::~DomStorageContext() { |
42 } | 48 } |
43 | 49 |
44 DomStorageNamespace* DomStorageContext::GetStorageNamespace( | 50 DomStorageNamespace* DomStorageContext::GetStorageNamespace( |
45 int64 namespace_id) { | 51 int64 namespace_id) { |
46 if (is_shutdown_) | 52 if (is_shutdown_) |
47 return NULL; | 53 return NULL; |
48 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); | 54 StorageNamespaceMap::iterator found = namespaces_.find(namespace_id); |
49 if (found == namespaces_.end()) { | 55 if (found == namespaces_.end()) { |
50 if (namespace_id == kLocalStorageNamespaceId) { | 56 if (namespace_id == kLocalStorageNamespaceId) { |
51 if (!directory_.empty()) { | 57 FilePath target_directory = GetLocalStorageDirectory(); |
52 if (!file_util::CreateDirectory(directory_)) { | 58 if (!target_directory.empty()) { |
| 59 if (!file_util::CreateDirectory(target_directory)) { |
53 LOG(ERROR) << "Failed to create 'Local Storage' directory," | 60 LOG(ERROR) << "Failed to create 'Local Storage' directory," |
54 " falling back to in-memory only."; | 61 " falling back to in-memory only."; |
55 directory_ = FilePath(); | 62 target_directory = FilePath(); |
56 } | 63 } |
57 } | 64 } |
58 DomStorageNamespace* local = | 65 DomStorageNamespace* local = |
59 new DomStorageNamespace(directory_, task_runner_); | 66 new DomStorageNamespace(target_directory, task_runner_); |
60 namespaces_[kLocalStorageNamespaceId] = local; | 67 namespaces_[kLocalStorageNamespaceId] = local; |
61 return local; | 68 return local; |
62 } | 69 } |
63 return NULL; | 70 return NULL; |
64 } | 71 } |
65 return found->second; | 72 return found->second; |
66 } | 73 } |
67 | 74 |
| 75 FilePath DomStorageContext::GetLocalStorageDirectory() { |
| 76 if (directory_.empty()) |
| 77 return FilePath(); |
| 78 return directory_.AppendASCII(kLocalStorageDirectory); |
| 79 } |
| 80 |
68 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos, | 81 void DomStorageContext::GetUsageInfo(std::vector<UsageInfo>* infos, |
69 bool include_file_info) { | 82 bool include_file_info) { |
70 if (directory_.empty()) | 83 if (directory_.empty()) |
71 return; | 84 return; |
72 FileEnumerator enumerator(directory_, false, FileEnumerator::FILES); | 85 FileEnumerator enumerator(GetLocalStorageDirectory(), false, |
| 86 FileEnumerator::FILES); |
73 for (FilePath path = enumerator.Next(); !path.empty(); | 87 for (FilePath path = enumerator.Next(); !path.empty(); |
74 path = enumerator.Next()) { | 88 path = enumerator.Next()) { |
75 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { | 89 if (path.MatchesExtension(DomStorageArea::kDatabaseFileExtension)) { |
76 UsageInfo info; | 90 UsageInfo info; |
77 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); | 91 info.origin = DomStorageArea::OriginFromDatabaseFileName(path); |
78 if (include_file_info) { | 92 if (include_file_info) { |
79 FileEnumerator::FindInfo find_info; | 93 FileEnumerator::FindInfo find_info; |
80 enumerator.GetFindInfo(&find_info); | 94 enumerator.GetFindInfo(&find_info); |
81 info.data_size = FileEnumerator::GetFilesize(find_info); | 95 info.data_size = FileEnumerator::GetFilesize(find_info); |
82 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); | 96 info.last_modified = FileEnumerator::GetLastModifiedTime(find_info); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 for (size_t i = 0; i < infos.size(); ++i) { | 232 for (size_t i = 0; i < infos.size(); ++i) { |
219 const GURL& origin = infos[i].origin; | 233 const GURL& origin = infos[i].origin; |
220 if (special_storage_policy_ && | 234 if (special_storage_policy_ && |
221 special_storage_policy_->IsStorageProtected(origin)) | 235 special_storage_policy_->IsStorageProtected(origin)) |
222 continue; | 236 continue; |
223 if (!clear_local_state_ && | 237 if (!clear_local_state_ && |
224 !special_storage_policy_->IsStorageSessionOnly(origin)) | 238 !special_storage_policy_->IsStorageSessionOnly(origin)) |
225 continue; | 239 continue; |
226 | 240 |
227 const bool kNotRecursive = false; | 241 const bool kNotRecursive = false; |
228 FilePath database_file_path = directory_.Append( | 242 FilePath database_file_path = GetLocalStorageDirectory().Append( |
229 DomStorageArea::DatabaseFileNameFromOrigin(origin)); | 243 DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
230 file_util::Delete(database_file_path, kNotRecursive); | 244 file_util::Delete(database_file_path, kNotRecursive); |
231 file_util::Delete( | 245 file_util::Delete( |
232 DomStorageDatabase::GetJournalFilePath(database_file_path), | 246 DomStorageDatabase::GetJournalFilePath(database_file_path), |
233 kNotRecursive); | 247 kNotRecursive); |
234 } | 248 } |
235 } | 249 } |
236 | 250 |
237 } // namespace dom_storage | 251 } // namespace dom_storage |
OLD | NEW |