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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 return local; | 88 return local; |
89 } | 89 } |
90 return NULL; | 90 return NULL; |
91 } | 91 } |
92 return found->second.get(); | 92 return found->second.get(); |
93 } | 93 } |
94 | 94 |
95 void DOMStorageContextImpl::GetLocalStorageUsage( | 95 void DOMStorageContextImpl::GetLocalStorageUsage( |
96 std::vector<LocalStorageUsageInfo>* infos, | 96 std::vector<LocalStorageUsageInfo>* infos, |
97 bool include_file_info) { | 97 bool include_file_info) { |
98 if (localstorage_directory_.empty()) | 98 if (localstorage_directory_.empty()) { |
99 DOMStorageNamespace* local = GetStorageNamespace(kLocalStorageNamespaceId); | |
100 std::vector<GURL> origins; | |
101 local->ReadOrigins(&origins); | |
102 for (std::vector<GURL>::const_iterator origin_it = origins.begin(); | |
michaeln
2016/05/05 00:38:23
please use a range based for loop for this one
fo
Julien Isorce Samsung
2016/05/05 11:05:04
Done.
| |
103 origin_it != origins.end(); ++origin_it) { | |
104 LocalStorageUsageInfo info; | |
105 info.origin = *origin_it; | |
106 infos->push_back(info); | |
107 } | |
99 return; | 108 return; |
109 } | |
110 | |
100 base::FileEnumerator enumerator(localstorage_directory_, false, | 111 base::FileEnumerator enumerator(localstorage_directory_, false, |
101 base::FileEnumerator::FILES); | 112 base::FileEnumerator::FILES); |
102 for (base::FilePath path = enumerator.Next(); !path.empty(); | 113 for (base::FilePath path = enumerator.Next(); !path.empty(); |
103 path = enumerator.Next()) { | 114 path = enumerator.Next()) { |
104 if (path.MatchesExtension(DOMStorageArea::kDatabaseFileExtension)) { | 115 if (path.MatchesExtension(DOMStorageArea::kDatabaseFileExtension)) { |
105 LocalStorageUsageInfo info; | 116 LocalStorageUsageInfo info; |
106 info.origin = DOMStorageArea::OriginFromDatabaseFileName(path); | 117 info.origin = DOMStorageArea::OriginFromDatabaseFileName(path); |
107 if (include_file_info) { | 118 if (include_file_info) { |
108 base::FileEnumerator::FileInfo find_info = enumerator.GetInfo(); | 119 base::FileEnumerator::FileInfo find_info = enumerator.GetInfo(); |
109 info.data_size = find_info.GetSize(); | 120 info.data_size = find_info.GetSize(); |
110 info.last_modified = find_info.GetLastModifiedTime(); | 121 info.last_modified = find_info.GetLastModifiedTime(); |
111 } | 122 } |
112 infos->push_back(info); | 123 infos->push_back(info); |
113 } | 124 } |
114 } | 125 } |
115 } | 126 } |
116 | 127 |
117 void DOMStorageContextImpl::GetSessionStorageUsage( | 128 void DOMStorageContextImpl::GetSessionStorageUsage( |
118 std::vector<SessionStorageUsageInfo>* infos) { | 129 std::vector<SessionStorageUsageInfo>* infos) { |
119 if (!session_storage_database_.get()) | 130 if (!session_storage_database_.get()) { |
131 for (StorageNamespaceMap::const_iterator namespace_it = namespaces_.begin(); | |
132 namespace_it != namespaces_.end(); ++namespace_it) { | |
michaeln
2016/05/05 00:38:23
might be nice to use range based loops here too
Julien Isorce Samsung
2016/05/05 11:05:04
Done and I used "auto" like in DOMStorageContextIm
| |
133 std::vector<GURL> origins; | |
134 namespace_it->second->ReadOrigins(&origins); | |
135 for (std::vector<GURL>::const_iterator origin_it = origins.begin(); | |
136 origin_it != origins.end(); ++origin_it) { | |
137 SessionStorageUsageInfo info; | |
138 info.persistent_namespace_id = | |
139 namespace_it->second->persistent_namespace_id(); | |
140 info.origin = *origin_it; | |
141 infos->push_back(info); | |
142 } | |
143 } | |
120 return; | 144 return; |
145 } | |
146 | |
121 std::map<std::string, std::vector<GURL> > namespaces_and_origins; | 147 std::map<std::string, std::vector<GURL> > namespaces_and_origins; |
122 session_storage_database_->ReadNamespacesAndOrigins( | 148 session_storage_database_->ReadNamespacesAndOrigins( |
123 &namespaces_and_origins); | 149 &namespaces_and_origins); |
124 for (std::map<std::string, std::vector<GURL> >::const_iterator it = | 150 for (std::map<std::string, std::vector<GURL> >::const_iterator it = |
125 namespaces_and_origins.begin(); | 151 namespaces_and_origins.begin(); |
126 it != namespaces_and_origins.end(); ++it) { | 152 it != namespaces_and_origins.end(); ++it) { |
127 for (std::vector<GURL>::const_iterator origin_it = it->second.begin(); | 153 for (std::vector<GURL>::const_iterator origin_it = it->second.begin(); |
128 origin_it != it->second.end(); ++origin_it) { | 154 origin_it != it->second.end(); ++origin_it) { |
129 SessionStorageUsageInfo info; | 155 SessionStorageUsageInfo info; |
130 info.persistent_namespace_id = it->first; | 156 info.persistent_namespace_id = it->first; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 if (!deletable_persistent_namespace_ids_.empty()) { | 446 if (!deletable_persistent_namespace_ids_.empty()) { |
421 task_runner_->PostDelayedTask( | 447 task_runner_->PostDelayedTask( |
422 FROM_HERE, base::Bind( | 448 FROM_HERE, base::Bind( |
423 &DOMStorageContextImpl::DeleteNextUnusedNamespace, | 449 &DOMStorageContextImpl::DeleteNextUnusedNamespace, |
424 this), | 450 this), |
425 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); | 451 base::TimeDelta::FromSeconds(kSessionStoraceScavengingSeconds)); |
426 } | 452 } |
427 } | 453 } |
428 | 454 |
429 } // namespace content | 455 } // namespace content |
OLD | NEW |