Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: chrome/browser/browsing_data/mock_browsing_data_cookie_helper.cc

Issue 459233002: Browsing Data Deletion: Style fixes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-apply comment tweaks Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h" 5 #include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/cookies/canonical_cookie.h" 8 #include "net/cookies/canonical_cookie.h"
9 #include "net/cookies/parsed_cookie.h" 9 #include "net/cookies/parsed_cookie.h"
10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper( 12 MockBrowsingDataCookieHelper::MockBrowsingDataCookieHelper(
12 net::URLRequestContextGetter* request_context_getter) 13 net::URLRequestContextGetter* request_context_getter)
13 : BrowsingDataCookieHelper(request_context_getter) { 14 : BrowsingDataCookieHelper(request_context_getter) {
14 } 15 }
15 16
16 MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() { 17 MockBrowsingDataCookieHelper::~MockBrowsingDataCookieHelper() {
17 } 18 }
18 19
19 void MockBrowsingDataCookieHelper::StartFetching( 20 void MockBrowsingDataCookieHelper::StartFetching(
20 const net::CookieMonster::GetCookieListCallback &callback) { 21 const net::CookieMonster::GetCookieListCallback &callback) {
22 ASSERT_FALSE(callback.is_null());
23 ASSERT_TRUE(callback_.is_null());
21 callback_ = callback; 24 callback_ = callback;
22 } 25 }
23 26
24 void MockBrowsingDataCookieHelper::DeleteCookie( 27 void MockBrowsingDataCookieHelper::DeleteCookie(
25 const net::CanonicalCookie& cookie) { 28 const net::CanonicalCookie& cookie) {
29 ASSERT_FALSE(callback_.is_null());
26 std::string key = cookie.Name() + "=" + cookie.Value(); 30 std::string key = cookie.Name() + "=" + cookie.Value();
27 CHECK(cookies_.find(key) != cookies_.end()); 31 ASSERT_TRUE(cookies_.find(key) != cookies_.end());
28 cookies_[key] = false; 32 cookies_[key] = false;
29 } 33 }
30 34
31 void MockBrowsingDataCookieHelper::AddCookieSamples( 35 void MockBrowsingDataCookieHelper::AddCookieSamples(
32 const GURL& url, const std::string& cookie_line) { 36 const GURL& url, const std::string& cookie_line) {
33 typedef net::CookieList::const_iterator cookie_iterator; 37 typedef net::CookieList::const_iterator cookie_iterator;
34 net::ParsedCookie pc(cookie_line); 38 net::ParsedCookie pc(cookie_line);
35 scoped_ptr<net::CanonicalCookie> cc(new net::CanonicalCookie(url, pc)); 39 scoped_ptr<net::CanonicalCookie> cc(new net::CanonicalCookie(url, pc));
36 40
37 if (cc.get()) { 41 if (cc.get()) {
38 for (cookie_iterator cookie = cookie_list_.begin(); 42 for (cookie_iterator cookie = cookie_list_.begin();
39 cookie != cookie_list_.end(); ++cookie) { 43 cookie != cookie_list_.end(); ++cookie) {
40 if (cookie->Name() == cc->Name() && 44 if (cookie->Name() == cc->Name() &&
41 cookie->Domain() == cc->Domain()&& 45 cookie->Domain() == cc->Domain() &&
42 cookie->Path() == cc->Path()) { 46 cookie->Path() == cc->Path()) {
43 return; 47 return;
44 } 48 }
45 } 49 }
46 cookie_list_.push_back(*cc); 50 cookie_list_.push_back(*cc);
47 cookies_[cookie_line] = true; 51 cookies_[cookie_line] = true;
48 } 52 }
49 } 53 }
50 54
51 void MockBrowsingDataCookieHelper::Notify() { 55 void MockBrowsingDataCookieHelper::Notify() {
52 if (!callback_.is_null()) 56 if (!callback_.is_null())
53 callback_.Run(cookie_list_); 57 callback_.Run(cookie_list_);
54 } 58 }
55 59
56 void MockBrowsingDataCookieHelper::Reset() { 60 void MockBrowsingDataCookieHelper::Reset() {
57 for (std::map<const std::string, bool>::iterator i = cookies_.begin(); 61 for (std::map<const std::string, bool>::iterator i = cookies_.begin();
58 i != cookies_.end(); ++i) 62 i != cookies_.end(); ++i)
59 i->second = true; 63 i->second = true;
60 } 64 }
61 65
62 bool MockBrowsingDataCookieHelper::AllDeleted() { 66 bool MockBrowsingDataCookieHelper::AllDeleted() {
63 for (std::map<const std::string, bool>::const_iterator i = cookies_.begin(); 67 for (std::map<const std::string, bool>::const_iterator i = cookies_.begin();
64 i != cookies_.end(); ++i) 68 i != cookies_.end(); ++i)
65 if (i->second) 69 if (i->second)
66 return false; 70 return false;
67 return true; 71 return true;
68 } 72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698