diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-13 05:05:16 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-13 05:05:16 +0000 |
commit | 69fe5a71188ed35b9f5f7827517a94dc91591807 (patch) | |
tree | e8ee2d0e6681e24fb94266e323fb252b4d43e5dc /webkit/quota | |
parent | d5a06328ca5a62834e42cb7c03d8f73e99420f9e (diff) | |
download | chromium_src-69fe5a71188ed35b9f5f7827517a94dc91591807.zip chromium_src-69fe5a71188ed35b9f5f7827517a94dc91591807.tar.gz chromium_src-69fe5a71188ed35b9f5f7827517a94dc91591807.tar.bz2 |
Add syncable filesystem/storage type
BUG=147763
TBR=jam@chromium.org,estade@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10915203
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/quota')
-rw-r--r-- | webkit/quota/quota_manager.cc | 53 | ||||
-rw-r--r-- | webkit/quota/quota_manager.h | 10 | ||||
-rw-r--r-- | webkit/quota/quota_manager_unittest.cc | 1 | ||||
-rw-r--r-- | webkit/quota/quota_types.h | 1 | ||||
-rw-r--r-- | webkit/quota/usage_tracker.cc | 2 |
5 files changed, 61 insertions, 6 deletions
diff --git a/webkit/quota/quota_manager.cc b/webkit/quota/quota_manager.cc index 9b92b66..095c24d 100644 --- a/webkit/quota/quota_manager.cc +++ b/webkit/quota/quota_manager.cc @@ -162,6 +162,11 @@ const int QuotaManager::kThresholdOfErrorsToBeBlacklisted = 3; const int QuotaManager::kEvictionIntervalInMilliSeconds = 30 * kMinutesInMilliSeconds; +// Heuristics: assuming average cloud server allows a few Gigs storage +// on the server side and the storage needs to be shared for user data +// and by multiple apps. +int64 QuotaManager::kSyncableStorageDefaultHostQuota = 500 * kMBytes; + // Callback translators. void CallGetUsageAndQuotaCallback( const QuotaManager::GetUsageAndQuotaCallback& callback, @@ -411,7 +416,7 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask { protected: virtual void Run() OVERRIDE { - remaining_trackers_ = 2; + remaining_trackers_ = 3; // This will populate cached hosts and usage info. manager()->GetUsageTracker(kStorageTypeTemporary)->GetGlobalUsage( base::Bind(&GetUsageInfoTask::DidGetGlobalUsage, @@ -419,6 +424,9 @@ class QuotaManager::GetUsageInfoTask : public QuotaTask { manager()->GetUsageTracker(kStorageTypePersistent)->GetGlobalUsage( base::Bind(&GetUsageInfoTask::DidGetGlobalUsage, weak_factory_.GetWeakPtr())); + manager()->GetUsageTracker(kStorageTypeSyncable)->GetGlobalUsage( + base::Bind(&GetUsageInfoTask::DidGetGlobalUsage, + weak_factory_.GetWeakPtr())); } virtual void Completed() OVERRIDE { @@ -517,6 +525,29 @@ class QuotaManager::UsageAndQuotaDispatcherTaskForPersistent } }; +class QuotaManager::UsageAndQuotaDispatcherTaskForSyncable + : public QuotaManager::UsageAndQuotaDispatcherTask { + public: + UsageAndQuotaDispatcherTaskForSyncable( + QuotaManager* manager, const HostAndType& host_and_type) + : UsageAndQuotaDispatcherTask(manager, host_and_type) {} + + protected: + virtual void RunBody() OVERRIDE { + manager()->GetUsageTracker(type())->GetHostUsage( + host(), NewWaitableHostUsageCallback()); + } + + virtual void DispatchCallbacks() OVERRIDE { + // TODO(kinuko): We should reflect the backend's actual quota instead + // of returning a fixed default value. + CallCallbacksAndClear(quota_status(), + host_usage(), host_usage(), + kSyncableStorageDefaultHostQuota, + available_space()); + } +}; + class QuotaManager::UsageAndQuotaDispatcherTaskForTemporaryGlobal : public QuotaManager::UsageAndQuotaDispatcherTask { public: @@ -556,6 +587,9 @@ QuotaManager::UsageAndQuotaDispatcherTask::Create( case kStorageTypePersistent: return new UsageAndQuotaDispatcherTaskForPersistent( manager, host_and_type); + case kStorageTypeSyncable: + return new UsageAndQuotaDispatcherTaskForSyncable( + manager, host_and_type); default: NOTREACHED(); } @@ -864,7 +898,7 @@ void QuotaManager::GetUsageAndQuota( GetUsageAndQuotaInternal( origin, type, false /* global */, base::Bind(&CallGetUsageAndQuotaCallback, callback, - IsStorageUnlimited(origin), IsInstalledApp(origin))); + IsStorageUnlimited(origin, type), IsInstalledApp(origin))); } void QuotaManager::NotifyStorageAccessed( @@ -1063,6 +1097,16 @@ void QuotaManager::GetStatistics( } } +bool QuotaManager::IsStorageUnlimited(const GURL& origin, + StorageType type) const { + // For syncable storage we should always enforce quota (since the + // quota must be capped by the server limit). + if (type == kStorageTypeSyncable) + return false; + return special_storage_policy_.get() && + special_storage_policy_->IsStorageUnlimited(origin); +} + void QuotaManager::GetOriginsModifiedSince(StorageType type, base::Time modified_since, const GetOriginsCallback& callback) { @@ -1134,6 +1178,9 @@ void QuotaManager::LazyInitialize() { persistent_usage_tracker_.reset( new UsageTracker(clients_, kStorageTypePersistent, special_storage_policy_)); + syncable_usage_tracker_.reset( + new UsageTracker(clients_, kStorageTypeSyncable, + special_storage_policy_)); int64* temporary_quota_override = new int64(-1); int64* desired_available_space = new int64(-1); @@ -1159,6 +1206,8 @@ UsageTracker* QuotaManager::GetUsageTracker(StorageType type) const { return temporary_usage_tracker_.get(); case kStorageTypePersistent: return persistent_usage_tracker_.get(); + case kStorageTypeSyncable: + return syncable_usage_tracker_.get(); default: NOTREACHED(); } diff --git a/webkit/quota/quota_manager.h b/webkit/quota/quota_manager.h index a8530da..ce4d5dc 100644 --- a/webkit/quota/quota_manager.h +++ b/webkit/quota/quota_manager.h @@ -183,10 +183,7 @@ class QuotaManager : public QuotaTaskObserver, void GetStatistics(std::map<std::string, std::string>* statistics); - bool IsStorageUnlimited(const GURL& origin) const { - return special_storage_policy_.get() && - special_storage_policy_->IsStorageUnlimited(origin); - } + bool IsStorageUnlimited(const GURL& origin, StorageType type) const; bool IsInstalledApp(const GURL& origin) const { return special_storage_policy_.get() && @@ -209,6 +206,9 @@ class QuotaManager : public QuotaTaskObserver, static const int kEvictionIntervalInMilliSeconds; + // This is kept non-const so that test code can change the value. + static int64 kSyncableStorageDefaultHostQuota; + protected: virtual ~QuotaManager(); @@ -226,6 +226,7 @@ class QuotaManager : public QuotaTaskObserver, class UsageAndQuotaDispatcherTask; class UsageAndQuotaDispatcherTaskForTemporary; class UsageAndQuotaDispatcherTaskForPersistent; + class UsageAndQuotaDispatcherTaskForSyncable; class UsageAndQuotaDispatcherTaskForTemporaryGlobal; class OriginDataDeleter; @@ -378,6 +379,7 @@ class QuotaManager : public QuotaTaskObserver, scoped_ptr<UsageTracker> temporary_usage_tracker_; scoped_ptr<UsageTracker> persistent_usage_tracker_; + scoped_ptr<UsageTracker> syncable_usage_tracker_; // TODO(michaeln): Need a way to clear the cache, drop and // reinstantiate the trackers when they're not handling requests. diff --git a/webkit/quota/quota_manager_unittest.cc b/webkit/quota/quota_manager_unittest.cc index 2002e84..16fc799 100644 --- a/webkit/quota/quota_manager_unittest.cc +++ b/webkit/quota/quota_manager_unittest.cc @@ -30,6 +30,7 @@ namespace quota { // For shorter names. const StorageType kTemp = kStorageTypeTemporary; const StorageType kPerm = kStorageTypePersistent; +const StorageType kSync = kStorageTypeSyncable; const int kAllClients = QuotaClient::kAllClientsMask; diff --git a/webkit/quota/quota_types.h b/webkit/quota/quota_types.h index a744b26..a66a9ca 100644 --- a/webkit/quota/quota_types.h +++ b/webkit/quota/quota_types.h @@ -21,6 +21,7 @@ namespace quota { enum StorageType { kStorageTypeTemporary, kStorageTypePersistent, + kStorageTypeSyncable, kStorageTypeUnknown, }; diff --git a/webkit/quota/usage_tracker.cc b/webkit/quota/usage_tracker.cc index fefe813..b01de32 100644 --- a/webkit/quota/usage_tracker.cc +++ b/webkit/quota/usage_tracker.cc @@ -521,6 +521,8 @@ void ClientUsageTracker::NoopHostUsageCallback( } bool ClientUsageTracker::IsStorageUnlimited(const GURL& origin) const { + if (type_ == kStorageTypeSyncable) + return false; return special_storage_policy_.get() && special_storage_policy_->IsStorageUnlimited(origin); } |