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

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

Issue 17518004: Move IndexedDB from WEBKIT_DEPRECATED to dedicated thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing files Created 7 years, 6 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 | Annotate | Revision Log
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_quota_client.h" 5 #include "content/browser/indexed_db/indexed_db_quota_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "content/browser/indexed_db/indexed_db_context_impl.h" 10 #include "content/browser/indexed_db/indexed_db_context_impl.h"
12 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
13 #include "net/base/net_util.h" 12 #include "net/base/net_util.h"
14 #include "webkit/browser/database/database_util.h" 13 #include "webkit/browser/database/database_util.h"
15 14
16 using quota::QuotaClient; 15 using quota::QuotaClient;
17 using webkit_database::DatabaseUtil; 16 using webkit_database::DatabaseUtil;
18 17
19 namespace content { 18 namespace content {
20 namespace { 19 namespace {
21 20
22 quota::QuotaStatusCode DeleteOriginDataOnWebKitThread( 21 quota::QuotaStatusCode DeleteOriginDataOnIndexedDBThread(
23 IndexedDBContextImpl* context, 22 IndexedDBContextImpl* context,
24 const GURL& origin) { 23 const GURL& origin) {
25 context->DeleteForOrigin(origin); 24 context->DeleteForOrigin(origin);
26 return quota::kQuotaStatusOk; 25 return quota::kQuotaStatusOk;
27 } 26 }
28 27
29 int64 GetOriginUsageOnWebKitThread(IndexedDBContextImpl* context, 28 int64 GetOriginUsageOnIndexedDBThread(IndexedDBContextImpl* context,
30 const GURL& origin) { 29 const GURL& origin) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 30 DCHECK(context->OnIndexedDBThread());
32 return context->GetOriginDiskUsage(origin); 31 return context->GetOriginDiskUsage(origin);
33 } 32 }
34 33
35 void GetAllOriginsOnWebKitThread(IndexedDBContextImpl* context, 34 void GetAllOriginsOnIndexedDBThread(IndexedDBContextImpl* context,
36 std::set<GURL>* origins_to_return) { 35 std::set<GURL>* origins_to_return) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 36 DCHECK(context->OnIndexedDBThread());
38 std::vector<GURL> all_origins = context->GetAllOrigins(); 37 std::vector<GURL> all_origins = context->GetAllOrigins();
39 origins_to_return->insert(all_origins.begin(), all_origins.end()); 38 origins_to_return->insert(all_origins.begin(), all_origins.end());
40 } 39 }
41 40
42 void DidGetOrigins(const IndexedDBQuotaClient::GetOriginsCallback& callback, 41 void DidGetOrigins(const IndexedDBQuotaClient::GetOriginsCallback& callback,
43 const std::set<GURL>* origins) { 42 const std::set<GURL>* origins) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
45 callback.Run(*origins); 44 callback.Run(*origins);
46 } 45 }
47 46
48 void GetOriginsForHostOnWebKitThread(IndexedDBContextImpl* context, 47 void GetOriginsForHostOnIndexedDBThread(IndexedDBContextImpl* context,
49 const std::string& host, 48 const std::string& host,
50 std::set<GURL>* origins_to_return) { 49 std::set<GURL>* origins_to_return) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT_DEPRECATED)); 50 DCHECK(context->OnIndexedDBThread());
52 std::vector<GURL> all_origins = context->GetAllOrigins(); 51 std::vector<GURL> all_origins = context->GetAllOrigins();
53 for (std::vector<GURL>::const_iterator iter = all_origins.begin(); 52 for (std::vector<GURL>::const_iterator iter = all_origins.begin();
54 iter != all_origins.end(); 53 iter != all_origins.end();
55 ++iter) { 54 ++iter) {
56 if (host == net::GetHostOrSpecFromURL(*iter)) 55 if (host == net::GetHostOrSpecFromURL(*iter))
57 origins_to_return->insert(*iter); 56 origins_to_return->insert(*iter);
58 } 57 }
59 } 58 }
60 59
61 } // namespace 60 } // namespace
62 61
63 // IndexedDBQuotaClient -------------------------------------------------------- 62 // IndexedDBQuotaClient --------------------------------------------------------
64 63
65 IndexedDBQuotaClient::IndexedDBQuotaClient( 64 IndexedDBQuotaClient::IndexedDBQuotaClient(
66 base::MessageLoopProxy* webkit_thread_message_loop,
67 IndexedDBContextImpl* indexed_db_context) 65 IndexedDBContextImpl* indexed_db_context)
68 : webkit_thread_message_loop_(webkit_thread_message_loop), 66 : indexed_db_context_(indexed_db_context) {}
69 indexed_db_context_(indexed_db_context) {}
70 67
71 IndexedDBQuotaClient::~IndexedDBQuotaClient() {} 68 IndexedDBQuotaClient::~IndexedDBQuotaClient() {}
72 69
73 QuotaClient::ID IndexedDBQuotaClient::id() const { return kIndexedDatabase; } 70 QuotaClient::ID IndexedDBQuotaClient::id() const { return kIndexedDatabase; }
74 71
75 void IndexedDBQuotaClient::OnQuotaManagerDestroyed() { delete this; } 72 void IndexedDBQuotaClient::OnQuotaManagerDestroyed() { delete this; }
76 73
77 void IndexedDBQuotaClient::GetOriginUsage(const GURL& origin_url, 74 void IndexedDBQuotaClient::GetOriginUsage(const GURL& origin_url,
78 quota::StorageType type, 75 quota::StorageType type,
79 const GetUsageCallback& callback) { 76 const GetUsageCallback& callback) {
80 DCHECK(!callback.is_null()); 77 DCHECK(!callback.is_null());
81 DCHECK(indexed_db_context_.get()); 78 DCHECK(indexed_db_context_.get());
82 79
83 // IndexedDB is in the temp namespace for now. 80 // IndexedDB is in the temp namespace for now.
84 if (type != quota::kStorageTypeTemporary) { 81 if (type != quota::kStorageTypeTemporary) {
85 callback.Run(0); 82 callback.Run(0);
86 return; 83 return;
87 } 84 }
88 85
89 base::PostTaskAndReplyWithResult( 86 base::PostTaskAndReplyWithResult(
90 webkit_thread_message_loop_.get(), 87 indexed_db_context_->TaskRunner(),
91 FROM_HERE, 88 FROM_HERE,
92 base::Bind( 89 base::Bind(
93 &GetOriginUsageOnWebKitThread, indexed_db_context_, origin_url), 90 &GetOriginUsageOnIndexedDBThread, indexed_db_context_, origin_url),
94 callback); 91 callback);
95 } 92 }
96 93
97 void IndexedDBQuotaClient::GetOriginsForType( 94 void IndexedDBQuotaClient::GetOriginsForType(
98 quota::StorageType type, 95 quota::StorageType type,
99 const GetOriginsCallback& callback) { 96 const GetOriginsCallback& callback) {
100 DCHECK(!callback.is_null()); 97 DCHECK(!callback.is_null());
101 DCHECK(indexed_db_context_.get()); 98 DCHECK(indexed_db_context_.get());
102 99
103 // All databases are in the temp namespace for now. 100 // All databases are in the temp namespace for now.
104 if (type != quota::kStorageTypeTemporary) { 101 if (type != quota::kStorageTypeTemporary) {
105 callback.Run(std::set<GURL>()); 102 callback.Run(std::set<GURL>());
106 return; 103 return;
107 } 104 }
108 105
109 std::set<GURL>* origins_to_return = new std::set<GURL>(); 106 std::set<GURL>* origins_to_return = new std::set<GURL>();
110 webkit_thread_message_loop_->PostTaskAndReply( 107 indexed_db_context_->TaskRunner()->PostTaskAndReply(
111 FROM_HERE, 108 FROM_HERE,
112 base::Bind(&GetAllOriginsOnWebKitThread, 109 base::Bind(&GetAllOriginsOnIndexedDBThread,
113 indexed_db_context_, 110 indexed_db_context_,
114 base::Unretained(origins_to_return)), 111 base::Unretained(origins_to_return)),
115 base::Bind(&DidGetOrigins, callback, base::Owned(origins_to_return))); 112 base::Bind(&DidGetOrigins, callback, base::Owned(origins_to_return)));
116 } 113 }
117 114
118 void IndexedDBQuotaClient::GetOriginsForHost( 115 void IndexedDBQuotaClient::GetOriginsForHost(
119 quota::StorageType type, 116 quota::StorageType type,
120 const std::string& host, 117 const std::string& host,
121 const GetOriginsCallback& callback) { 118 const GetOriginsCallback& callback) {
122 DCHECK(!callback.is_null()); 119 DCHECK(!callback.is_null());
123 DCHECK(indexed_db_context_.get()); 120 DCHECK(indexed_db_context_.get());
124 121
125 // All databases are in the temp namespace for now. 122 // All databases are in the temp namespace for now.
126 if (type != quota::kStorageTypeTemporary) { 123 if (type != quota::kStorageTypeTemporary) {
127 callback.Run(std::set<GURL>()); 124 callback.Run(std::set<GURL>());
128 return; 125 return;
129 } 126 }
130 127
131 std::set<GURL>* origins_to_return = new std::set<GURL>(); 128 std::set<GURL>* origins_to_return = new std::set<GURL>();
132 webkit_thread_message_loop_->PostTaskAndReply( 129 indexed_db_context_->TaskRunner()->PostTaskAndReply(
133 FROM_HERE, 130 FROM_HERE,
134 base::Bind(&GetOriginsForHostOnWebKitThread, 131 base::Bind(&GetOriginsForHostOnIndexedDBThread,
135 indexed_db_context_, 132 indexed_db_context_,
136 host, 133 host,
137 base::Unretained(origins_to_return)), 134 base::Unretained(origins_to_return)),
138 base::Bind(&DidGetOrigins, callback, base::Owned(origins_to_return))); 135 base::Bind(&DidGetOrigins, callback, base::Owned(origins_to_return)));
139 } 136 }
140 137
141 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin, 138 void IndexedDBQuotaClient::DeleteOriginData(const GURL& origin,
142 quota::StorageType type, 139 quota::StorageType type,
143 const DeletionCallback& callback) { 140 const DeletionCallback& callback) {
144 if (type != quota::kStorageTypeTemporary) { 141 if (type != quota::kStorageTypeTemporary) {
145 callback.Run(quota::kQuotaErrorNotSupported); 142 callback.Run(quota::kQuotaErrorNotSupported);
146 return; 143 return;
147 } 144 }
148 145
149 base::PostTaskAndReplyWithResult( 146 base::PostTaskAndReplyWithResult(
150 webkit_thread_message_loop_.get(), 147 indexed_db_context_->TaskRunner(),
151 FROM_HERE, 148 FROM_HERE,
152 base::Bind(&DeleteOriginDataOnWebKitThread, indexed_db_context_, origin), 149 base::Bind(
150 &DeleteOriginDataOnIndexedDBThread, indexed_db_context_, origin),
153 callback); 151 callback);
154 } 152 }
155 153
156 } // namespace content 154 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698