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

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

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 base::FileEnumerator file_enumerator( 280 base::FileEnumerator file_enumerator(
281 GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), true, 281 GetBlobPath(storage::GetIdentifierFromOrigin(origin_url)), true,
282 base::FileEnumerator::FILES); 282 base::FileEnumerator::FILES);
283 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty(); 283 for (base::FilePath file_path = file_enumerator.Next(); !file_path.empty();
284 file_path = file_enumerator.Next()) { 284 file_path = file_enumerator.Next()) {
285 count++; 285 count++;
286 } 286 }
287 return count; 287 return count;
288 } 288 }
289 289
290 int64 IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) { 290 int64_t IndexedDBContextImpl::GetOriginDiskUsage(const GURL& origin_url) {
291 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 291 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
292 if (data_path_.empty() || !IsInOriginSet(origin_url)) 292 if (data_path_.empty() || !IsInOriginSet(origin_url))
293 return 0; 293 return 0;
294 EnsureDiskUsageCacheInitialized(origin_url); 294 EnsureDiskUsageCacheInitialized(origin_url);
295 return origin_size_map_[origin_url]; 295 return origin_size_map_[origin_url];
296 } 296 }
297 297
298 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) { 298 base::Time IndexedDBContextImpl::GetOriginLastModified(const GURL& origin_url) {
299 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 299 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
300 if (data_path_.empty() || !IsInOriginSet(origin_url)) 300 if (data_path_.empty() || !IsInOriginSet(origin_url))
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 QueryAvailableQuota(origin_url); 457 QueryAvailableQuota(origin_url);
458 } 458 }
459 459
460 void IndexedDBContextImpl::DatabaseDeleted(const GURL& origin_url) { 460 void IndexedDBContextImpl::DatabaseDeleted(const GURL& origin_url) {
461 AddToOriginSet(origin_url); 461 AddToOriginSet(origin_url);
462 QueryDiskAndUpdateQuotaUsage(origin_url); 462 QueryDiskAndUpdateQuotaUsage(origin_url);
463 QueryAvailableQuota(origin_url); 463 QueryAvailableQuota(origin_url);
464 } 464 }
465 465
466 bool IndexedDBContextImpl::WouldBeOverQuota(const GURL& origin_url, 466 bool IndexedDBContextImpl::WouldBeOverQuota(const GURL& origin_url,
467 int64 additional_bytes) { 467 int64_t additional_bytes) {
468 if (space_available_map_.find(origin_url) == space_available_map_.end()) { 468 if (space_available_map_.find(origin_url) == space_available_map_.end()) {
469 // We haven't heard back from the QuotaManager yet, just let it through. 469 // We haven't heard back from the QuotaManager yet, just let it through.
470 return false; 470 return false;
471 } 471 }
472 bool over_quota = additional_bytes > space_available_map_[origin_url]; 472 bool over_quota = additional_bytes > space_available_map_[origin_url];
473 return over_quota; 473 return over_quota;
474 } 474 }
475 475
476 bool IndexedDBContextImpl::IsOverQuota(const GURL& origin_url) { 476 bool IndexedDBContextImpl::IsOverQuota(const GURL& origin_url) {
477 const int kOneAdditionalByte = 1; 477 const int kOneAdditionalByte = 1;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 .AddExtension(kBlobExtension); 516 .AddExtension(kBlobExtension);
517 } 517 }
518 518
519 base::FilePath IndexedDBContextImpl::GetLevelDBPath( 519 base::FilePath IndexedDBContextImpl::GetLevelDBPath(
520 const std::string& origin_id) const { 520 const std::string& origin_id) const {
521 DCHECK(!data_path_.empty()); 521 DCHECK(!data_path_.empty());
522 return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension) 522 return data_path_.AppendASCII(origin_id).AddExtension(kIndexedDBExtension)
523 .AddExtension(kLevelDBExtension); 523 .AddExtension(kLevelDBExtension);
524 } 524 }
525 525
526 int64 IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const { 526 int64_t IndexedDBContextImpl::ReadUsageFromDisk(const GURL& origin_url) const {
527 if (data_path_.empty()) 527 if (data_path_.empty())
528 return 0; 528 return 0;
529 int64 total_size = 0; 529 int64_t total_size = 0;
530 for (const base::FilePath& path : GetStoragePaths(origin_url)) 530 for (const base::FilePath& path : GetStoragePaths(origin_url))
531 total_size += base::ComputeDirectorySize(path); 531 total_size += base::ComputeDirectorySize(path);
532 return total_size; 532 return total_size;
533 } 533 }
534 534
535 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized( 535 void IndexedDBContextImpl::EnsureDiskUsageCacheInitialized(
536 const GURL& origin_url) { 536 const GURL& origin_url) {
537 if (origin_size_map_.find(origin_url) == origin_size_map_.end()) 537 if (origin_size_map_.find(origin_url) == origin_size_map_.end())
538 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url); 538 origin_size_map_[origin_url] = ReadUsageFromDisk(origin_url);
539 } 539 }
540 540
541 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage( 541 void IndexedDBContextImpl::QueryDiskAndUpdateQuotaUsage(
542 const GURL& origin_url) { 542 const GURL& origin_url) {
543 int64 former_disk_usage = origin_size_map_[origin_url]; 543 int64_t former_disk_usage = origin_size_map_[origin_url];
544 int64 current_disk_usage = ReadUsageFromDisk(origin_url); 544 int64_t current_disk_usage = ReadUsageFromDisk(origin_url);
545 int64 difference = current_disk_usage - former_disk_usage; 545 int64_t difference = current_disk_usage - former_disk_usage;
546 if (difference) { 546 if (difference) {
547 origin_size_map_[origin_url] = current_disk_usage; 547 origin_size_map_[origin_url] = current_disk_usage;
548 // quota_manager_proxy() is NULL in unit tests. 548 // quota_manager_proxy() is NULL in unit tests.
549 if (quota_manager_proxy()) { 549 if (quota_manager_proxy()) {
550 quota_manager_proxy()->NotifyStorageModified( 550 quota_manager_proxy()->NotifyStorageModified(
551 storage::QuotaClient::kIndexedDatabase, 551 storage::QuotaClient::kIndexedDatabase,
552 origin_url, 552 origin_url,
553 storage::kStorageTypeTemporary, 553 storage::kStorageTypeTemporary,
554 difference); 554 difference);
555 } 555 }
556 } 556 }
557 } 557 }
558 558
559 void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url, 559 void IndexedDBContextImpl::GotUsageAndQuota(const GURL& origin_url,
560 storage::QuotaStatusCode status, 560 storage::QuotaStatusCode status,
561 int64 usage, 561 int64_t usage,
562 int64 quota) { 562 int64_t quota) {
563 DCHECK_CURRENTLY_ON(BrowserThread::IO); 563 DCHECK_CURRENTLY_ON(BrowserThread::IO);
564 DCHECK(status == storage::kQuotaStatusOk || 564 DCHECK(status == storage::kQuotaStatusOk ||
565 status == storage::kQuotaErrorAbort) 565 status == storage::kQuotaErrorAbort)
566 << "status was " << status; 566 << "status was " << status;
567 if (status == storage::kQuotaErrorAbort) { 567 if (status == storage::kQuotaErrorAbort) {
568 // We seem to no longer care to wait around for the answer. 568 // We seem to no longer care to wait around for the answer.
569 return; 569 return;
570 } 570 }
571 TaskRunner()->PostTask(FROM_HERE, 571 TaskRunner()->PostTask(FROM_HERE,
572 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota, 572 base::Bind(&IndexedDBContextImpl::GotUpdatedQuota,
573 this, 573 this,
574 origin_url, 574 origin_url,
575 usage, 575 usage,
576 quota)); 576 quota));
577 } 577 }
578 578
579 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url, 579 void IndexedDBContextImpl::GotUpdatedQuota(const GURL& origin_url,
580 int64 usage, 580 int64_t usage,
581 int64 quota) { 581 int64_t quota) {
582 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 582 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
583 space_available_map_[origin_url] = quota - usage; 583 space_available_map_[origin_url] = quota - usage;
584 } 584 }
585 585
586 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) { 586 void IndexedDBContextImpl::QueryAvailableQuota(const GURL& origin_url) {
587 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 587 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
588 DCHECK(TaskRunner()->RunsTasksOnCurrentThread()); 588 DCHECK(TaskRunner()->RunsTasksOnCurrentThread());
589 if (quota_manager_proxy()) { 589 if (quota_manager_proxy()) {
590 BrowserThread::PostTask( 590 BrowserThread::PostTask(
591 BrowserThread::IO, 591 BrowserThread::IO,
(...skipping 29 matching lines...) Expand all
621 origin_set_.reset(); 621 origin_set_.reset();
622 origin_size_map_.clear(); 622 origin_size_map_.clear();
623 space_available_map_.clear(); 623 space_available_map_.clear();
624 } 624 }
625 625
626 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const { 626 base::SequencedTaskRunner* IndexedDBContextImpl::TaskRunner() const {
627 return task_runner_.get(); 627 return task_runner_.get();
628 } 628 }
629 629
630 } // namespace content 630 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_context_impl.h ('k') | content/browser/indexed_db/indexed_db_cursor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698