15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch#include "content/browser/quota/mock_quota_manager_proxy.h"
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_loop.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/single_thread_task_runner.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "url/gurl.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)using storage::kStorageTypeUnknown;
12c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
13c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochnamespace content {
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)MockQuotaManagerProxy::MockQuotaManagerProxy(
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    MockQuotaManager* quota_manager,
175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::SingleThreadTaskRunner* task_runner)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : QuotaManagerProxy(quota_manager, task_runner),
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      storage_accessed_count_(0),
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      storage_modified_count_(0),
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      last_notified_type_(kStorageTypeUnknown),
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      last_notified_delta_(0),
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      registered_client_(NULL) {}
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MockQuotaManagerProxy::RegisterClient(QuotaClient* client) {
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(!registered_client_);
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registered_client_ = client;
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MockQuotaManagerProxy::SimulateQuotaManagerDestroyed() {
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (registered_client_) {
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // We cannot call this in the destructor as the client (indirectly)
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // holds a refptr of the proxy.
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    registered_client_->OnQuotaManagerDestroyed();
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    registered_client_ = NULL;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MockQuotaManagerProxy::NotifyStorageAccessed(
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    QuotaClient::ID client_id, const GURL& origin, StorageType type) {
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ++storage_accessed_count_;
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  last_notified_origin_ = origin;
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  last_notified_type_ = type;
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void MockQuotaManagerProxy::NotifyStorageModified(
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    QuotaClient::ID client_id, const GURL& origin,
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    StorageType type, int64 delta) {
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ++storage_modified_count_;
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  last_notified_origin_ = origin;
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  last_notified_type_ = type;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  last_notified_delta_ = delta;
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (mock_manager())
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    mock_manager()->UpdateUsage(origin, type, delta);
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)MockQuotaManagerProxy::~MockQuotaManagerProxy() {
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(!registered_client_);
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
61c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}  // namespace content
62