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

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

Issue 2777183010: [Quota] Lower quota for ephemeral mode (ie. session only) (Closed)
Patch Set: randomize Created 3 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
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 } 208 }
209 209
210 } // namespace 210 } // namespace
211 211
212 class QuotaManager::UsageAndQuotaHelper : public QuotaTask { 212 class QuotaManager::UsageAndQuotaHelper : public QuotaTask {
213 public: 213 public:
214 UsageAndQuotaHelper(QuotaManager* manager, 214 UsageAndQuotaHelper(QuotaManager* manager,
215 const GURL& origin, 215 const GURL& origin,
216 StorageType type, 216 StorageType type,
217 bool is_unlimited, 217 bool is_unlimited,
218 bool is_session_only,
218 bool is_incognito, 219 bool is_incognito,
219 const UsageAndQuotaCallback& callback) 220 const UsageAndQuotaCallback& callback)
220 : QuotaTask(manager), 221 : QuotaTask(manager),
221 origin_(origin), 222 origin_(origin),
222 callback_(callback), 223 callback_(callback),
223 type_(type), 224 type_(type),
224 is_unlimited_(is_unlimited), 225 is_unlimited_(is_unlimited),
226 is_session_only_(is_session_only),
225 is_incognito_(is_incognito), 227 is_incognito_(is_incognito),
226 weak_factory_(this) {} 228 weak_factory_(this) {}
227 229
228 protected: 230 protected:
229 void Run() override { 231 void Run() override {
230 // Start the async process of gathering the info we need. 232 // Start the async process of gathering the info we need.
231 // Gather 4 pieces of info before computing an answer: 233 // Gather 4 pieces of info before computing an answer:
232 // settings, device_storage_capacity, host_usage, and host_quota. 234 // settings, device_storage_capacity, host_usage, and host_quota.
233 base::Closure barrier = base::BarrierClosure( 235 base::Closure barrier = base::BarrierClosure(
234 4, base::Bind(&UsageAndQuotaHelper::OnBarrierComplete, 236 4, base::Bind(&UsageAndQuotaHelper::OnBarrierComplete,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 private: 295 private:
294 QuotaManager* manager() const { 296 QuotaManager* manager() const {
295 return static_cast<QuotaManager*>(observer()); 297 return static_cast<QuotaManager*>(observer());
296 } 298 }
297 299
298 void OnGotSettings(const base::Closure& barrier_closure, 300 void OnGotSettings(const base::Closure& barrier_closure,
299 const QuotaSettings& settings) { 301 const QuotaSettings& settings) {
300 settings_ = settings; 302 settings_ = settings;
301 barrier_closure.Run(); 303 barrier_closure.Run();
302 if (type_ == kStorageTypeTemporary && !is_unlimited_) { 304 if (type_ == kStorageTypeTemporary && !is_unlimited_) {
303 SetDesiredHostQuota(barrier_closure, kQuotaStatusOk, 305 int64_t host_quota = is_session_only_
304 settings.per_host_quota); 306 ? settings.session_only_per_host_quota
307 : settings.per_host_quota;
308 SetDesiredHostQuota(barrier_closure, kQuotaStatusOk, host_quota);
305 } 309 }
306 } 310 }
307 311
308 void OnGotCapacity(const base::Closure& barrier_closure, 312 void OnGotCapacity(const base::Closure& barrier_closure,
309 int64_t total_space, 313 int64_t total_space,
310 int64_t available_space) { 314 int64_t available_space) {
311 total_space_ = total_space; 315 total_space_ = total_space;
312 available_space_ = available_space; 316 available_space_ = available_space;
313 barrier_closure.Run(); 317 barrier_closure.Run();
314 } 318 }
315 319
316 void OnGotHostUsage(const base::Closure& barrier_closure, int64_t usage) { 320 void OnGotHostUsage(const base::Closure& barrier_closure, int64_t usage) {
317 host_usage_ = usage; 321 host_usage_ = usage;
318 barrier_closure.Run(); 322 barrier_closure.Run();
319 } 323 }
320 324
321 void SetDesiredHostQuota(const base::Closure& barrier_closure, 325 void SetDesiredHostQuota(const base::Closure& barrier_closure,
322 QuotaStatusCode status, 326 QuotaStatusCode status,
323 int64_t quota) { 327 int64_t quota) {
324 desired_host_quota_ = quota; 328 desired_host_quota_ = quota;
325 barrier_closure.Run(); 329 barrier_closure.Run();
326 } 330 }
327 331
328 void OnBarrierComplete() { CallCompleted(); } 332 void OnBarrierComplete() { CallCompleted(); }
329 333
330 GURL origin_; 334 GURL origin_;
331 QuotaManager::UsageAndQuotaCallback callback_; 335 QuotaManager::UsageAndQuotaCallback callback_;
332 StorageType type_; 336 StorageType type_;
333 bool is_unlimited_; 337 bool is_unlimited_;
338 bool is_session_only_;
334 bool is_incognito_; 339 bool is_incognito_;
335 int64_t available_space_ = 0; 340 int64_t available_space_ = 0;
336 int64_t total_space_ = 0; 341 int64_t total_space_ = 0;
337 int64_t desired_host_quota_ = 0; 342 int64_t desired_host_quota_ = 0;
338 int64_t host_usage_ = 0; 343 int64_t host_usage_ = 0;
339 QuotaSettings settings_; 344 QuotaSettings settings_;
340 base::WeakPtrFactory<UsageAndQuotaHelper> weak_factory_; 345 base::WeakPtrFactory<UsageAndQuotaHelper> weak_factory_;
341 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaHelper); 346 DISALLOW_COPY_AND_ASSIGN(UsageAndQuotaHelper);
342 }; 347 };
343 348
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 const GURL& origin, 839 const GURL& origin,
835 StorageType type, 840 StorageType type,
836 const UsageAndQuotaCallback& callback) { 841 const UsageAndQuotaCallback& callback) {
837 DCHECK(origin == origin.GetOrigin()); 842 DCHECK(origin == origin.GetOrigin());
838 if (!IsSupportedType(type) || 843 if (!IsSupportedType(type) ||
839 (is_incognito_ && !IsSupportedIncognitoType(type))) { 844 (is_incognito_ && !IsSupportedIncognitoType(type))) {
840 callback.Run(kQuotaErrorNotSupported, 0, 0); 845 callback.Run(kQuotaErrorNotSupported, 0, 0);
841 return; 846 return;
842 } 847 }
843 LazyInitialize(); 848 LazyInitialize();
849
850 bool is_session_only = special_storage_policy_.get() &&
cmumford 2017/04/04 16:38:29 Nit: scoped_refptr has: explicit operator bool()
michaeln 2017/04/05 01:20:56 Done.
851 special_storage_policy_->IsStorageSessionOnly(origin);
844 UsageAndQuotaHelper* helper = new UsageAndQuotaHelper( 852 UsageAndQuotaHelper* helper = new UsageAndQuotaHelper(
845 this, origin, type, IsStorageUnlimited(origin, type), is_incognito_, 853 this, origin, type, IsStorageUnlimited(origin, type), is_session_only,
846 callback); 854 is_incognito_, callback);
847 helper->Start(); 855 helper->Start();
848 } 856 }
849 857
850 void QuotaManager::GetUsageAndQuota(const GURL& origin, 858 void QuotaManager::GetUsageAndQuota(const GURL& origin,
851 StorageType type, 859 StorageType type,
852 const UsageAndQuotaCallback& callback) { 860 const UsageAndQuotaCallback& callback) {
853 DCHECK(origin == origin.GetOrigin()); 861 DCHECK(origin == origin.GetOrigin());
854 862
855 if (IsStorageUnlimited(origin, type)) { 863 if (IsStorageUnlimited(origin, type)) {
856 // TODO(michaeln): This seems like a non-obvious odd behavior, probably for 864 // TODO(michaeln): This seems like a non-obvious odd behavior, probably for
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 } 1684 }
1677 1685
1678 // static 1686 // static
1679 std::tuple<int64_t, int64_t> QuotaManager::GetVolumeInfo( 1687 std::tuple<int64_t, int64_t> QuotaManager::GetVolumeInfo(
1680 const base::FilePath& path) { 1688 const base::FilePath& path) {
1681 return std::make_tuple(base::SysInfo::AmountOfTotalDiskSpace(path), 1689 return std::make_tuple(base::SysInfo::AmountOfTotalDiskSpace(path),
1682 base::SysInfo::AmountOfFreeDiskSpace(path)); 1690 base::SysInfo::AmountOfFreeDiskSpace(path));
1683 } 1691 }
1684 1692
1685 } // namespace storage 1693 } // namespace storage
OLDNEW
« no previous file with comments | « no previous file | storage/browser/quota/quota_settings.h » ('j') | storage/browser/quota/quota_settings.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698