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

Side by Side Diff: storage/browser/quota/quota_manager.cc

Issue 1394563002: Add trace to the caller of QuotaManager::GetAvailableSpace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « storage/browser/quota/quota_callbacks.h ('k') | storage/browser/quota/quota_manager_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "storage/browser/quota/quota_manager.h" 5 #include "storage/browser/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/profiler/scoped_tracker.h" 15 #include "base/profiler/scoped_tracker.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/sys_info.h" 19 #include "base/sys_info.h"
20 #include "base/task_runner_util.h" 20 #include "base/task_runner_util.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "base/trace_event/trace_event.h"
22 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
23 #include "storage/browser/quota/client_usage_tracker.h" 24 #include "storage/browser/quota/client_usage_tracker.h"
24 #include "storage/browser/quota/quota_manager_proxy.h" 25 #include "storage/browser/quota/quota_manager_proxy.h"
25 #include "storage/browser/quota/quota_temporary_storage_evictor.h" 26 #include "storage/browser/quota/quota_temporary_storage_evictor.h"
26 #include "storage/browser/quota/storage_monitor.h" 27 #include "storage/browser/quota/storage_monitor.h"
27 #include "storage/browser/quota/usage_tracker.h" 28 #include "storage/browser/quota/usage_tracker.h"
28 #include "storage/common/quota/quota_types.h" 29 #include "storage/common/quota/quota_types.h"
29 30
30 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 31 #define UMA_HISTOGRAM_MBYTES(name, sample) \
31 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 32 UMA_HISTOGRAM_CUSTOM_COUNTS( \
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 bool UpdateModifiedTimeOnDBThread(const GURL& origin, 183 bool UpdateModifiedTimeOnDBThread(const GURL& origin,
183 StorageType type, 184 StorageType type,
184 base::Time modified_time, 185 base::Time modified_time,
185 QuotaDatabase* database) { 186 QuotaDatabase* database) {
186 DCHECK(database); 187 DCHECK(database);
187 return database->SetOriginLastModifiedTime(origin, type, modified_time); 188 return database->SetOriginLastModifiedTime(origin, type, modified_time);
188 } 189 }
189 190
190 int64 CallSystemGetAmountOfFreeDiskSpace(const base::FilePath& profile_path) { 191 int64 CallSystemGetAmountOfFreeDiskSpace(const base::FilePath& profile_path) {
192 // crbug.com/349708
193 TRACE_EVENT0("io", "CallSystemGetAmountOfFreeDiskSpace");
194
191 // Ensure the profile path exists. 195 // Ensure the profile path exists.
192 if (!base::CreateDirectory(profile_path)) { 196 if (!base::CreateDirectory(profile_path)) {
193 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); 197 LOG(WARNING) << "Create directory failed for path" << profile_path.value();
194 return 0; 198 return 0;
195 } 199 }
196 return base::SysInfo::AmountOfFreeDiskSpace(profile_path); 200 return base::SysInfo::AmountOfFreeDiskSpace(profile_path);
197 } 201 }
198 202
199 int64 CalculateTemporaryGlobalQuota(int64 global_limited_usage, 203 int64 CalculateTemporaryGlobalQuota(int64 global_limited_usage,
200 int64 available_space) { 204 int64 available_space) {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 407 }
404 408
405 void DidGetQuota(QuotaStatusCode status, int64 quota) { 409 void DidGetQuota(QuotaStatusCode status, int64 quota) {
406 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) 410 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk)
407 status_ = status; 411 status_ = status;
408 usage_and_quota_.quota = quota; 412 usage_and_quota_.quota = quota;
409 CheckCompleted(); 413 CheckCompleted();
410 } 414 }
411 415
412 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) { 416 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) {
417 // crbug.com/349708
418 TRACE_EVENT0(
419 "io", "UsageAndQuotaCallbackDispatcher::DidGetAvailableSpace");
420
413 DCHECK_GE(space, 0); 421 DCHECK_GE(space, 0);
414 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) 422 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk)
415 status_ = status; 423 status_ = status;
416 usage_and_quota_.available_disk_space = space; 424 usage_and_quota_.available_disk_space = space;
417 CheckCompleted(); 425 CheckCompleted();
418 } 426 }
419 427
420 void Run() override { 428 void Run() override {
421 // We initialize waiting_callbacks to 1 so that we won't run 429 // We initialize waiting_callbacks to 1 so that we won't run
422 // the completion callback until here even some of the callbacks 430 // the completion callback until here even some of the callbacks
423 // are dispatched synchronously. 431 // are dispatched synchronously.
424 CheckCompleted(); 432 CheckCompleted();
425 } 433 }
426 434
427 void Aborted() override { 435 void Aborted() override {
428 callback_.Run(kQuotaErrorAbort, UsageAndQuota()); 436 callback_.Run(kQuotaErrorAbort, UsageAndQuota());
429 DeleteSoon(); 437 DeleteSoon();
430 } 438 }
431 439
432 void Completed() override { 440 void Completed() override {
441 // crbug.com/349708
442 TRACE_EVENT0("io", "UsageAndQuotaCallbackDispatcher::Completed");
443
433 DCHECK(!has_usage_ || usage_and_quota_.usage >= 0); 444 DCHECK(!has_usage_ || usage_and_quota_.usage >= 0);
434 DCHECK(!has_global_limited_usage_ || 445 DCHECK(!has_global_limited_usage_ ||
435 usage_and_quota_.global_limited_usage >= 0); 446 usage_and_quota_.global_limited_usage >= 0);
436 DCHECK(!has_quota_ || usage_and_quota_.quota >= 0); 447 DCHECK(!has_quota_ || usage_and_quota_.quota >= 0);
437 DCHECK(!has_available_disk_space_ || 448 DCHECK(!has_available_disk_space_ ||
438 usage_and_quota_.available_disk_space >= 0); 449 usage_and_quota_.available_disk_space >= 0);
439 450
440 callback_.Run(status_, usage_and_quota_); 451 callback_.Run(status_, usage_and_quota_);
441 DeleteSoon(); 452 DeleteSoon();
442 } 453 }
(...skipping 22 matching lines...) Expand all
465 GetUsageInfoTask( 476 GetUsageInfoTask(
466 QuotaManager* manager, 477 QuotaManager* manager,
467 const GetUsageInfoCallback& callback) 478 const GetUsageInfoCallback& callback)
468 : QuotaTask(manager), 479 : QuotaTask(manager),
469 callback_(callback), 480 callback_(callback),
470 weak_factory_(this) { 481 weak_factory_(this) {
471 } 482 }
472 483
473 protected: 484 protected:
474 void Run() override { 485 void Run() override {
486 // crbug.com/349708
487 TRACE_EVENT0("io", "QuotaManager::GetUsageInfoTask::Run");
488
475 remaining_trackers_ = 3; 489 remaining_trackers_ = 3;
476 // This will populate cached hosts and usage info. 490 // This will populate cached hosts and usage info.
477 manager()->GetUsageTracker(kStorageTypeTemporary)->GetGlobalUsage( 491 manager()->GetUsageTracker(kStorageTypeTemporary)->GetGlobalUsage(
478 base::Bind(&GetUsageInfoTask::DidGetGlobalUsage, 492 base::Bind(&GetUsageInfoTask::DidGetGlobalUsage,
479 weak_factory_.GetWeakPtr(), 493 weak_factory_.GetWeakPtr(),
480 kStorageTypeTemporary)); 494 kStorageTypeTemporary));
481 manager()->GetUsageTracker(kStorageTypePersistent)->GetGlobalUsage( 495 manager()->GetUsageTracker(kStorageTypePersistent)->GetGlobalUsage(
482 base::Bind(&GetUsageInfoTask::DidGetGlobalUsage, 496 base::Bind(&GetUsageInfoTask::DidGetGlobalUsage,
483 weak_factory_.GetWeakPtr(), 497 weak_factory_.GetWeakPtr(),
484 kStorageTypePersistent)); 498 kStorageTypePersistent));
485 manager()->GetUsageTracker(kStorageTypeSyncable)->GetGlobalUsage( 499 manager()->GetUsageTracker(kStorageTypeSyncable)->GetGlobalUsage(
486 base::Bind(&GetUsageInfoTask::DidGetGlobalUsage, 500 base::Bind(&GetUsageInfoTask::DidGetGlobalUsage,
487 weak_factory_.GetWeakPtr(), 501 weak_factory_.GetWeakPtr(),
488 kStorageTypeSyncable)); 502 kStorageTypeSyncable));
489 } 503 }
490 504
491 void Completed() override { 505 void Completed() override {
506 // crbug.com/349708
507 TRACE_EVENT0("io", "QuotaManager::GetUsageInfoTask::Completed");
508
492 callback_.Run(entries_); 509 callback_.Run(entries_);
493 DeleteSoon(); 510 DeleteSoon();
494 } 511 }
495 512
496 void Aborted() override { 513 void Aborted() override {
497 callback_.Run(UsageInfoEntries()); 514 callback_.Run(UsageInfoEntries());
498 DeleteSoon(); 515 DeleteSoon();
499 } 516 }
500 517
501 private: 518 private:
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } else { 576 } else {
560 ++skipped_clients_; 577 ++skipped_clients_;
561 if (--remaining_clients_ == 0) 578 if (--remaining_clients_ == 0)
562 CallCompleted(); 579 CallCompleted();
563 } 580 }
564 } 581 }
565 } 582 }
566 583
567 void Completed() override { 584 void Completed() override {
568 if (error_count_ == 0) { 585 if (error_count_ == 0) {
586 // crbug.com/349708
587 TRACE_EVENT0("io", "QuotaManager::OriginDataDeleter::Completed Ok");
588
569 // Only remove the entire origin if we didn't skip any client types. 589 // Only remove the entire origin if we didn't skip any client types.
570 if (skipped_clients_ == 0) 590 if (skipped_clients_ == 0)
571 manager()->DeleteOriginFromDatabase(origin_, type_); 591 manager()->DeleteOriginFromDatabase(origin_, type_);
572 callback_.Run(kQuotaStatusOk); 592 callback_.Run(kQuotaStatusOk);
573 } else { 593 } else {
594 // crbug.com/349708
595 TRACE_EVENT0("io", "QuotaManager::OriginDataDeleter::Completed Error");
596
574 callback_.Run(kQuotaErrorInvalidModification); 597 callback_.Run(kQuotaErrorInvalidModification);
575 } 598 }
576 DeleteSoon(); 599 DeleteSoon();
577 } 600 }
578 601
579 void Aborted() override { 602 void Aborted() override {
580 callback_.Run(kQuotaErrorAbort); 603 callback_.Run(kQuotaErrorAbort);
581 DeleteSoon(); 604 DeleteSoon();
582 } 605 }
583 606
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 iter != manager()->clients_.end(); ++iter) { 656 iter != manager()->clients_.end(); ++iter) {
634 (*iter)->GetOriginsForHost( 657 (*iter)->GetOriginsForHost(
635 type_, host_, 658 type_, host_,
636 base::Bind(&HostDataDeleter::DidGetOriginsForHost, 659 base::Bind(&HostDataDeleter::DidGetOriginsForHost,
637 weak_factory_.GetWeakPtr())); 660 weak_factory_.GetWeakPtr()));
638 } 661 }
639 } 662 }
640 663
641 void Completed() override { 664 void Completed() override {
642 if (error_count_ == 0) { 665 if (error_count_ == 0) {
666 // crbug.com/349708
667 TRACE_EVENT0("io", "QuotaManager::HostDataDeleter::Completed Ok");
668
643 callback_.Run(kQuotaStatusOk); 669 callback_.Run(kQuotaStatusOk);
644 } else { 670 } else {
671 // crbug.com/349708
672 TRACE_EVENT0("io", "QuotaManager::HostDataDeleter::Completed Error");
673
645 callback_.Run(kQuotaErrorInvalidModification); 674 callback_.Run(kQuotaErrorInvalidModification);
646 } 675 }
647 DeleteSoon(); 676 DeleteSoon();
648 } 677 }
649 678
650 void Aborted() override { 679 void Aborted() override {
651 callback_.Run(kQuotaErrorAbort); 680 callback_.Run(kQuotaErrorAbort);
652 DeleteSoon(); 681 DeleteSoon();
653 } 682 }
654 683
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 } 982 }
954 983
955 HostDataDeleter* deleter = 984 HostDataDeleter* deleter =
956 new HostDataDeleter(this, host, type, quota_client_mask, callback); 985 new HostDataDeleter(this, host, type, quota_client_mask, callback);
957 deleter->Start(); 986 deleter->Start();
958 } 987 }
959 988
960 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { 989 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) {
961 if (!available_space_callbacks_.Add(callback)) 990 if (!available_space_callbacks_.Add(callback))
962 return; 991 return;
992 // crbug.com/349708
993 TRACE_EVENT0("io", "QuotaManager::GetAvailableSpace");
963 994
964 PostTaskAndReplyWithResult(db_thread_.get(), 995 PostTaskAndReplyWithResult(db_thread_.get(),
965 FROM_HERE, 996 FROM_HERE,
966 base::Bind(get_disk_space_fn_, profile_path_), 997 base::Bind(get_disk_space_fn_, profile_path_),
967 base::Bind(&QuotaManager::DidGetAvailableSpace, 998 base::Bind(&QuotaManager::DidGetAvailableSpace,
968 weak_factory_.GetWeakPtr())); 999 weak_factory_.GetWeakPtr()));
969 } 1000 }
970 1001
971 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { 1002 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) {
972 LazyInitialize(); 1003 LazyInitialize();
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 eviction_context_.evicted_type = type; 1486 eviction_context_.evicted_type = type;
1456 eviction_context_.evict_origin_data_callback = callback; 1487 eviction_context_.evict_origin_data_callback = callback;
1457 1488
1458 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask, 1489 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask,
1459 base::Bind(&QuotaManager::DidOriginDataEvicted, 1490 base::Bind(&QuotaManager::DidOriginDataEvicted,
1460 weak_factory_.GetWeakPtr())); 1491 weak_factory_.GetWeakPtr()));
1461 } 1492 }
1462 1493
1463 void QuotaManager::GetUsageAndQuotaForEviction( 1494 void QuotaManager::GetUsageAndQuotaForEviction(
1464 const UsageAndQuotaCallback& callback) { 1495 const UsageAndQuotaCallback& callback) {
1496 // crbug.com/349708
1497 TRACE_EVENT0("io", "QuotaManager::GetUsageAndQuotaForEviction");
1498
1465 DCHECK(io_thread_->BelongsToCurrentThread()); 1499 DCHECK(io_thread_->BelongsToCurrentThread());
1466 LazyInitialize(); 1500 LazyInitialize();
1467 1501
1468 UsageAndQuotaCallbackDispatcher* dispatcher = 1502 UsageAndQuotaCallbackDispatcher* dispatcher =
1469 new UsageAndQuotaCallbackDispatcher(this); 1503 new UsageAndQuotaCallbackDispatcher(this);
1470 GetUsageTracker(kStorageTypeTemporary) 1504 GetUsageTracker(kStorageTypeTemporary)
1471 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); 1505 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback());
1472 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); 1506 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback());
1473 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); 1507 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback());
1474 dispatcher->WaitForResults(callback); 1508 dispatcher->WaitForResults(callback);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 weak_factory_.GetWeakPtr())); 1629 weak_factory_.GetWeakPtr()));
1596 } 1630 }
1597 1631
1598 void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) { 1632 void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) {
1599 DidDatabaseWork(success); 1633 DidDatabaseWork(success);
1600 if (success) 1634 if (success)
1601 StartEviction(); 1635 StartEviction();
1602 } 1636 }
1603 1637
1604 void QuotaManager::DidGetAvailableSpace(int64 space) { 1638 void QuotaManager::DidGetAvailableSpace(int64 space) {
1639 // crbug.com/349708
1640 TRACE_EVENT1("io", "QuotaManager::DidGetAvailableSpace",
1641 "n_callbacks", available_space_callbacks_.size());
1642
1605 available_space_callbacks_.Run(kQuotaStatusOk, space); 1643 available_space_callbacks_.Run(kQuotaStatusOk, space);
1606 } 1644 }
1607 1645
1608 void QuotaManager::DidDatabaseWork(bool success) { 1646 void QuotaManager::DidDatabaseWork(bool success) {
1609 db_disabled_ = !success; 1647 db_disabled_ = !success;
1610 } 1648 }
1611 1649
1612 void QuotaManager::DeleteOnCorrectThread() const { 1650 void QuotaManager::DeleteOnCorrectThread() const {
1613 if (!io_thread_->BelongsToCurrentThread() && 1651 if (!io_thread_->BelongsToCurrentThread() &&
1614 io_thread_->DeleteSoon(FROM_HERE, this)) { 1652 io_thread_->DeleteSoon(FROM_HERE, this)) {
(...skipping 10 matching lines...) Expand all
1625 // |database_|, therefore we can be sure that database_ is alive when this 1663 // |database_|, therefore we can be sure that database_ is alive when this
1626 // task runs. 1664 // task runs.
1627 base::PostTaskAndReplyWithResult( 1665 base::PostTaskAndReplyWithResult(
1628 db_thread_.get(), 1666 db_thread_.get(),
1629 from_here, 1667 from_here,
1630 base::Bind(task, base::Unretained(database_.get())), 1668 base::Bind(task, base::Unretained(database_.get())),
1631 reply); 1669 reply);
1632 } 1670 }
1633 1671
1634 } // namespace storage 1672 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/quota/quota_callbacks.h ('k') | storage/browser/quota/quota_manager_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698