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 "content/browser/dom_storage/dom_storage_context_impl.h" | 5 #include "content/browser/dom_storage/dom_storage_context_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 return local; | 101 return local; |
102 } | 102 } |
103 return NULL; | 103 return NULL; |
104 } | 104 } |
105 return found->second.get(); | 105 return found->second.get(); |
106 } | 106 } |
107 | 107 |
108 void DOMStorageContextImpl::GetLocalStorageUsage( | 108 void DOMStorageContextImpl::GetLocalStorageUsage( |
109 std::vector<LocalStorageUsageInfo>* infos, | 109 std::vector<LocalStorageUsageInfo>* infos, |
110 bool include_file_info) { | 110 bool include_file_info) { |
111 if (localstorage_directory_.empty()) | 111 if (localstorage_directory_.empty()) { |
| 112 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); |
| 113 std::vector<GURL> origins; |
| 114 local->GetOriginsWithAreas(&origins); |
| 115 for (const GURL& origin : origins) { |
| 116 LocalStorageUsageInfo info; |
| 117 info.origin = origin; |
| 118 infos->push_back(info); |
| 119 } |
112 return; | 120 return; |
| 121 } |
| 122 |
113 base::FileEnumerator enumerator(localstorage_directory_, false, | 123 base::FileEnumerator enumerator(localstorage_directory_, false, |
114 base::FileEnumerator::FILES); | 124 base::FileEnumerator::FILES); |
115 for (base::FilePath path = enumerator.Next(); !path.empty(); | 125 for (base::FilePath path = enumerator.Next(); !path.empty(); |
116 path = enumerator.Next()) { | 126 path = enumerator.Next()) { |
117 if (path.MatchesExtension(DOMStorageArea::kDatabaseFileExtension)) { | 127 if (path.MatchesExtension(DOMStorageArea::kDatabaseFileExtension)) { |
118 LocalStorageUsageInfo info; | 128 LocalStorageUsageInfo info; |
119 info.origin = DOMStorageArea::OriginFromDatabaseFileName(path); | 129 info.origin = DOMStorageArea::OriginFromDatabaseFileName(path); |
120 if (include_file_info) { | 130 if (include_file_info) { |
121 base::FileEnumerator::FileInfo find_info = enumerator.GetInfo(); | 131 base::FileEnumerator::FileInfo find_info = enumerator.GetInfo(); |
122 info.data_size = find_info.GetSize(); | 132 info.data_size = find_info.GetSize(); |
123 info.last_modified = find_info.GetLastModifiedTime(); | 133 info.last_modified = find_info.GetLastModifiedTime(); |
124 } | 134 } |
125 infos->push_back(info); | 135 infos->push_back(info); |
126 } | 136 } |
127 } | 137 } |
128 } | 138 } |
129 | 139 |
130 void DOMStorageContextImpl::GetSessionStorageUsage( | 140 void DOMStorageContextImpl::GetSessionStorageUsage( |
131 std::vector<SessionStorageUsageInfo>* infos) { | 141 std::vector<SessionStorageUsageInfo>* infos) { |
132 if (!session_storage_database_.get()) | 142 if (!session_storage_database_.get()) { |
| 143 for (const auto& entry : namespaces_) { |
| 144 std::vector<GURL> origins; |
| 145 entry.second->GetOriginsWithAreas(&origins); |
| 146 for (const GURL& origin : origins) { |
| 147 SessionStorageUsageInfo info; |
| 148 info.persistent_namespace_id = entry.second->persistent_namespace_id(); |
| 149 info.origin = origin; |
| 150 infos->push_back(info); |
| 151 } |
| 152 } |
133 return; | 153 return; |
| 154 } |
| 155 |
134 std::map<std::string, std::vector<GURL> > namespaces_and_origins; | 156 std::map<std::string, std::vector<GURL> > namespaces_and_origins; |
135 session_storage_database_->ReadNamespacesAndOrigins( | 157 session_storage_database_->ReadNamespacesAndOrigins( |
136 &namespaces_and_origins); | 158 &namespaces_and_origins); |
137 for (std::map<std::string, std::vector<GURL> >::const_iterator it = | 159 for (std::map<std::string, std::vector<GURL> >::const_iterator it = |
138 namespaces_and_origins.begin(); | 160 namespaces_and_origins.begin(); |
139 it != namespaces_and_origins.end(); ++it) { | 161 it != namespaces_and_origins.end(); ++it) { |
140 for (std::vector<GURL>::const_iterator origin_it = it->second.begin(); | 162 for (std::vector<GURL>::const_iterator origin_it = it->second.begin(); |
141 origin_it != it->second.end(); ++origin_it) { | 163 origin_it != it->second.end(); ++origin_it) { |
142 SessionStorageUsageInfo info; | 164 SessionStorageUsageInfo info; |
143 info.persistent_namespace_id = it->first; | 165 info.persistent_namespace_id = it->first; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (!deletable_persistent_namespace_ids_.empty()) { | 470 if (!deletable_persistent_namespace_ids_.empty()) { |
449 task_runner_->PostDelayedTask( | 471 task_runner_->PostDelayedTask( |
450 FROM_HERE, base::Bind( | 472 FROM_HERE, base::Bind( |
451 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 473 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
452 this), | 474 this), |
453 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 475 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
454 } | 476 } |
455 } | 477 } |
456 | 478 |
457 } // namespace content | 479 } // namespace content |
OLD | NEW |