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

Side by Side Diff: webkit/quota/usage_tracker.cc

Issue 7056025: More WebSQLDatabase and QuotaManager integration. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 "webkit/quota/usage_tracker.h" 5 #include "webkit/quota/usage_tracker.h"
6 6
7 #include <deque> 7 #include <deque>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 UsageTracker* tracker() const { return tracker_; } 67 UsageTracker* tracker() const { return tracker_; }
68 ClientUsageTracker* client_tracker() const { return client_tracker_; } 68 ClientUsageTracker* client_tracker() const { return client_tracker_; }
69 const std::map<GURL, int64>& origin_usage_map() const { 69 const std::map<GURL, int64>& origin_usage_map() const {
70 return origin_usage_map_; 70 return origin_usage_map_;
71 } 71 }
72 72
73 private: 73 private:
74 void DidGetUsage(int64 usage) { 74 void DidGetUsage(int64 usage) {
75 // Defend against confusing inputs from QuotaClients.
76 DCHECK_GE(usage, 0);
77 if (usage < 0)
78 usage = 0;
79
75 // This code assumes DidGetUsage callbacks are called in the same 80 // This code assumes DidGetUsage callbacks are called in the same
76 // order as we dispatched GetOriginUsage calls. 81 // order as we dispatched GetOriginUsage calls.
77 DCHECK(original_message_loop()->BelongsToCurrentThread()); 82 DCHECK(original_message_loop()->BelongsToCurrentThread());
78 DCHECK(!pending_origins_.empty()); 83 DCHECK(!pending_origins_.empty());
79 origin_usage_map_.insert(std::make_pair( 84 origin_usage_map_.insert(std::make_pair(
80 pending_origins_.front(), usage)); 85 pending_origins_.front(), usage));
81 pending_origins_.pop_front(); 86 pending_origins_.pop_front();
82 if (pending_origins_.empty()) { 87 if (pending_origins_.empty()) {
83 // We're done. 88 // We're done.
84 CallCompleted(); 89 CallCompleted();
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 origins_to_process->insert(*iter); 331 origins_to_process->insert(*iter);
327 } 332 }
328 } 333 }
329 334
330 void ClientUsageTracker::UpdateUsageCache( 335 void ClientUsageTracker::UpdateUsageCache(
331 const GURL& origin, int64 delta) { 336 const GURL& origin, int64 delta) {
332 std::string host = net::GetHostOrSpecFromURL(origin); 337 std::string host = net::GetHostOrSpecFromURL(origin);
333 if (cached_origins_.find(origin) != cached_origins_.end()) { 338 if (cached_origins_.find(origin) != cached_origins_.end()) {
334 host_usage_map_[host] += delta; 339 host_usage_map_[host] += delta;
335 global_usage_ += delta; 340 global_usage_ += delta;
341 DCHECK_GE(host_usage_map_[host], 0);
342 DCHECK_GE(global_usage_, 0);
336 return; 343 return;
337 } 344 }
338 if (global_usage_retrieved_ || 345 if (global_usage_retrieved_ ||
339 host_usage_map_.find(host) != host_usage_map_.end()) { 346 host_usage_map_.find(host) != host_usage_map_.end()) {
340 // This might be for a new origin. 347 // This might be for a new origin.
341 cached_origins_.insert(origin); 348 cached_origins_.insert(origin);
342 host_usage_map_[host] = delta; 349 host_usage_map_[host] = delta;
343 global_usage_ += delta; 350 global_usage_ += delta;
351 DCHECK_GE(host_usage_map_[host], 0);
352 DCHECK_GE(global_usage_, 0);
344 return; 353 return;
345 } 354 }
346 // See if the origin has been processed in outstanding gather tasks 355 // See if the origin has been processed in outstanding gather tasks
347 // and add up the delta if it has. 356 // and add up the delta if it has.
348 if (global_usage_task_ && global_usage_task_->IsOriginDone(origin)) { 357 if (global_usage_task_ && global_usage_task_->IsOriginDone(origin)) {
349 host_usage_map_[host] += delta; 358 host_usage_map_[host] += delta;
350 global_usage_ += delta; 359 global_usage_ += delta;
360 DCHECK_GE(host_usage_map_[host], 0);
361 DCHECK_GE(global_usage_, 0);
351 return; 362 return;
352 } 363 }
353 if (host_usage_tasks_.find(host) != host_usage_tasks_.end() && 364 if (host_usage_tasks_.find(host) != host_usage_tasks_.end() &&
354 host_usage_tasks_[host]->IsOriginDone(origin)) { 365 host_usage_tasks_[host]->IsOriginDone(origin)) {
355 host_usage_map_[host] += delta; 366 host_usage_map_[host] += delta;
367 DCHECK_GE(host_usage_map_[host], 0);
356 } 368 }
357 // Otherwise we have not cached usage info for the origin yet. 369 // Otherwise we have not cached usage info for the origin yet.
358 // Succeeding GetUsage tasks would eventually catch the change. 370 // Succeeding GetUsage tasks would eventually catch the change.
359 } 371 }
360 372
361 void ClientUsageTracker::DidGetGlobalUsage( 373 void ClientUsageTracker::DidGetGlobalUsage(
362 const std::map<GURL, int64>& origin_usage_map) { 374 const std::map<GURL, int64>& origin_usage_map) {
363 DCHECK(global_usage_task_ != NULL); 375 DCHECK(global_usage_task_ != NULL);
364 global_usage_task_ = NULL; 376 global_usage_task_ = NULL;
365 // TODO(kinuko): Record when it has retrieved the global usage. 377 // TODO(kinuko): Record when it has retrieved the global usage.
366 global_usage_retrieved_ = true; 378 global_usage_retrieved_ = true;
367 for (std::map<GURL, int64>::const_iterator iter = origin_usage_map.begin(); 379 for (std::map<GURL, int64>::const_iterator iter = origin_usage_map.begin();
368 iter != origin_usage_map.end(); 380 iter != origin_usage_map.end();
369 ++iter) { 381 ++iter) {
370 if (cached_origins_.insert(iter->first).second) { 382 if (cached_origins_.insert(iter->first).second) {
371 global_usage_ += iter->second; 383 global_usage_ += iter->second;
372 std::string host = net::GetHostOrSpecFromURL(iter->first); 384 std::string host = net::GetHostOrSpecFromURL(iter->first);
373 host_usage_map_[host] += iter->second; 385 host_usage_map_[host] += iter->second;
386 DCHECK_GE(host_usage_map_[host], 0);
387 DCHECK_GE(global_usage_, 0);
374 } 388 }
375 } 389 }
376 390
377 // Dispatches the global usage callback. 391 // Dispatches the global usage callback.
378 DCHECK(global_usage_callback_.HasCallbacks()); 392 DCHECK(global_usage_callback_.HasCallbacks());
379 global_usage_callback_.Run(global_usage_); 393 global_usage_callback_.Run(global_usage_);
380 394
381 // Dispatches host usage callbacks. 395 // Dispatches host usage callbacks.
382 for (HostUsageCallbackMap::iterator iter = host_usage_callbacks_.Begin(); 396 for (HostUsageCallbackMap::iterator iter = host_usage_callbacks_.Begin();
383 iter != host_usage_callbacks_.End(); 397 iter != host_usage_callbacks_.End();
(...skipping 12 matching lines...) Expand all
396 const std::string& host, 410 const std::string& host,
397 const std::map<GURL, int64>& origin_usage_map) { 411 const std::map<GURL, int64>& origin_usage_map) {
398 DCHECK(host_usage_tasks_.find(host) != host_usage_tasks_.end()); 412 DCHECK(host_usage_tasks_.find(host) != host_usage_tasks_.end());
399 host_usage_tasks_.erase(host); 413 host_usage_tasks_.erase(host);
400 for (std::map<GURL, int64>::const_iterator iter = origin_usage_map.begin(); 414 for (std::map<GURL, int64>::const_iterator iter = origin_usage_map.begin();
401 iter != origin_usage_map.end(); 415 iter != origin_usage_map.end();
402 ++iter) { 416 ++iter) {
403 if (cached_origins_.insert(iter->first).second) { 417 if (cached_origins_.insert(iter->first).second) {
404 global_usage_ += iter->second; 418 global_usage_ += iter->second;
405 host_usage_map_[host] += iter->second; 419 host_usage_map_[host] += iter->second;
420 DCHECK_GE(host_usage_map_[host], 0);
421 DCHECK_GE(global_usage_, 0);
406 } 422 }
407 } 423 }
408 424
409 // Dispatches the host usage callback. 425 // Dispatches the host usage callback.
410 host_usage_callbacks_.Run(host, host, host_usage_map_[host]); 426 host_usage_callbacks_.Run(host, host, host_usage_map_[host]);
411 } 427 }
412 428
413 } // namespace quota 429 } // namespace quota
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698