1// Copyright (c) 2010 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/mock_browsing_data_indexed_db_helper.h"
6
7#include "base/callback.h"
8#include "base/logging.h"
9
10MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper(
11    Profile* profile)
12    : profile_(profile) {
13}
14
15MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() {
16}
17
18void MockBrowsingDataIndexedDBHelper::StartFetching(
19    Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) {
20  callback_.reset(callback);
21}
22
23void MockBrowsingDataIndexedDBHelper::CancelNotification() {
24  callback_.reset(NULL);
25}
26
27void MockBrowsingDataIndexedDBHelper::DeleteIndexedDBFile(
28    const FilePath& file_path) {
29  CHECK(files_.find(file_path.value()) != files_.end());
30  last_deleted_file_ = file_path;
31  files_[file_path.value()] = false;
32}
33
34void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() {
35  response_.push_back(
36      BrowsingDataIndexedDBHelper::IndexedDBInfo(
37          "http", "idbhost1", 1, "idb1", "http://idbhost1:1/",
38          FilePath(FILE_PATH_LITERAL("file1")), 1, base::Time()));
39  files_[FILE_PATH_LITERAL("file1")] = true;
40  response_.push_back(
41      BrowsingDataIndexedDBHelper::IndexedDBInfo(
42          "http", "idbhost2", 2, "idb2", "http://idbhost2:2/",
43          FilePath(FILE_PATH_LITERAL("file2")), 2, base::Time()));
44  files_[FILE_PATH_LITERAL("file2")] = true;
45}
46
47void MockBrowsingDataIndexedDBHelper::Notify() {
48  CHECK(callback_.get());
49  callback_->Run(response_);
50}
51
52void MockBrowsingDataIndexedDBHelper::Reset() {
53  for (std::map<const FilePath::StringType, bool>::iterator i = files_.begin();
54       i != files_.end(); ++i)
55    i->second = true;
56}
57
58bool MockBrowsingDataIndexedDBHelper::AllDeleted() {
59  for (std::map<const FilePath::StringType, bool>::const_iterator i =
60       files_.begin(); i != files_.end(); ++i)
61    if (i->second)
62      return false;
63  return true;
64}
65