• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/message_loop_proxy.h"
14 #include "base/sequenced_task_runner_helpers.h"
15 #include "webkit/common/quota/quota_types.h"
16 
17 class BrowsingDataQuotaHelper;
18 class Profile;
19 
20 struct 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.
33 class 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               int64 syncable_usage);
46     ~QuotaInfo();
47 
48     // Certain versions of MSVC 2008 have bad implementations of ADL for nested
49     // classes so they require these operators to be declared here instead of in
50     // the global namespace.
51     bool operator <(const QuotaInfo& rhs) const;
52     bool operator ==(const QuotaInfo& rhs) const;
53 
54     std::string host;
55     int64 temporary_usage;
56     int64 persistent_usage;
57     int64 syncable_usage;
58   };
59 
60   typedef std::list<QuotaInfo> QuotaInfoArray;
61   typedef base::Callback<void(const QuotaInfoArray&)> FetchResultCallback;
62 
63   static BrowsingDataQuotaHelper* Create(Profile* profile);
64 
65   virtual void StartFetching(const FetchResultCallback& callback) = 0;
66 
67   virtual void RevokeHostQuota(const std::string& host) = 0;
68 
69  protected:
70   explicit BrowsingDataQuotaHelper(base::MessageLoopProxy* io_thread_);
71   virtual ~BrowsingDataQuotaHelper();
72 
73  private:
74   friend class base::DeleteHelper<BrowsingDataQuotaHelper>;
75   friend struct BrowsingDataQuotaHelperDeleter;
76   scoped_refptr<base::MessageLoopProxy> io_thread_;
77 
78   DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelper);
79 };
80 
81 #endif  // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_H_
82