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

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

Issue 2930183002: Let IndexedDBContextImpl create its own task runner (Closed)
Patch Set: rebased Created 3 years, 5 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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_enumerator.h" 12 #include "base/files/file_enumerator.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "base/sequenced_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "base/task_scheduler/post_task.h"
20 #include "base/threading/thread_restrictions.h" 21 #include "base/threading/thread_restrictions.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
23 #include "base/values.h" 24 #include "base/values.h"
24 #include "content/browser/browser_main_loop.h" 25 #include "content/browser/browser_main_loop.h"
25 #include "content/browser/indexed_db/indexed_db_connection.h" 26 #include "content/browser/indexed_db/indexed_db_connection.h"
26 #include "content/browser/indexed_db/indexed_db_database.h" 27 #include "content/browser/indexed_db/indexed_db_database.h"
27 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 28 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
28 #include "content/browser/indexed_db/indexed_db_factory_impl.h" 29 #include "content/browser/indexed_db/indexed_db_factory_impl.h"
29 #include "content/browser/indexed_db/indexed_db_quota_client.h" 30 #include "content/browser/indexed_db/indexed_db_quota_client.h"
30 #include "content/browser/indexed_db/indexed_db_tracing.h" 31 #include "content/browser/indexed_db/indexed_db_tracing.h"
31 #include "content/browser/indexed_db/indexed_db_transaction.h" 32 #include "content/browser/indexed_db/indexed_db_transaction.h"
32 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
33 #include "content/public/browser/indexed_db_info.h" 34 #include "content/public/browser/indexed_db_info.h"
34 #include "content/public/common/content_switches.h" 35 #include "content/public/common/content_switches.h"
35 #include "storage/browser/database/database_util.h" 36 #include "storage/browser/database/database_util.h"
36 #include "storage/browser/quota/quota_manager_proxy.h"
37 #include "storage/browser/quota/special_storage_policy.h"
38 #include "storage/common/database/database_identifier.h" 37 #include "storage/common/database/database_identifier.h"
39 #include "ui/base/text/bytes_formatting.h" 38 #include "ui/base/text/bytes_formatting.h"
40 #include "url/origin.h" 39 #include "url/origin.h"
41 40
42 using base::DictionaryValue; 41 using base::DictionaryValue;
43 using base::ListValue; 42 using base::ListValue;
44 using storage::DatabaseUtil; 43 using storage::DatabaseUtil;
45 using url::Origin; 44 using url::Origin;
46 45
47 namespace content { 46 namespace content {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (special_storage_policy->IsStorageProtected(origin_url)) 100 if (special_storage_policy->IsStorageProtected(origin_url))
102 continue; 101 continue;
103 base::DeleteFile(*file_path, true); 102 base::DeleteFile(*file_path, true);
104 } 103 }
105 } 104 }
106 105
107 } // namespace 106 } // namespace
108 107
109 IndexedDBContextImpl::IndexedDBContextImpl( 108 IndexedDBContextImpl::IndexedDBContextImpl(
110 const base::FilePath& data_path, 109 const base::FilePath& data_path,
111 storage::SpecialStoragePolicy* special_storage_policy, 110 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy,
112 storage::QuotaManagerProxy* quota_manager_proxy, 111 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy)
113 scoped_refptr<base::SequencedTaskRunner> task_runner)
114 : force_keep_session_state_(false), 112 : force_keep_session_state_(false),
115 special_storage_policy_(special_storage_policy), 113 special_storage_policy_(special_storage_policy),
116 quota_manager_proxy_(quota_manager_proxy), 114 quota_manager_proxy_(quota_manager_proxy),
117 task_runner_(std::move(task_runner)) { 115 task_runner_(base::CreateSequencedTaskRunnerWithTraits(
116 {base::MayBlock(), base::WithBaseSyncPrimitives(),
117 base::TaskPriority::USER_VISIBLE,
118 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})) {
118 IDB_TRACE("init"); 119 IDB_TRACE("init");
119 if (!data_path.empty()) 120 if (!data_path.empty())
120 data_path_ = data_path.Append(kIndexedDBDirectory); 121 data_path_ = data_path.Append(kIndexedDBDirectory);
121 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this)); 122 quota_manager_proxy->RegisterClient(new IndexedDBQuotaClient(this));
122 } 123 }
123 124
124 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() { 125 IndexedDBFactory* IndexedDBContextImpl::GetIDBFactory() {
125 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); 126 DCHECK(TaskRunner()->RunsTasksInCurrentSequence());
126 if (!factory_.get()) { 127 if (!factory_.get()) {
127 // Prime our cache of origins with existing databases so we can 128 // Prime our cache of origins with existing databases so we can
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 const GURL& origin_url) const { 420 const GURL& origin_url) const {
420 return GetFilePathForTesting(Origin(origin_url)); 421 return GetFilePathForTesting(Origin(origin_url));
421 } 422 }
422 423
423 base::FilePath IndexedDBContextImpl::GetFilePathForTesting( 424 base::FilePath IndexedDBContextImpl::GetFilePathForTesting(
424 const Origin& origin) const { 425 const Origin& origin) const {
425 return GetLevelDBPath(origin); 426 return GetLevelDBPath(origin);
426 } 427 }
427 428
428 void IndexedDBContextImpl::SetTaskRunnerForTesting( 429 void IndexedDBContextImpl::SetTaskRunnerForTesting(
429 base::SequencedTaskRunner* task_runner) { 430 scoped_refptr<base::SequencedTaskRunner> task_runner) {
430 DCHECK(!task_runner_.get()); 431 task_runner_ = std::move(task_runner);
431 task_runner_ = task_runner; 432 }
433
434 void IndexedDBContextImpl::ResetCachesForTesting() {
435 origin_set_.reset();
436 origin_size_map_.clear();
432 } 437 }
433 438
434 void IndexedDBContextImpl::ConnectionOpened(const Origin& origin, 439 void IndexedDBContextImpl::ConnectionOpened(const Origin& origin,
435 IndexedDBConnection* connection) { 440 IndexedDBConnection* connection) {
436 DCHECK(TaskRunner()->RunsTasksInCurrentSequence()); 441 DCHECK(TaskRunner()->RunsTasksInCurrentSequence());
437 quota_manager_proxy()->NotifyStorageAccessed( 442 quota_manager_proxy()->NotifyStorageAccessed(
438 storage::QuotaClient::kIndexedDatabase, origin.GetURL(), 443 storage::QuotaClient::kIndexedDatabase, origin.GetURL(),
439 storage::kStorageTypeTemporary); 444 storage::kStorageTypeTemporary);
440 if (AddToOriginSet(origin)) { 445 if (AddToOriginSet(origin)) {
441 // A newly created db, notify the quota system. 446 // A newly created db, notify the quota system.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 std::set<Origin>* IndexedDBContextImpl::GetOriginSet() { 557 std::set<Origin>* IndexedDBContextImpl::GetOriginSet() {
553 if (!origin_set_) { 558 if (!origin_set_) {
554 std::vector<Origin> origins; 559 std::vector<Origin> origins;
555 GetAllOriginsAndPaths(data_path_, &origins, NULL); 560 GetAllOriginsAndPaths(data_path_, &origins, NULL);
556 origin_set_ = 561 origin_set_ =
557 base::MakeUnique<std::set<Origin>>(origins.begin(), origins.end()); 562 base::MakeUnique<std::set<Origin>>(origins.begin(), origins.end());
558 } 563 }
559 return origin_set_.get(); 564 return origin_set_.get();
560 } 565 }
561 566
562 void IndexedDBContextImpl::ResetCaches() {
563 origin_set_.reset();
564 origin_size_map_.clear();
565 }
566
567 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { 567 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const {
568 DCHECK(task_runner_.get());
568 return task_runner_.get(); 569 return task_runner_.get();
569 } 570 }
570 571
571 } // namespace content 572 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_context_impl.h ('k') | content/browser/indexed_db/indexed_db_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698