Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 } | 181 } |
| 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) { |
|
kinuko
2015/10/08 09:08:44
Let's have a trace here too
| |
| 191 // Ensure the profile path exists. | 192 // Ensure the profile path exists. |
| 192 if (!base::CreateDirectory(profile_path)) { | 193 if (!base::CreateDirectory(profile_path)) { |
| 193 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); | 194 LOG(WARNING) << "Create directory failed for path" << profile_path.value(); |
| 194 return 0; | 195 return 0; |
| 195 } | 196 } |
| 196 return base::SysInfo::AmountOfFreeDiskSpace(profile_path); | 197 return base::SysInfo::AmountOfFreeDiskSpace(profile_path); |
| 197 } | 198 } |
| 198 | 199 |
| 199 int64 CalculateTemporaryGlobalQuota(int64 global_limited_usage, | 200 int64 CalculateTemporaryGlobalQuota(int64 global_limited_usage, |
| 200 int64 available_space) { | 201 int64 available_space) { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 CheckCompleted(); | 403 CheckCompleted(); |
| 403 } | 404 } |
| 404 | 405 |
| 405 void DidGetQuota(QuotaStatusCode status, int64 quota) { | 406 void DidGetQuota(QuotaStatusCode status, int64 quota) { |
| 406 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) | 407 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) |
| 407 status_ = status; | 408 status_ = status; |
| 408 usage_and_quota_.quota = quota; | 409 usage_and_quota_.quota = quota; |
| 409 CheckCompleted(); | 410 CheckCompleted(); |
| 410 } | 411 } |
| 411 | 412 |
| 412 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) { | 413 void DidGetAvailableSpace(QuotaStatusCode status, int64 space) { |
|
kinuko
2015/10/08 09:08:44
Let's add trace here too
| |
| 413 DCHECK_GE(space, 0); | 414 DCHECK_GE(space, 0); |
| 414 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) | 415 if (status_ == kQuotaStatusUnknown || status_ == kQuotaStatusOk) |
| 415 status_ = status; | 416 status_ = status; |
| 416 usage_and_quota_.available_disk_space = space; | 417 usage_and_quota_.available_disk_space = space; |
| 417 CheckCompleted(); | 418 CheckCompleted(); |
| 418 } | 419 } |
| 419 | 420 |
| 420 void Run() override { | 421 void Run() override { |
| 421 // We initialize waiting_callbacks to 1 so that we won't run | 422 // We initialize waiting_callbacks to 1 so that we won't run |
| 422 // the completion callback until here even some of the callbacks | 423 // the completion callback until here even some of the callbacks |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 952 return; | 953 return; |
| 953 } | 954 } |
| 954 | 955 |
| 955 HostDataDeleter* deleter = | 956 HostDataDeleter* deleter = |
| 956 new HostDataDeleter(this, host, type, quota_client_mask, callback); | 957 new HostDataDeleter(this, host, type, quota_client_mask, callback); |
| 957 deleter->Start(); | 958 deleter->Start(); |
| 958 } | 959 } |
| 959 | 960 |
| 960 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { | 961 void QuotaManager::GetAvailableSpace(const AvailableSpaceCallback& callback) { |
| 961 if (!available_space_callbacks_.Add(callback)) | 962 if (!available_space_callbacks_.Add(callback)) |
| 962 return; | 963 return; |
|
kinuko
2015/10/08 09:08:44
Maybe have a trace here too?
| |
| 963 | 964 |
| 964 PostTaskAndReplyWithResult(db_thread_.get(), | 965 PostTaskAndReplyWithResult(db_thread_.get(), |
| 965 FROM_HERE, | 966 FROM_HERE, |
| 966 base::Bind(get_disk_space_fn_, profile_path_), | 967 base::Bind(get_disk_space_fn_, profile_path_), |
| 967 base::Bind(&QuotaManager::DidGetAvailableSpace, | 968 base::Bind(&QuotaManager::DidGetAvailableSpace, |
| 968 weak_factory_.GetWeakPtr())); | 969 weak_factory_.GetWeakPtr())); |
| 969 } | 970 } |
| 970 | 971 |
| 971 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { | 972 void QuotaManager::GetTemporaryGlobalQuota(const QuotaCallback& callback) { |
| 972 LazyInitialize(); | 973 LazyInitialize(); |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1455 eviction_context_.evicted_type = type; | 1456 eviction_context_.evicted_type = type; |
| 1456 eviction_context_.evict_origin_data_callback = callback; | 1457 eviction_context_.evict_origin_data_callback = callback; |
| 1457 | 1458 |
| 1458 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask, | 1459 DeleteOriginData(origin, type, QuotaClient::kAllClientsMask, |
| 1459 base::Bind(&QuotaManager::DidOriginDataEvicted, | 1460 base::Bind(&QuotaManager::DidOriginDataEvicted, |
| 1460 weak_factory_.GetWeakPtr())); | 1461 weak_factory_.GetWeakPtr())); |
| 1461 } | 1462 } |
| 1462 | 1463 |
| 1463 void QuotaManager::GetUsageAndQuotaForEviction( | 1464 void QuotaManager::GetUsageAndQuotaForEviction( |
| 1464 const UsageAndQuotaCallback& callback) { | 1465 const UsageAndQuotaCallback& callback) { |
| 1466 // crbug.com/349708 | |
| 1467 TRACE_EVENT0("io", "QuotaManager::GetUsageAndQuotaForEviction"); | |
| 1468 | |
| 1465 DCHECK(io_thread_->BelongsToCurrentThread()); | 1469 DCHECK(io_thread_->BelongsToCurrentThread()); |
| 1466 LazyInitialize(); | 1470 LazyInitialize(); |
| 1467 | 1471 |
| 1468 UsageAndQuotaCallbackDispatcher* dispatcher = | 1472 UsageAndQuotaCallbackDispatcher* dispatcher = |
| 1469 new UsageAndQuotaCallbackDispatcher(this); | 1473 new UsageAndQuotaCallbackDispatcher(this); |
| 1470 GetUsageTracker(kStorageTypeTemporary) | 1474 GetUsageTracker(kStorageTypeTemporary) |
| 1471 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); | 1475 ->GetGlobalLimitedUsage(dispatcher->GetGlobalLimitedUsageCallback()); |
| 1472 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); | 1476 GetTemporaryGlobalQuota(dispatcher->GetQuotaCallback()); |
| 1473 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); | 1477 GetAvailableSpace(dispatcher->GetAvailableSpaceCallback()); |
| 1474 dispatcher->WaitForResults(callback); | 1478 dispatcher->WaitForResults(callback); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1594 base::Bind(&QuotaManager::DidInitializeTemporaryOriginsInfo, | 1598 base::Bind(&QuotaManager::DidInitializeTemporaryOriginsInfo, |
| 1595 weak_factory_.GetWeakPtr())); | 1599 weak_factory_.GetWeakPtr())); |
| 1596 } | 1600 } |
| 1597 | 1601 |
| 1598 void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) { | 1602 void QuotaManager::DidInitializeTemporaryOriginsInfo(bool success) { |
| 1599 DidDatabaseWork(success); | 1603 DidDatabaseWork(success); |
| 1600 if (success) | 1604 if (success) |
| 1601 StartEviction(); | 1605 StartEviction(); |
| 1602 } | 1606 } |
| 1603 | 1607 |
| 1604 void QuotaManager::DidGetAvailableSpace(int64 space) { | 1608 void QuotaManager::DidGetAvailableSpace(int64 space) { |
|
kinuko
2015/10/08 09:08:44
Let's have trace here too
michaeln
2015/10/09 00:51:43
Yes, i think this is the root of what we want to t
oshima
2015/10/09 17:14:09
Yes. I thought so adding trace here doesn't help m
michaeln
2015/10/09 19:00:05
it could help. there are at least two possibilitie
oshima
2015/10/09 21:07:00
Done.
| |
| 1605 available_space_callbacks_.Run(kQuotaStatusOk, space); | 1609 available_space_callbacks_.Run(kQuotaStatusOk, space); |
| 1606 } | 1610 } |
| 1607 | 1611 |
| 1608 void QuotaManager::DidDatabaseWork(bool success) { | 1612 void QuotaManager::DidDatabaseWork(bool success) { |
| 1609 db_disabled_ = !success; | 1613 db_disabled_ = !success; |
| 1610 } | 1614 } |
| 1611 | 1615 |
| 1612 void QuotaManager::DeleteOnCorrectThread() const { | 1616 void QuotaManager::DeleteOnCorrectThread() const { |
| 1613 if (!io_thread_->BelongsToCurrentThread() && | 1617 if (!io_thread_->BelongsToCurrentThread() && |
| 1614 io_thread_->DeleteSoon(FROM_HERE, this)) { | 1618 io_thread_->DeleteSoon(FROM_HERE, this)) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1625 // |database_|, therefore we can be sure that database_ is alive when this | 1629 // |database_|, therefore we can be sure that database_ is alive when this |
| 1626 // task runs. | 1630 // task runs. |
| 1627 base::PostTaskAndReplyWithResult( | 1631 base::PostTaskAndReplyWithResult( |
| 1628 db_thread_.get(), | 1632 db_thread_.get(), |
| 1629 from_here, | 1633 from_here, |
| 1630 base::Bind(task, base::Unretained(database_.get())), | 1634 base::Bind(task, base::Unretained(database_.get())), |
| 1631 reply); | 1635 reply); |
| 1632 } | 1636 } |
| 1633 | 1637 |
| 1634 } // namespace storage | 1638 } // namespace storage |
| OLD | NEW |