• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
MockBrowsingDataIndexedDBHelper(Profile * profile)10 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper(
11     Profile* profile)
12     : profile_(profile) {
13 }
14 
~MockBrowsingDataIndexedDBHelper()15 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() {
16 }
17 
StartFetching(Callback1<const std::vector<IndexedDBInfo> &>::Type * callback)18 void MockBrowsingDataIndexedDBHelper::StartFetching(
19     Callback1<const std::vector<IndexedDBInfo>& >::Type* callback) {
20   callback_.reset(callback);
21 }
22 
CancelNotification()23 void MockBrowsingDataIndexedDBHelper::CancelNotification() {
24   callback_.reset(NULL);
25 }
26 
DeleteIndexedDBFile(const FilePath & file_path)27 void 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 
AddIndexedDBSamples()34 void 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 
Notify()47 void MockBrowsingDataIndexedDBHelper::Notify() {
48   CHECK(callback_.get());
49   callback_->Run(response_);
50 }
51 
Reset()52 void 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 
AllDeleted()58 bool 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