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

Side by Side Diff: content/browser/in_process_webkit/indexed_db_context.cc

Issue 8070001: Use base::Callback in Quota related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/in_process_webkit/indexed_db_context.h" 5 #include "content/browser/in_process_webkit/indexed_db_context.h"
6 6
7 #include "base/bind.h"
7 #include "base/command_line.h" 8 #include "base/command_line.h"
8 #include "base/file_util.h" 9 #include "base/file_util.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
11 #include "base/string_util.h" 12 #include "base/string_util.h"
12 #include "base/task.h" 13 #include "base/task.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "content/browser/browser_thread.h" 15 #include "content/browser/browser_thread.h"
15 #include "content/browser/in_process_webkit/indexed_db_quota_client.h" 16 #include "content/browser/in_process_webkit/indexed_db_quota_client.h"
16 #include "content/browser/in_process_webkit/webkit_context.h" 17 #include "content/browser/in_process_webkit/webkit_context.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 81 }
81 82
82 } // namespace 83 } // namespace
83 84
84 const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] = 85 const FilePath::CharType IndexedDBContext::kIndexedDBDirectory[] =
85 FILE_PATH_LITERAL("IndexedDB"); 86 FILE_PATH_LITERAL("IndexedDB");
86 87
87 const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] = 88 const FilePath::CharType IndexedDBContext::kIndexedDBExtension[] =
88 FILE_PATH_LITERAL(".leveldb"); 89 FILE_PATH_LITERAL(".leveldb");
89 90
90 class IndexedDBContext::IndexedDBGetUsageAndQuotaCallback :
91 public quota::QuotaManager::GetUsageAndQuotaCallback {
92 public:
93 IndexedDBGetUsageAndQuotaCallback(IndexedDBContext* context,
94 const GURL& origin_url)
95 : context_(context),
96 origin_url_(origin_url) {
97 }
98
99 void Run(quota::QuotaStatusCode status, int64 usage, int64 quota) {
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
101 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort)
102 << "status was " << status;
103 if (status == quota::kQuotaErrorAbort) {
104 // We seem to no longer care to wait around for the answer.
105 return;
106 }
107 BrowserThread::PostTask(BrowserThread::WEBKIT, FROM_HERE,
108 NewRunnableMethod(context_.get(),
109 &IndexedDBContext::GotUpdatedQuota,
110 origin_url_,
111 usage,
112 quota));
113 }
114
115 virtual void RunWithParams(
116 const Tuple3<quota::QuotaStatusCode, int64, int64>& params) {
117 Run(params.a, params.b, params.c);
118 }
119
120 private:
121 scoped_refptr<IndexedDBContext> context_;
122 const GURL origin_url_;
123 };
124
125 IndexedDBContext::IndexedDBContext( 91 IndexedDBContext::IndexedDBContext(
126 WebKitContext* webkit_context, 92 WebKitContext* webkit_context,
127 quota::SpecialStoragePolicy* special_storage_policy, 93 quota::SpecialStoragePolicy* special_storage_policy,
128 quota::QuotaManagerProxy* quota_manager_proxy, 94 quota::QuotaManagerProxy* quota_manager_proxy,
129 base::MessageLoopProxy* webkit_thread_loop) 95 base::MessageLoopProxy* webkit_thread_loop)
130 : clear_local_state_on_exit_(false), 96 : clear_local_state_on_exit_(false),
131 special_storage_policy_(special_storage_policy), 97 special_storage_policy_(special_storage_policy),
132 quota_manager_proxy_(quota_manager_proxy) { 98 quota_manager_proxy_(quota_manager_proxy) {
133 if (!webkit_context->is_incognito()) 99 if (!webkit_context->is_incognito())
134 data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory); 100 data_path_ = webkit_context->data_path().Append(kIndexedDBDirectory);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // quota_manager_proxy() is NULL in unit tests. 275 // quota_manager_proxy() is NULL in unit tests.
310 if (quota_manager_proxy()) 276 if (quota_manager_proxy())
311 quota_manager_proxy()->NotifyStorageModified( 277 quota_manager_proxy()->NotifyStorageModified(
312 quota::QuotaClient::kIndexedDatabase, 278 quota::QuotaClient::kIndexedDatabase,
313 origin_url, 279 origin_url,
314 quota::kStorageTypeTemporary, 280 quota::kStorageTypeTemporary,
315 difference); 281 difference);
316 } 282 }
317 } 283 }
318 284
285 void IndexedDBContext::GotUsageAndQuota(const GURL& origin_url,
286 quota::QuotaStatusCode status,
287 int64 usage, int64 quota) {
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
289 DCHECK(status == quota::kQuotaStatusOk || status == quota::kQuotaErrorAbort)
290 << "status was " << status;
291 if (status == quota::kQuotaErrorAbort) {
292 // We seem to no longer care to wait around for the answer.
293 return;
294 }
295 BrowserThread::PostTask(
296 BrowserThread::WEBKIT, FROM_HERE,
297 NewRunnableMethod(this,
298 &IndexedDBContext::GotUpdatedQuota,
299 origin_url,
300 usage,
301 quota));
302 }
303
319 void IndexedDBContext::GotUpdatedQuota(const GURL& origin_url, int64 usage, 304 void IndexedDBContext::GotUpdatedQuota(const GURL& origin_url, int64 usage,
320 int64 quota) { 305 int64 quota) {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
322 space_available_map_[origin_url] = quota - usage; 307 space_available_map_[origin_url] = quota - usage;
323 } 308 }
324 309
325 void IndexedDBContext::QueryAvailableQuota(const GURL& origin_url) { 310 void IndexedDBContext::QueryAvailableQuota(const GURL& origin_url) {
326 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 311 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); 312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT));
328 if (quota_manager_proxy()) 313 if (quota_manager_proxy())
329 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 314 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
330 NewRunnableMethod(this, &IndexedDBContext::QueryAvailableQuota, 315 NewRunnableMethod(this, &IndexedDBContext::QueryAvailableQuota,
331 origin_url)); 316 origin_url));
332 return; 317 return;
333 } 318 }
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
335 if (!quota_manager_proxy()->quota_manager()) 320 if (!quota_manager_proxy()->quota_manager())
336 return; 321 return;
337 IndexedDBGetUsageAndQuotaCallback* callback =
338 new IndexedDBGetUsageAndQuotaCallback(this, origin_url);
339 quota_manager_proxy()->quota_manager()->GetUsageAndQuota( 322 quota_manager_proxy()->quota_manager()->GetUsageAndQuota(
340 origin_url, 323 origin_url,
341 quota::kStorageTypeTemporary, 324 quota::kStorageTypeTemporary,
342 callback); 325 base::Bind(&IndexedDBContext::GotUsageAndQuota,
326 this, origin_url));
343 } 327 }
344 328
345 std::set<GURL>* IndexedDBContext::GetOriginSet() { 329 std::set<GURL>* IndexedDBContext::GetOriginSet() {
346 if (!origin_set_.get()) { 330 if (!origin_set_.get()) {
347 origin_set_.reset(new std::set<GURL>); 331 origin_set_.reset(new std::set<GURL>);
348 std::vector<GURL> origins; 332 std::vector<GURL> origins;
349 GetAllOriginsAndPaths(data_path_, &origins, NULL); 333 GetAllOriginsAndPaths(data_path_, &origins, NULL);
350 for (std::vector<GURL>::const_iterator iter = origins.begin(); 334 for (std::vector<GURL>::const_iterator iter = origins.begin();
351 iter != origins.end(); ++iter) { 335 iter != origins.end(); ++iter) {
352 origin_set_->insert(*iter); 336 origin_set_->insert(*iter);
353 } 337 }
354 } 338 }
355 return origin_set_.get(); 339 return origin_set_.get();
356 } 340 }
357 341
358 void IndexedDBContext::ResetCaches() { 342 void IndexedDBContext::ResetCaches() {
359 origin_set_.reset(); 343 origin_set_.reset();
360 origin_size_map_.clear(); 344 origin_size_map_.clear();
361 space_available_map_.clear(); 345 space_available_map_.clear();
362 } 346 }
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_context.h ('k') | content/browser/in_process_webkit/indexed_db_quota_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698