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

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

Issue 218793002: Provide monitoring of usage for a storage type and origin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failures Created 6 years, 8 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 | « webkit/browser/quota/quota_manager.h ('k') | webkit/browser/quota/storage_monitor.h » ('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 "webkit/browser/quota/quota_manager.h" 5 #include "webkit/browser/quota/quota_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <functional> 9 #include <functional>
10 #include <set> 10 #include <set>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/sequenced_task_runner.h" 19 #include "base/sequenced_task_runner.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/sys_info.h" 22 #include "base/sys_info.h"
23 #include "base/task_runner_util.h" 23 #include "base/task_runner_util.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "net/base/net_util.h" 25 #include "net/base/net_util.h"
26 #include "webkit/browser/quota/quota_database.h" 26 #include "webkit/browser/quota/quota_database.h"
27 #include "webkit/browser/quota/quota_manager_proxy.h" 27 #include "webkit/browser/quota/quota_manager_proxy.h"
28 #include "webkit/browser/quota/quota_temporary_storage_evictor.h" 28 #include "webkit/browser/quota/quota_temporary_storage_evictor.h"
29 #include "webkit/browser/quota/storage_monitor.h"
29 #include "webkit/browser/quota/usage_tracker.h" 30 #include "webkit/browser/quota/usage_tracker.h"
30 #include "webkit/common/quota/quota_types.h" 31 #include "webkit/common/quota/quota_types.h"
31 32
32 #define UMA_HISTOGRAM_MBYTES(name, sample) \ 33 #define UMA_HISTOGRAM_MBYTES(name, sample) \
33 UMA_HISTOGRAM_CUSTOM_COUNTS( \ 34 UMA_HISTOGRAM_CUSTOM_COUNTS( \
34 (name), static_cast<int>((sample) / kMBytes), \ 35 (name), static_cast<int>((sample) / kMBytes), \
35 1, 10 * 1024 * 1024 /* 10TB */, 100) 36 1, 10 * 1024 * 1024 /* 10TB */, 100)
36 37
37 namespace quota { 38 namespace quota {
38 39
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 this, io_thread)), 802 this, io_thread)),
802 db_disabled_(false), 803 db_disabled_(false),
803 eviction_disabled_(false), 804 eviction_disabled_(false),
804 io_thread_(io_thread), 805 io_thread_(io_thread),
805 db_thread_(db_thread), 806 db_thread_(db_thread),
806 temporary_quota_initialized_(false), 807 temporary_quota_initialized_(false),
807 temporary_quota_override_(-1), 808 temporary_quota_override_(-1),
808 desired_available_space_(-1), 809 desired_available_space_(-1),
809 special_storage_policy_(special_storage_policy), 810 special_storage_policy_(special_storage_policy),
810 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace), 811 get_disk_space_fn_(&CallSystemGetAmountOfFreeDiskSpace),
812 storage_monitor_(new StorageMonitor(this)),
811 weak_factory_(this) { 813 weak_factory_(this) {
812 } 814 }
813 815
814 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) { 816 void QuotaManager::GetUsageInfo(const GetUsageInfoCallback& callback) {
815 LazyInitialize(); 817 LazyInitialize();
816 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback); 818 GetUsageInfoTask* get_usage_info = new GetUsageInfoTask(this, callback);
817 get_usage_info->Start(); 819 get_usage_info->Start();
818 } 820 }
819 821
820 void QuotaManager::GetUsageAndQuotaForWebApps( 822 void QuotaManager::GetUsageAndQuotaForWebApps(
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 type)); 1154 type));
1153 } 1155 }
1154 1156
1155 bool QuotaManager::ResetUsageTracker(StorageType type) { 1157 bool QuotaManager::ResetUsageTracker(StorageType type) {
1156 DCHECK(GetUsageTracker(type)); 1158 DCHECK(GetUsageTracker(type));
1157 if (GetUsageTracker(type)->IsWorking()) 1159 if (GetUsageTracker(type)->IsWorking())
1158 return false; 1160 return false;
1159 switch (type) { 1161 switch (type) {
1160 case kStorageTypeTemporary: 1162 case kStorageTypeTemporary:
1161 temporary_usage_tracker_.reset(new UsageTracker( 1163 temporary_usage_tracker_.reset(new UsageTracker(
1162 clients_, kStorageTypeTemporary, special_storage_policy_.get())); 1164 clients_, kStorageTypeTemporary, special_storage_policy_.get(),
1165 storage_monitor_.get()));
1163 return true; 1166 return true;
1164 case kStorageTypePersistent: 1167 case kStorageTypePersistent:
1165 persistent_usage_tracker_.reset(new UsageTracker( 1168 persistent_usage_tracker_.reset(new UsageTracker(
1166 clients_, kStorageTypePersistent, special_storage_policy_.get())); 1169 clients_, kStorageTypePersistent, special_storage_policy_.get(),
1170 storage_monitor_.get()));
1167 return true; 1171 return true;
1168 case kStorageTypeSyncable: 1172 case kStorageTypeSyncable:
1169 syncable_usage_tracker_.reset(new UsageTracker( 1173 syncable_usage_tracker_.reset(new UsageTracker(
1170 clients_, kStorageTypeSyncable, special_storage_policy_.get())); 1174 clients_, kStorageTypeSyncable, special_storage_policy_.get(),
1175 storage_monitor_.get()));
1171 return true; 1176 return true;
1172 default: 1177 default:
1173 NOTREACHED(); 1178 NOTREACHED();
1174 } 1179 }
1175 return true; 1180 return true;
1176 } 1181 }
1177 1182
1183 void QuotaManager::AddStorageObserver(
1184 StorageObserver* observer, const StorageObserver::MonitorParams& params) {
1185 DCHECK(observer);
1186 storage_monitor_->AddObserver(observer, params);
1187 }
1188
1189 void QuotaManager::RemoveStorageObserver(StorageObserver* observer) {
1190 DCHECK(observer);
1191 storage_monitor_->RemoveObserver(observer);
1192 }
1193
1194 void QuotaManager::RemoveStorageObserverForFilter(
1195 StorageObserver* observer, const StorageObserver::Filter& filter) {
1196 DCHECK(observer);
1197 storage_monitor_->RemoveObserverForFilter(observer, filter);
1198 }
1199
1178 QuotaManager::~QuotaManager() { 1200 QuotaManager::~QuotaManager() {
1179 proxy_->manager_ = NULL; 1201 proxy_->manager_ = NULL;
1180 std::for_each(clients_.begin(), clients_.end(), 1202 std::for_each(clients_.begin(), clients_.end(),
1181 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed)); 1203 std::mem_fun(&QuotaClient::OnQuotaManagerDestroyed));
1182 if (database_) 1204 if (database_)
1183 db_thread_->DeleteSoon(FROM_HERE, database_.release()); 1205 db_thread_->DeleteSoon(FROM_HERE, database_.release());
1184 } 1206 }
1185 1207
1186 QuotaManager::EvictionContext::EvictionContext() 1208 QuotaManager::EvictionContext::EvictionContext()
1187 : evicted_type(kStorageTypeUnknown) { 1209 : evicted_type(kStorageTypeUnknown) {
1188 } 1210 }
1189 1211
1190 QuotaManager::EvictionContext::~EvictionContext() { 1212 QuotaManager::EvictionContext::~EvictionContext() {
1191 } 1213 }
1192 1214
1193 void QuotaManager::LazyInitialize() { 1215 void QuotaManager::LazyInitialize() {
1194 DCHECK(io_thread_->BelongsToCurrentThread()); 1216 DCHECK(io_thread_->BelongsToCurrentThread());
1195 if (database_) { 1217 if (database_) {
1196 // Initialization seems to be done already. 1218 // Initialization seems to be done already.
1197 return; 1219 return;
1198 } 1220 }
1199 1221
1200 // Use an empty path to open an in-memory only databse for incognito. 1222 // Use an empty path to open an in-memory only databse for incognito.
1201 database_.reset(new QuotaDatabase(is_incognito_ ? base::FilePath() : 1223 database_.reset(new QuotaDatabase(is_incognito_ ? base::FilePath() :
1202 profile_path_.AppendASCII(kDatabaseName))); 1224 profile_path_.AppendASCII(kDatabaseName)));
1203 1225
1204 temporary_usage_tracker_.reset(new UsageTracker( 1226 temporary_usage_tracker_.reset(new UsageTracker(
1205 clients_, kStorageTypeTemporary, special_storage_policy_.get())); 1227 clients_, kStorageTypeTemporary, special_storage_policy_.get(),
1228 storage_monitor_.get()));
1206 persistent_usage_tracker_.reset(new UsageTracker( 1229 persistent_usage_tracker_.reset(new UsageTracker(
1207 clients_, kStorageTypePersistent, special_storage_policy_.get())); 1230 clients_, kStorageTypePersistent, special_storage_policy_.get(),
1231 storage_monitor_.get()));
1208 syncable_usage_tracker_.reset(new UsageTracker( 1232 syncable_usage_tracker_.reset(new UsageTracker(
1209 clients_, kStorageTypeSyncable, special_storage_policy_.get())); 1233 clients_, kStorageTypeSyncable, special_storage_policy_.get(),
1234 storage_monitor_.get()));
1210 1235
1211 int64* temporary_quota_override = new int64(-1); 1236 int64* temporary_quota_override = new int64(-1);
1212 int64* desired_available_space = new int64(-1); 1237 int64* desired_available_space = new int64(-1);
1213 PostTaskAndReplyWithResultForDBThread( 1238 PostTaskAndReplyWithResultForDBThread(
1214 FROM_HERE, 1239 FROM_HERE,
1215 base::Bind(&InitializeOnDBThread, 1240 base::Bind(&InitializeOnDBThread,
1216 base::Unretained(temporary_quota_override), 1241 base::Unretained(temporary_quota_override),
1217 base::Unretained(desired_available_space)), 1242 base::Unretained(desired_available_space)),
1218 base::Bind(&QuotaManager::DidInitialize, 1243 base::Bind(&QuotaManager::DidInitialize,
1219 weak_factory_.GetWeakPtr(), 1244 weak_factory_.GetWeakPtr(),
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 // |database_|, therefore we can be sure that database_ is alive when this 1616 // |database_|, therefore we can be sure that database_ is alive when this
1592 // task runs. 1617 // task runs.
1593 base::PostTaskAndReplyWithResult( 1618 base::PostTaskAndReplyWithResult(
1594 db_thread_.get(), 1619 db_thread_.get(),
1595 from_here, 1620 from_here,
1596 base::Bind(task, base::Unretained(database_.get())), 1621 base::Bind(task, base::Unretained(database_.get())),
1597 reply); 1622 reply);
1598 } 1623 }
1599 1624
1600 } // namespace quota 1625 } // namespace quota
OLDNEW
« no previous file with comments | « webkit/browser/quota/quota_manager.h ('k') | webkit/browser/quota/storage_monitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698