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

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

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

Powered by Google App Engine
This is Rietveld 408576698