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_database_helper.h"
6
7#include "base/callback.h"
8
9MockBrowsingDataDatabaseHelper::MockBrowsingDataDatabaseHelper(
10    Profile* profile)
11    : BrowsingDataDatabaseHelper(profile) {
12}
13
14MockBrowsingDataDatabaseHelper::~MockBrowsingDataDatabaseHelper() {
15}
16
17void MockBrowsingDataDatabaseHelper::StartFetching(
18    const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) {
19  callback_ = callback;
20}
21
22void MockBrowsingDataDatabaseHelper::DeleteDatabase(
23    const std::string& origin,
24    const std::string& name) {
25  std::string key = origin + ":" + name;
26  CHECK(databases_.find(key) != databases_.end());
27  last_deleted_origin_ = origin;
28  last_deleted_db_ = name;
29  databases_[key] = false;
30}
31
32void MockBrowsingDataDatabaseHelper::AddDatabaseSamples() {
33  webkit_database::DatabaseIdentifier id1 =
34      webkit_database::DatabaseIdentifier::Parse("http_gdbhost1_1");
35  response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo(
36      id1, "db1", "description 1", 1, base::Time()));
37  databases_["http_gdbhost1_1:db1"] = true;
38  webkit_database::DatabaseIdentifier id2 =
39      webkit_database::DatabaseIdentifier::Parse("http_gdbhost2_2");
40  response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo(
41      id2, "db2", "description 2", 2, base::Time()));
42  databases_["http_gdbhost2_2:db2"] = true;
43}
44
45void MockBrowsingDataDatabaseHelper::Notify() {
46  CHECK_EQ(false, callback_.is_null());
47  callback_.Run(response_);
48}
49
50void MockBrowsingDataDatabaseHelper::Reset() {
51  for (std::map<const std::string, bool>::iterator i = databases_.begin();
52       i != databases_.end(); ++i)
53    i->second = true;
54}
55
56bool MockBrowsingDataDatabaseHelper::AllDeleted() {
57  for (std::map<const std::string, bool>::const_iterator i = databases_.begin();
58       i != databases_.end(); ++i)
59    if (i->second)
60      return false;
61  return true;
62}
63