mock_quota_manager_proxy.cc revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Copyright 2014 The Chromium Authors. All rights reserved.
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Use of this source code is governed by a BSD-style license that can be
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// found in the LICENSE file.
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "content/browser/quota/mock_quota_manager_proxy.h"
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "base/message_loop/message_loop.h"
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "base/single_thread_task_runner.h"
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "url/gurl.h"
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryusing storage::kStorageTypeUnknown;
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace content {
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
153c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMockQuotaManagerProxy::MockQuotaManagerProxy(
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    MockQuotaManager* quota_manager,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    base::SingleThreadTaskRunner* task_runner)
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    : QuotaManagerProxy(quota_manager, task_runner),
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      storage_accessed_count_(0),
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      storage_modified_count_(0),
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      last_notified_type_(kStorageTypeUnknown),
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      last_notified_delta_(0),
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry      registered_client_(NULL) {}
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MockQuotaManagerProxy::RegisterClient(QuotaClient* client) {
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DCHECK(!registered_client_);
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  registered_client_ = client;
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MockQuotaManagerProxy::SimulateQuotaManagerDestroyed() {
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (registered_client_) {
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // We cannot call this in the destructor as the client (indirectly)
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    // holds a refptr of the proxy.
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    registered_client_->OnQuotaManagerDestroyed();
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    registered_client_ = NULL;
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  }
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MockQuotaManagerProxy::NotifyStorageAccessed(
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    QuotaClient::ID client_id, const GURL& origin, StorageType type) {
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ++storage_accessed_count_;
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  last_notified_origin_ = origin;
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  last_notified_type_ = type;
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid MockQuotaManagerProxy::NotifyStorageModified(
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    QuotaClient::ID client_id, const GURL& origin,
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    StorageType type, int64 delta) {
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  ++storage_modified_count_;
503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  last_notified_origin_ = origin;
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  last_notified_type_ = type;
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  last_notified_delta_ = delta;
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  if (mock_manager())
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry    mock_manager()->UpdateUsage(origin, type, delta);
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
573c827367444ee418f129b2c238299f49d3264554Jarkko PoyryMockQuotaManagerProxy::~MockQuotaManagerProxy() {
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry  DCHECK(!registered_client_);
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}  // namespace content
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry