Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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_cookie_helper.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/time.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "content/browser/browser_thread.h" | |
| 13 #include "googleurl/src/gurl.h" | |
| 14 #include "net/url_request/url_request_context.h" | |
| 15 #include "net/url_request/url_request_context_getter.h" | |
| 16 | |
| 17 using base::Time; | |
| 18 | |
| 19 BrowsingDataCookieHelper::BrowsingDataCookieHelper(Profile* profile) | |
| 20 : is_fetching_(false), | |
| 21 profile_(profile), | |
| 22 request_context_getter_(profile->GetRequestContext()) { | |
| 23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 24 } | |
| 25 | |
| 26 BrowsingDataCookieHelper::~BrowsingDataCookieHelper() { | |
| 27 } | |
| 28 | |
| 29 void BrowsingDataCookieHelper::StartFetching( | |
| 30 const base::Callback<void(const net::CookieList& cookies)>& callback) { | |
| 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 32 DCHECK(!is_fetching_); | |
| 33 DCHECK(!callback.is_null()); | |
| 34 DCHECK(completion_callback_.is_null()); | |
| 35 is_fetching_ = true; | |
| 36 completion_callback_ = callback; | |
| 37 BrowserThread::PostTask( | |
| 38 BrowserThread::IO, FROM_HERE, | |
| 39 base::Bind(&BrowsingDataCookieHelper::FetchCookiesOnIOThread, this)); | |
| 40 } | |
| 41 | |
| 42 void BrowsingDataCookieHelper::CancelNotification() { | |
| 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 44 completion_callback_.Reset(); | |
| 45 } | |
| 46 | |
| 47 void BrowsingDataCookieHelper::DeleteCookie( | |
| 48 const net::CookieMonster::CanonicalCookie& cookie) { | |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 50 BrowserThread::PostTask( | |
| 51 BrowserThread::IO, FROM_HERE, | |
| 52 base::Bind(&BrowsingDataCookieHelper::DeleteCookieOnIOThread, | |
| 53 this, cookie)); | |
| 54 } | |
| 55 | |
| 56 void BrowsingDataCookieHelper::FetchCookiesOnIOThread() { | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 58 scoped_refptr<net::CookieMonster> cookie_monster = | |
| 59 request_context_getter_->GetURLRequestContext()-> | |
| 60 cookie_store()->GetCookieMonster(); | |
| 61 if (cookie_monster) { | |
| 62 cookie_monster->GetAllCookiesAsync( | |
| 63 base::Bind(&BrowsingDataCookieHelper::OnFetchComplete, this)); | |
| 64 } else { | |
| 65 OnFetchComplete(net::CookieList()); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void BrowsingDataCookieHelper::OnFetchComplete(const net::CookieList& cookies) { | |
| 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 71 BrowserThread::PostTask( | |
| 72 BrowserThread::UI, FROM_HERE, | |
| 73 base::Bind(&BrowsingDataCookieHelper::NotifyInUIThread, this, cookies)); | |
| 74 } | |
| 75 | |
| 76 void BrowsingDataCookieHelper::NotifyInUIThread( | |
| 77 const net::CookieList& cookies) { | |
| 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 79 DCHECK(is_fetching_); | |
| 80 is_fetching_ = false; | |
| 81 if (!completion_callback_.is_null()) { | |
| 82 completion_callback_.Run(cookies); | |
| 83 completion_callback_.Reset(); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void BrowsingDataCookieHelper::DeleteCookieOnIOThread( | |
| 88 const net::CookieMonster::CanonicalCookie& cookie) { | |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 90 scoped_refptr<net::CookieMonster> cookie_monster = | |
| 91 request_context_getter_->GetURLRequestContext()-> | |
| 92 cookie_store()->GetCookieMonster(); | |
| 93 if (cookie_monster) { | |
| 94 cookie_monster->DeleteCanonicalCookieAsync( | |
| 95 cookie, net::CookieMonster::DeleteCookieCallback()); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 CannedBrowsingDataCookieHelper::CannedBrowsingDataCookieHelper( | |
| 100 Profile* profile) | |
| 101 : BrowsingDataCookieHelper(profile), | |
| 102 profile_(profile) { | |
| 103 } | |
| 104 | |
| 105 CannedBrowsingDataCookieHelper::~CannedBrowsingDataCookieHelper() {} | |
| 106 | |
| 107 CannedBrowsingDataCookieHelper* CannedBrowsingDataCookieHelper::Clone() { | |
| 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 109 CannedBrowsingDataCookieHelper* clone = | |
| 110 new CannedBrowsingDataCookieHelper(profile_); | |
| 111 | |
| 112 clone->cookie_list_ = cookie_list_; | |
| 113 return clone; | |
| 114 } | |
| 115 | |
| 116 void CannedBrowsingDataCookieHelper::AddReadCookie( | |
| 117 const GURL& url, | |
| 118 const net::CookieList& cookie_list) { | |
| 119 typedef net::CookieList::const_iterator cookie_iterator; | |
| 120 for (cookie_iterator add_cookie = cookie_list.begin(); | |
| 121 add_cookie != cookie_list.end(); ++add_cookie) { | |
| 122 DeleteMetchingCookie(*add_cookie); | |
| 123 cookie_list_.push_back(*add_cookie); | |
| 124 } | |
| 125 } | |
| 126 | |
| 127 void CannedBrowsingDataCookieHelper::AddChangeCookie( | |
| 128 const GURL& url, | |
| 129 const std::string& cookie_line, | |
| 130 const net::CookieOptions& options) { | |
| 131 typedef net::CookieList::iterator cookie_iterator; | |
| 132 | |
| 133 net::CookieMonster::ParsedCookie pc(cookie_line); | |
| 134 if (options.exclude_httponly() && pc.IsHttpOnly()) { | |
|
jochen (gone - plz use gerrit)
2011/07/27 07:17:32
How can this happen? I don't think there's a code
ycxiao
2011/07/27 14:29:46
The code path from URLRequestHttpJob set include h
erikwright (departed)
2011/07/27 14:47:24
Yancheng: note that the code path you referred to
ycxiao
2011/07/27 16:19:59
Yes, the render message filter set exclude_http_on
| |
| 135 return; | |
| 136 } | |
| 137 | |
| 138 scoped_ptr<net::CookieMonster::CanonicalCookie> cc; | |
| 139 cc.reset(new net::CookieMonster::CanonicalCookie(url, pc)); | |
| 140 if (cc->Domain() == "") { | |
|
jochen (gone - plz use gerrit)
2011/07/27 07:17:32
when does this happen?
ycxiao
2011/07/27 14:29:46
The CookieStore method SetCookieWithOptions may fa
erikwright (departed)
2011/07/27 14:47:24
Yancheng, can you clarify at which point GetCookie
ycxiao
2011/07/27 16:19:59
Sorry. The GetCookieDomainWithString is called by
| |
| 141 return; | |
| 142 } | |
| 143 | |
| 144 if (cc.get()) { | |
| 145 for (cookie_iterator cookie = cookie_list_.begin(); | |
|
jochen (gone - plz use gerrit)
2011/07/27 07:17:32
deletematchingcookie(cc)?
ycxiao
2011/07/27 14:29:46
It is also for the consistent behaviours as Cookie
erikwright (departed)
2011/07/27 14:47:24
Yes, but since it is identical to DeleteMatchingCo
ycxiao
2011/07/27 16:19:59
Done.
| |
| 146 cookie != cookie_list_.end(); ++cookie) { | |
| 147 if (cookie->Name() == cc->Name() && | |
| 148 cookie->Domain() == cc->Domain()&& | |
| 149 cookie->Path() == cc->Path()) { | |
| 150 cookie_list_.erase(cookie); | |
| 151 break; | |
| 152 } | |
| 153 } | |
| 154 cookie_list_.push_back(*cc); | |
| 155 } | |
| 156 } | |
| 157 | |
| 158 void CannedBrowsingDataCookieHelper::Reset() { | |
| 159 cookie_list_.clear(); | |
| 160 } | |
| 161 | |
| 162 bool CannedBrowsingDataCookieHelper::empty() const { | |
| 163 return cookie_list_.empty(); | |
| 164 } | |
| 165 | |
| 166 void CannedBrowsingDataCookieHelper::StartFetching( | |
| 167 const net::CookieMonster::GetCookieListCallback& callback) { | |
| 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 169 if (!callback.is_null()) | |
| 170 callback.Run(cookie_list_); | |
| 171 } | |
| 172 | |
| 173 void CannedBrowsingDataCookieHelper::CancelNotification() {} | |
| 174 | |
| 175 bool CannedBrowsingDataCookieHelper::DeleteMetchingCookie( | |
| 176 const net::CookieMonster::CanonicalCookie& add_cookie) { | |
| 177 typedef net::CookieList::iterator cookie_iterator; | |
| 178 for (cookie_iterator cookie = cookie_list_.begin(); | |
| 179 cookie != cookie_list_.end(); ++cookie) { | |
| 180 if (cookie->Name() == add_cookie.Name() && | |
| 181 cookie->Domain() == add_cookie.Domain()&& | |
| 182 cookie->Path() == add_cookie.Path()) { | |
| 183 cookie_list_.erase(cookie); | |
| 184 return true; | |
| 185 } | |
| 186 } | |
| 187 return false; | |
| 188 } | |
| OLD | NEW |