browsing_data_quota_helper.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_H_ 6#define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_H_ 7 8#include <list> 9#include <string> 10 11#include "base/callback.h" 12#include "base/memory/ref_counted.h" 13#include "base/message_loop_proxy.h" 14#include "base/sequenced_task_runner_helpers.h" 15#include "webkit/quota/quota_types.h" 16 17class BrowsingDataQuotaHelper; 18class Profile; 19 20struct BrowsingDataQuotaHelperDeleter { 21 static void Destruct(const BrowsingDataQuotaHelper* helper); 22}; 23 24// This class is an interface class to bridge between Cookies Tree and Unified 25// Quota System. This class provides a way to get usage and quota information 26// through the instance. 27// 28// Call Create to create an instance for a profile and call StartFetching with 29// a callback to fetch information asynchronously. 30// 31// Parallel fetching is not allowed, a fetching task should start after end of 32// previous task. All method of this class should called from UI thread. 33class BrowsingDataQuotaHelper 34 : public base::RefCountedThreadSafe<BrowsingDataQuotaHelper, 35 BrowsingDataQuotaHelperDeleter> { 36 public: 37 // QuotaInfo contains host-based quota and usage information for persistent 38 // and temporary storage. 39 struct QuotaInfo { 40 QuotaInfo(); 41 explicit QuotaInfo(const std::string& host); 42 QuotaInfo(const std::string& host, 43 int64 temporary_usage, 44 int64 persistent_usage); 45 ~QuotaInfo(); 46 47 // Certain versions of MSVC 2008 have bad implementations of ADL for nested 48 // classes so they require these operators to be declared here instead of in 49 // the global namespace. 50 bool operator <(const QuotaInfo& rhs) const; 51 bool operator ==(const QuotaInfo& rhs) const; 52 53 std::string host; 54 int64 temporary_usage; 55 int64 persistent_usage; 56 }; 57 58 typedef std::list<QuotaInfo> QuotaInfoArray; 59 typedef base::Callback<void(const QuotaInfoArray&)> FetchResultCallback; 60 61 static BrowsingDataQuotaHelper* Create(Profile* profile); 62 63 virtual void StartFetching(const FetchResultCallback& callback) = 0; 64 65 virtual void RevokeHostQuota(const std::string& host) = 0; 66 67 protected: 68 explicit BrowsingDataQuotaHelper(base::MessageLoopProxy* io_thread_); 69 virtual ~BrowsingDataQuotaHelper(); 70 71 private: 72 friend class base::DeleteHelper<BrowsingDataQuotaHelper>; 73 friend struct BrowsingDataQuotaHelperDeleter; 74 scoped_refptr<base::MessageLoopProxy> io_thread_; 75 76 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelper); 77}; 78 79#endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_H_ 80