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_server_bound_cert_helper.h"
6
7#include "base/logging.h"
8
9MockBrowsingDataServerBoundCertHelper::MockBrowsingDataServerBoundCertHelper()
10    : BrowsingDataServerBoundCertHelper() {}
11
12MockBrowsingDataServerBoundCertHelper::
13~MockBrowsingDataServerBoundCertHelper() {}
14
15void MockBrowsingDataServerBoundCertHelper::StartFetching(
16    const FetchResultCallback& callback) {
17  callback_ = callback;
18}
19
20void MockBrowsingDataServerBoundCertHelper::DeleteServerBoundCert(
21    const std::string& server_id) {
22  CHECK(server_bound_certs_.find(server_id) != server_bound_certs_.end());
23  server_bound_certs_[server_id] = false;
24}
25
26void MockBrowsingDataServerBoundCertHelper::AddServerBoundCertSample(
27    const std::string& server_id) {
28  DCHECK(server_bound_certs_.find(server_id) == server_bound_certs_.end());
29  server_bound_cert_list_.push_back(
30      net::ServerBoundCertStore::ServerBoundCert(
31          server_id, base::Time(), base::Time(), "key", "cert"));
32  server_bound_certs_[server_id] = true;
33}
34
35void MockBrowsingDataServerBoundCertHelper::Notify() {
36  net::ServerBoundCertStore::ServerBoundCertList cert_list;
37  for (net::ServerBoundCertStore::ServerBoundCertList::iterator i =
38       server_bound_cert_list_.begin();
39       i != server_bound_cert_list_.end(); ++i) {
40    if (server_bound_certs_[i->server_identifier()])
41      cert_list.push_back(*i);
42  }
43  callback_.Run(cert_list);
44}
45
46void MockBrowsingDataServerBoundCertHelper::Reset() {
47  for (std::map<const std::string, bool>::iterator i =
48       server_bound_certs_.begin();
49       i != server_bound_certs_.end(); ++i)
50    i->second = true;
51}
52
53bool MockBrowsingDataServerBoundCertHelper::AllDeleted() {
54  for (std::map<const std::string, bool>::const_iterator i =
55       server_bound_certs_.begin();
56       i != server_bound_certs_.end(); ++i)
57    if (i->second)
58      return false;
59  return true;
60}
61