1// Copyright (c) 2012 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#include "chrome/browser/browsing_data/mock_browsing_data_indexed_db_helper.h"
6
7#include "base/callback.h"
8#include "base/logging.h"
9
10MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper() {
11}
12
13MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() {
14}
15
16void MockBrowsingDataIndexedDBHelper::StartFetching(
17    const base::Callback<void(const std::list<content::IndexedDBInfo>&)>&
18    callback) {
19  callback_ = callback;
20}
21
22void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB(
23    const GURL& origin) {
24  CHECK(origins_.find(origin) != origins_.end());
25  origins_[origin] = false;
26}
27
28void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() {
29  const GURL kOrigin1("http://idbhost1:1/");
30  const GURL kOrigin2("http://idbhost2:2/");
31  content::IndexedDBInfo info1(kOrigin1, 1, base::Time(), base::FilePath(), 0);
32  response_.push_back(info1);
33  origins_[kOrigin1] = true;
34  content::IndexedDBInfo info2(kOrigin2, 2, base::Time(), base::FilePath(), 0);
35  response_.push_back(info2);
36  origins_[kOrigin2] = true;
37}
38
39void MockBrowsingDataIndexedDBHelper::Notify() {
40  CHECK_EQ(false, callback_.is_null());
41  callback_.Run(response_);
42}
43
44void MockBrowsingDataIndexedDBHelper::Reset() {
45  for (std::map<GURL, bool>::iterator i = origins_.begin();
46       i != origins_.end(); ++i)
47    i->second = true;
48}
49
50bool MockBrowsingDataIndexedDBHelper::AllDeleted() {
51  for (std::map<GURL, bool>::const_iterator i = origins_.begin();
52       i != origins_.end(); ++i)
53    if (i->second)
54      return false;
55  return true;
56}
57