summaryrefslogtreecommitdiffstats
path: root/chrome/browser/mock_browsing_data_local_storage_helper.cc
blob: 0b80d375f84be47e6bafe405eafc26d6e8327243 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/mock_browsing_data_local_storage_helper.h"

#include "base/callback.h"
#include "base/logging.h"

MockBrowsingDataLocalStorageHelper::MockBrowsingDataLocalStorageHelper(
  Profile* profile)
  : BrowsingDataLocalStorageHelper(profile),
    profile_(profile) {
}

MockBrowsingDataLocalStorageHelper::~MockBrowsingDataLocalStorageHelper() {
}

void MockBrowsingDataLocalStorageHelper::StartFetching(
    Callback1<const std::vector<LocalStorageInfo>& >::Type* callback) {
  callback_.reset(callback);
}

void MockBrowsingDataLocalStorageHelper::CancelNotification() {
  callback_.reset(NULL);
}

void MockBrowsingDataLocalStorageHelper::DeleteLocalStorageFile(
    const FilePath& file_path) {
  CHECK(files_.find(file_path.value()) != files_.end());
  last_deleted_file_ = file_path;
  files_[file_path.value()] = false;
}

void MockBrowsingDataLocalStorageHelper::AddLocalStorageSamples() {
  response_.push_back(
      BrowsingDataLocalStorageHelper::LocalStorageInfo(
          "http", "host1", 1, "db1", "http://host1:1/",
          FilePath(FILE_PATH_LITERAL("file1")), 1, base::Time()));
  files_[FILE_PATH_LITERAL("file1")] = true;
  response_.push_back(
      BrowsingDataLocalStorageHelper::LocalStorageInfo(
          "http", "host2", 2, "db2", "http://host2:2/",
          FilePath(FILE_PATH_LITERAL("file2")), 2, base::Time()));
  files_[FILE_PATH_LITERAL("file2")] = true;
}

void MockBrowsingDataLocalStorageHelper::Notify() {
  CHECK(callback_.get());
  callback_->Run(response_);
}

void MockBrowsingDataLocalStorageHelper::Reset() {
  for (std::map<const FilePath::StringType, bool>::iterator i = files_.begin();
       i != files_.end(); ++i)
    i->second = true;
}

bool MockBrowsingDataLocalStorageHelper::AllDeleted() {
  for (std::map<const FilePath::StringType, bool>::const_iterator i =
       files_.begin(); i != files_.end(); ++i)
    if (i->second)
      return false;
  return true;
}