summaryrefslogtreecommitdiffstats
path: root/chrome/browser/mock_browsing_data_server_bound_cert_helper.cc
blob: 63b063fc7e8e2ecb44f67655331ddd980f4e1d87 (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
// Copyright (c) 2012 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_server_bound_cert_helper.h"

#include "base/logging.h"

MockBrowsingDataServerBoundCertHelper::MockBrowsingDataServerBoundCertHelper()
    : BrowsingDataServerBoundCertHelper() {}

MockBrowsingDataServerBoundCertHelper::
~MockBrowsingDataServerBoundCertHelper() {}

void MockBrowsingDataServerBoundCertHelper::StartFetching(
    const FetchResultCallback& callback) {
  callback_ = callback;
}

void MockBrowsingDataServerBoundCertHelper::DeleteServerBoundCert(
    const std::string& server_id) {
  CHECK(server_bound_certs_.find(server_id) != server_bound_certs_.end());
  server_bound_certs_[server_id] = false;
}

void MockBrowsingDataServerBoundCertHelper::AddServerBoundCertSample(
    const std::string& server_id) {
  DCHECK(server_bound_certs_.find(server_id) == server_bound_certs_.end());
  server_bound_cert_list_.push_back(
      net::ServerBoundCertStore::ServerBoundCert(
          server_id, net::CLIENT_CERT_ECDSA_SIGN,
          base::Time(), base::Time(), "key", "cert"));
  server_bound_certs_[server_id] = true;
}

void MockBrowsingDataServerBoundCertHelper::Notify() {
  net::ServerBoundCertStore::ServerBoundCertList cert_list;
  for (net::ServerBoundCertStore::ServerBoundCertList::iterator i =
       server_bound_cert_list_.begin();
       i != server_bound_cert_list_.end(); ++i) {
    if (server_bound_certs_[i->server_identifier()])
      cert_list.push_back(*i);
  }
  callback_.Run(cert_list);
}

void MockBrowsingDataServerBoundCertHelper::Reset() {
  for (std::map<const std::string, bool>::iterator i =
       server_bound_certs_.begin();
       i != server_bound_certs_.end(); ++i)
    i->second = true;
}

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