summaryrefslogtreecommitdiffstats
path: root/chrome/browser/mock_browsing_data_cookie_helper.cc
blob: 2d85cabf74ecb9a0fcb3eede0e8308763e55d456 (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
66
67
68
69
// Copyright (c) 2011 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_cookie_helper.h"

MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(Profile* profile)
    : BrowsingDataCookieHelper(profile),
      profile_(profile) {
}

MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() {
}

void MockBrowsingDataCookieHelper::StartFetching(
    const net::CookieMonster::GetCookieListCallback &callback) {
  callback_ = callback;
}

void MockBrowsingDataCookieHelper::CancelNotification() {
  callback_.Reset();
}

void MockBrowsingDataCookieHelper::DeleteCookie(
    const net::CookieMonster::CanonicalCookie& cookie) {
  std::string key = cookie.Name() + "=" + cookie.Value();
  CHECK(cookies_.find(key) != cookies_.end());
  cookies_[key] = false;
}

void MockBrowsingDataCookieHelper::AddCookieSamples(
    const GURL& url, const std::string& cookie_line) {
  typedef net::CookieList::const_iterator cookie_iterator;
  net::CookieMonster::ParsedCookie pc(cookie_line);
  scoped_ptr<net::CookieMonster::CanonicalCookie> cc;
  cc.reset(new net::CookieMonster::CanonicalCookie(url, pc));

  if (cc.get()) {
    for (cookie_iterator cookie = cookie_list_.begin();
        cookie != cookie_list_.end(); ++cookie) {
      if (cookie->Name() == cc->Name() &&
          cookie->Domain() == cc->Domain()&&
          cookie->Path() == cc->Path()) {
        return;
      }
    }
    cookie_list_.push_back(*cc);
    cookies_[cookie_line] = true;
  }
}

void MockBrowsingDataCookieHelper::Notify() {
  if (!callback_.is_null())
    callback_.Run(cookie_list_);
}

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

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