OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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_cookie_helper.h" | |
6 | |
7 MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(Profile* profile) | |
8 : BrowsingDataCookieHelper(profile), | |
9 profile_(profile) { | |
10 } | |
11 | |
12 MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() { | |
13 } | |
14 | |
15 void MockBrowsingDataCookieHelper::StartFetching( | |
16 const net::CookieMonster::GetCookieListCallback &callback) { | |
17 callback_ = callback; | |
18 } | |
19 | |
20 void MockBrowsingDataCookieHelper::CancelNotification() { | |
21 callback_.Reset(); | |
22 } | |
23 | |
24 void MockBrowsingDataCookieHelper::DeleteCookie( | |
25 const net::CookieMonster::CanonicalCookie& cookie) { | |
26 std::string key = cookie.Name() + "=" + cookie.Value(); | |
27 CHECK(cookies_.find(key) != cookies_.end()); | |
28 cookies_[key] = false; | |
29 } | |
30 | |
31 void MockBrowsingDataCookieHelper::AddCookieSamples( | |
32 const GURL& url, const std::string& cookie_line) { | |
33 typedef net::CookieList::const_iterator cookie_iterator; | |
34 net::CookieMonster::ParsedCookie pc(cookie_line); | |
35 scoped_ptr<net::CookieMonster::CanonicalCookie> cc; | |
36 cc.reset(new net::CookieMonster::CanonicalCookie(url, pc)); | |
37 | |
38 if (cc.get()) { | |
39 for (cookie_iterator cookie = cookie_list_.begin(); | |
40 cookie != cookie_list_.end(); ++cookie) { | |
41 if (cookie->Name() == cc->Name() && | |
42 cookie->Domain() == cc->Domain()&& | |
43 cookie->Path() == cc->Path()) { | |
44 return; | |
45 } | |
46 } | |
47 cookie_list_.push_back(*cc); | |
48 cookies_[cookie_line] = true; | |
49 } | |
50 } | |
51 | |
52 void MockBrowsingDataCookieHelper::Notify() { | |
53 if (!callback_.is_null()) | |
54 callback_.Run(cookie_list_); | |
55 } | |
56 | |
57 void MockBrowsingDataCookieHelper::Reset() { | |
58 for (std::map<const std::string, bool>::iterator i = cookies_.begin(); | |
59 i != cookies_.end(); ++i) | |
60 i->second = true; | |
61 } | |
62 | |
63 bool MockBrowsingDataCookieHelper::AllDeleted() { | |
64 for (std::map<const std::string, bool>::const_iterator i = cookies_.begin(); | |
65 i != cookies_.end(); ++i) | |
66 if (i->second) | |
67 return false; | |
68 return true; | |
69 } | |
OLD | NEW |