Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: content/browser/indexed_db/indexed_db_context_impl.cc

Issue 2233153002: IndexedDB: WrapUnique(new T(args..)) -> MakeUnique<T>(args...) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/indexed_db/indexed_db_context_impl.h" 5 #include "content/browser/indexed_db/indexed_db_context_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 static bool HostNameComparator(const Origin& i, const Origin& j) { 159 static bool HostNameComparator(const Origin& i, const Origin& j) {
160 return i.host() < j.host(); 160 return i.host() < j.host();
161 } 161 }
162 162
163 base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() { 163 base::ListValue* IndexedDBContextImpl::GetAllOriginsDetails() {
164 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 164 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
165 std::vector<Origin> origins = GetAllOrigins(); 165 std::vector<Origin> origins = GetAllOrigins();
166 166
167 std::sort(origins.begin(), origins.end(), HostNameComparator); 167 std::sort(origins.begin(), origins.end(), HostNameComparator);
168 168
169 std::unique_ptr<base::ListValue> list(new base::ListValue()); 169 std::unique_ptr<base::ListValue> list(base::MakeUnique<base::ListValue>());
170 for (const auto& origin : origins) { 170 for (const auto& origin : origins) {
171 std::unique_ptr<base::DictionaryValue> info(new base::DictionaryValue()); 171 std::unique_ptr<base::DictionaryValue> info(
172 base::MakeUnique<base::DictionaryValue>());
172 info->SetString("url", origin.Serialize()); 173 info->SetString("url", origin.Serialize());
173 info->SetString("size", ui::FormatBytes(GetOriginDiskUsage(origin))); 174 info->SetString("size", ui::FormatBytes(GetOriginDiskUsage(origin)));
174 info->SetDouble("last_modified", GetOriginLastModified(origin).ToJsTime()); 175 info->SetDouble("last_modified", GetOriginLastModified(origin).ToJsTime());
175 if (!is_incognito()) { 176 if (!is_incognito()) {
176 std::unique_ptr<base::ListValue> paths(new base::ListValue()); 177 std::unique_ptr<base::ListValue> paths(
178 base::MakeUnique<base::ListValue>());
177 for (const base::FilePath& path : GetStoragePaths(origin)) 179 for (const base::FilePath& path : GetStoragePaths(origin))
178 paths->AppendString(path.value()); 180 paths->AppendString(path.value());
179 info->Set("paths", paths.release()); 181 info->Set("paths", paths.release());
180 } 182 }
181 info->SetDouble("connection_count", GetConnectionCount(origin)); 183 info->SetDouble("connection_count", GetConnectionCount(origin));
182 184
183 // This ends up being O(n^2) since we iterate over all open databases 185 // This ends up being O(n^2) since we iterate over all open databases
184 // to extract just those in the origin, and we're iterating over all 186 // to extract just those in the origin, and we're iterating over all
185 // origins in the outer loop. 187 // origins in the outer loop.
186 188
187 if (factory_.get()) { 189 if (factory_.get()) {
188 std::pair<IndexedDBFactory::OriginDBMapIterator, 190 std::pair<IndexedDBFactory::OriginDBMapIterator,
189 IndexedDBFactory::OriginDBMapIterator> 191 IndexedDBFactory::OriginDBMapIterator>
190 range = factory_->GetOpenDatabasesForOrigin(origin); 192 range = factory_->GetOpenDatabasesForOrigin(origin);
191 // TODO(jsbell): Sort by name? 193 // TODO(jsbell): Sort by name?
192 std::unique_ptr<base::ListValue> database_list(new base::ListValue()); 194 std::unique_ptr<base::ListValue> database_list(
195 base::MakeUnique<base::ListValue>());
193 196
194 for (IndexedDBFactory::OriginDBMapIterator it = range.first; 197 for (IndexedDBFactory::OriginDBMapIterator it = range.first;
195 it != range.second; 198 it != range.second;
196 ++it) { 199 ++it) {
197 const IndexedDBDatabase* db = it->second; 200 const IndexedDBDatabase* db = it->second;
198 std::unique_ptr<base::DictionaryValue> db_info( 201 std::unique_ptr<base::DictionaryValue> db_info(
199 new base::DictionaryValue()); 202 base::MakeUnique<base::DictionaryValue>());
200 203
201 db_info->SetString("name", db->name()); 204 db_info->SetString("name", db->name());
202 db_info->SetDouble("connection_count", db->ConnectionCount()); 205 db_info->SetDouble("connection_count", db->ConnectionCount());
203 db_info->SetDouble("active_open_delete", db->ActiveOpenDeleteCount()); 206 db_info->SetDouble("active_open_delete", db->ActiveOpenDeleteCount());
204 db_info->SetDouble("pending_open_delete", db->PendingOpenDeleteCount()); 207 db_info->SetDouble("pending_open_delete", db->PendingOpenDeleteCount());
205 208
206 std::unique_ptr<base::ListValue> transaction_list( 209 std::unique_ptr<base::ListValue> transaction_list(
207 new base::ListValue()); 210 base::MakeUnique<base::ListValue>());
208 std::vector<const IndexedDBTransaction*> transactions = 211 std::vector<const IndexedDBTransaction*> transactions =
209 db->transaction_coordinator().GetTransactions(); 212 db->transaction_coordinator().GetTransactions();
210 for (const auto* transaction : transactions) { 213 for (const auto* transaction : transactions) {
211 std::unique_ptr<base::DictionaryValue> transaction_info( 214 std::unique_ptr<base::DictionaryValue> transaction_info(
212 new base::DictionaryValue()); 215 base::MakeUnique<base::DictionaryValue>());
213 216
214 const char* const kModes[] = 217 const char* const kModes[] =
215 { "readonly", "readwrite", "versionchange" }; 218 { "readonly", "readwrite", "versionchange" };
216 transaction_info->SetString("mode", kModes[transaction->mode()]); 219 transaction_info->SetString("mode", kModes[transaction->mode()]);
217 switch (transaction->state()) { 220 switch (transaction->state()) {
218 case IndexedDBTransaction::CREATED: 221 case IndexedDBTransaction::CREATED:
219 transaction_info->SetString("status", "blocked"); 222 transaction_info->SetString("status", "blocked");
220 break; 223 break;
221 case IndexedDBTransaction::STARTED: 224 case IndexedDBTransaction::STARTED:
222 if (transaction->diagnostics().tasks_scheduled > 0) 225 if (transaction->diagnostics().tasks_scheduled > 0)
(...skipping 23 matching lines...) Expand all
246 .InMillisecondsF()); 249 .InMillisecondsF());
247 transaction_info->SetDouble( 250 transaction_info->SetDouble(
248 "runtime", 251 "runtime",
249 (base::Time::Now() - transaction->diagnostics().start_time) 252 (base::Time::Now() - transaction->diagnostics().start_time)
250 .InMillisecondsF()); 253 .InMillisecondsF());
251 transaction_info->SetDouble( 254 transaction_info->SetDouble(
252 "tasks_scheduled", transaction->diagnostics().tasks_scheduled); 255 "tasks_scheduled", transaction->diagnostics().tasks_scheduled);
253 transaction_info->SetDouble( 256 transaction_info->SetDouble(
254 "tasks_completed", transaction->diagnostics().tasks_completed); 257 "tasks_completed", transaction->diagnostics().tasks_completed);
255 258
256 std::unique_ptr<base::ListValue> scope(new base::ListValue()); 259 std::unique_ptr<base::ListValue> scope(
260 base::MakeUnique<base::ListValue>());
257 for (const auto& id : transaction->scope()) { 261 for (const auto& id : transaction->scope()) {
258 const auto& it = db->metadata().object_stores.find(id); 262 const auto& it = db->metadata().object_stores.find(id);
259 if (it != db->metadata().object_stores.end()) 263 if (it != db->metadata().object_stores.end())
260 scope->AppendString(it->second.name); 264 scope->AppendString(it->second.name);
261 } 265 }
262 266
263 transaction_info->Set("scope", scope.release()); 267 transaction_info->Set("scope", scope.release());
264 transaction_list->Append(std::move(transaction_info)); 268 transaction_list->Append(std::move(transaction_info));
265 } 269 }
266 db_info->Set("transactions", transaction_list.release()); 270 db_info->Set("transactions", transaction_list.release());
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 quota_manager_proxy()->NotifyStorageModified( 553 quota_manager_proxy()->NotifyStorageModified(
550 storage::QuotaClient::kIndexedDatabase, GURL(origin.Serialize()), 554 storage::QuotaClient::kIndexedDatabase, GURL(origin.Serialize()),
551 storage::kStorageTypeTemporary, difference); 555 storage::kStorageTypeTemporary, difference);
552 } 556 }
553 } 557 }
554 558
555 std::set<Origin>* IndexedDBContextImpl::GetOriginSet() { 559 std::set<Origin>* IndexedDBContextImpl::GetOriginSet() {
556 if (!origin_set_) { 560 if (!origin_set_) {
557 std::vector<Origin> origins; 561 std::vector<Origin> origins;
558 GetAllOriginsAndPaths(data_path_, &origins, NULL); 562 GetAllOriginsAndPaths(data_path_, &origins, NULL);
559 origin_set_.reset(new std::set<Origin>(origins.begin(), origins.end())); 563 origin_set_ =
564 base::MakeUnique<std::set<Origin>>(origins.begin(), origins.end());
560 } 565 }
561 return origin_set_.get(); 566 return origin_set_.get();
562 } 567 }
563 568
564 void IndexedDBContextImpl::ResetCaches() { 569 void IndexedDBContextImpl::ResetCaches() {
565 origin_set_.reset(); 570 origin_set_.reset();
566 origin_size_map_.clear(); 571 origin_size_map_.clear();
567 } 572 }
568 573
569 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { 574 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const {
570 return task_runner_.get(); 575 return task_runner_.get();
571 } 576 }
572 577
573 } // namespace content 578 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_cleanup_on_io_error_unittest.cc ('k') | content/browser/indexed_db/indexed_db_cursor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698