15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_PROXY_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_PROXY_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/browser/quota/mock_quota_manager.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "storage/browser/quota/quota_client.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "storage/browser/quota/quota_manager_proxy.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "storage/common/quota/quota_types.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "url/gurl.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using storage::QuotaManagerProxy;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockQuotaManager;
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MockQuotaManagerProxy : public QuotaManagerProxy {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // It is ok to give NULL to |quota_manager|.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MockQuotaManagerProxy(MockQuotaManager* quota_manager,
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        base::SingleThreadTaskRunner* task_runner);
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RegisterClient(QuotaClient* client) OVERRIDE;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SimulateQuotaManagerDestroyed();
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We don't mock them.
31  virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
32  virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
33  virtual void SetUsageCacheEnabled(QuotaClient::ID client_id,
34                                    const GURL& origin,
35                                    StorageType type,
36                                    bool enabled) OVERRIDE {}
37  virtual void GetUsageAndQuota(
38      base::SequencedTaskRunner* original_task_runner,
39      const GURL& origin,
40      StorageType type,
41      const QuotaManager::GetUsageAndQuotaCallback& callback) OVERRIDE {}
42
43  // Validates the |client_id| and updates the internal access count
44  // which can be accessed via notify_storage_accessed_count().
45  // The also records the |origin| and |type| in last_notified_origin_ and
46  // last_notified_type_.
47  virtual void NotifyStorageAccessed(QuotaClient::ID client_id,
48                                     const GURL& origin,
49                                     StorageType type) OVERRIDE;
50
51  // Records the |origin|, |type| and |delta| as last_notified_origin_,
52  // last_notified_type_ and last_notified_delta_ respecitvely.
53  // If non-null MockQuotaManager is given to the constructor this also
54  // updates the manager's internal usage information.
55  virtual void NotifyStorageModified(QuotaClient::ID client_id,
56                                     const GURL& origin,
57                                     StorageType type,
58                                     int64 delta) OVERRIDE;
59
60  int notify_storage_accessed_count() const { return storage_accessed_count_; }
61  int notify_storage_modified_count() const { return storage_modified_count_; }
62  GURL last_notified_origin() const { return last_notified_origin_; }
63  StorageType last_notified_type() const { return last_notified_type_; }
64  int64 last_notified_delta() const { return last_notified_delta_; }
65
66 protected:
67  virtual ~MockQuotaManagerProxy();
68
69 private:
70  MockQuotaManager* mock_manager() const {
71    return static_cast<MockQuotaManager*>(quota_manager());
72  }
73
74  int storage_accessed_count_;
75  int storage_modified_count_;
76  GURL last_notified_origin_;
77  StorageType last_notified_type_;
78  int64 last_notified_delta_;
79
80  QuotaClient* registered_client_;
81
82  DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerProxy);
83};
84
85}  // namespace content
86
87#endif  // CONTENT_BROWSER_QUOTA_MOCK_QUOTA_MANAGER_PROXY_H_
88