Home | History | Annotate | Download | only in quota
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef WEBKIT_BROWSER_QUOTA_QUOTA_CLIENT_H_
      6 #define WEBKIT_BROWSER_QUOTA_QUOTA_CLIENT_H_
      7 
      8 #include <list>
      9 #include <set>
     10 #include <string>
     11 
     12 #include "base/callback.h"
     13 #include "url/gurl.h"
     14 #include "webkit/browser/webkit_storage_browser_export.h"
     15 #include "webkit/common/quota/quota_types.h"
     16 
     17 namespace quota {
     18 
     19 // An abstract interface for quota manager clients.
     20 // Each storage API must provide an implementation of this interface and
     21 // register it to the quota manager.
     22 // All the methods are assumed to be called on the IO thread in the browser.
     23 class WEBKIT_STORAGE_BROWSER_EXPORT QuotaClient {
     24  public:
     25   typedef base::Callback<void(int64 usage)> GetUsageCallback;
     26   typedef base::Callback<void(const std::set<GURL>& origins)>
     27       GetOriginsCallback;
     28   typedef base::Callback<void(QuotaStatusCode status)> DeletionCallback;
     29 
     30   virtual ~QuotaClient() {}
     31 
     32   enum ID {
     33     kUnknown = 1 << 0,
     34     kFileSystem = 1 << 1,
     35     kDatabase = 1 << 2,
     36     kAppcache = 1 << 3,
     37     kIndexedDatabase = 1 << 4,
     38     kAllClientsMask = -1,
     39   };
     40 
     41   virtual ID id() const = 0;
     42 
     43   // Called when the quota manager is destroyed.
     44   virtual void OnQuotaManagerDestroyed() = 0;
     45 
     46   // Called by the QuotaManager.
     47   // Gets the amount of data stored in the storage specified by
     48   // |origin_url| and |type|.
     49   // Note it is safe to fire the callback after the QuotaClient is destructed.
     50   virtual void GetOriginUsage(const GURL& origin_url,
     51                               StorageType type,
     52                               const GetUsageCallback& callback) = 0;
     53 
     54   // Called by the QuotaManager.
     55   // Returns a list of origins that has data in the |type| storage.
     56   // Note it is safe to fire the callback after the QuotaClient is destructed.
     57   virtual void GetOriginsForType(StorageType type,
     58                                  const GetOriginsCallback& callback) = 0;
     59 
     60   // Called by the QuotaManager.
     61   // Returns a list of origins that match the |host|.
     62   // Note it is safe to fire the callback after the QuotaClient is destructed.
     63   virtual void GetOriginsForHost(StorageType type,
     64                                  const std::string& host,
     65                                  const GetOriginsCallback& callback) = 0;
     66 
     67   // Called by the QuotaManager.
     68   // Note it is safe to fire the callback after the QuotaClient is destructed.
     69   virtual void DeleteOriginData(const GURL& origin,
     70                                 StorageType type,
     71                                 const DeletionCallback& callback) = 0;
     72 };
     73 
     74 // TODO(dmikurube): Replace it to std::vector for efficiency.
     75 typedef std::list<QuotaClient*> QuotaClientList;
     76 
     77 }  // namespace quota
     78 
     79 #endif  // WEBKIT_BROWSER_QUOTA_QUOTA_CLIENT_H_
     80