summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browsing_data_quota_helper_impl.h
blob: 5e857a7e8e2cc244ed1ccfa8c614dd343aad909f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
#define CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
#pragma once

#include <map>
#include <set>
#include <string>
#include <utility>

#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "chrome/browser/browsing_data_quota_helper.h"
#include "content/public/browser/browser_thread.h"
#include "webkit/quota/quota_types.h"

namespace quota {
class QuotaManager;
}

// Implementation of BrowsingDataQuotaHelper.  Since a client of
// BrowsingDataQuotaHelper should live in UI thread and QuotaManager lives in
// IO thread, we have to communicate over thread using PostTask.
class BrowsingDataQuotaHelperImpl : public BrowsingDataQuotaHelper {
 public:
  virtual void StartFetching(const FetchResultCallback& callback) OVERRIDE;
  virtual void RevokeHostQuota(const std::string& host) OVERRIDE;

 private:
  BrowsingDataQuotaHelperImpl(base::MessageLoopProxy* ui_thread,
                              base::MessageLoopProxy* io_thread,
                              quota::QuotaManager* quota_manager);
  virtual ~BrowsingDataQuotaHelperImpl();

  void FetchQuotaInfo();

  // Callback function for GetOriginModifiedSince.
  void GotOrigins(const std::set<GURL>& origins, quota::StorageType type);

  void ProcessPendingHosts();
  void GetHostUsage(const std::string& host, quota::StorageType type);

  // Callback function for GetHostUsage.
  void GotHostUsage(const std::string& host,
                    quota::StorageType type,
                    int64 usage);

  void OnComplete();
  void DidRevokeHostQuota(quota::QuotaStatusCode status,
                          const std::string& host,
                          quota::StorageType type,
                          int64 quota);

  scoped_refptr<quota::QuotaManager> quota_manager_;
  FetchResultCallback callback_;

  typedef std::set<std::pair<std::string, quota::StorageType> > PendingHosts;
  PendingHosts pending_hosts_;
  std::map<std::string, QuotaInfo> quota_info_;

  bool is_fetching_;

  scoped_refptr<base::MessageLoopProxy> ui_thread_;
  scoped_refptr<base::MessageLoopProxy> io_thread_;
  base::WeakPtrFactory<BrowsingDataQuotaHelperImpl> weak_factory_;

  friend class BrowsingDataQuotaHelper;
  friend class BrowsingDataQuotaHelperTest;

  DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperImpl);
};

#endif  // CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_