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

Side by Side Diff: chrome/browser/extensions/api/cookies/cookies_api.cc

Issue 1828683002: [Extensions] Convert APIs to use movable types [3] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Antony's Created 4 years, 9 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
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 // Implements the Chrome Extensions Cookies API. 5 // Implements the Chrome Extensions Cookies API.
6 6
7 #include "chrome/browser/extensions/api/cookies/cookies_api.h" 7 #include "chrome/browser/extensions/api/cookies/cookies_api.h"
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 } 137 }
138 138
139 void CookiesEventRouter::CookieChanged( 139 void CookiesEventRouter::CookieChanged(
140 Profile* profile, 140 Profile* profile,
141 ChromeCookieDetails* details) { 141 ChromeCookieDetails* details) {
142 scoped_ptr<base::ListValue> args(new base::ListValue()); 142 scoped_ptr<base::ListValue> args(new base::ListValue());
143 base::DictionaryValue* dict = new base::DictionaryValue(); 143 base::DictionaryValue* dict = new base::DictionaryValue();
144 dict->SetBoolean(keys::kRemovedKey, details->removed); 144 dict->SetBoolean(keys::kRemovedKey, details->removed);
145 145
146 scoped_ptr<cookies::Cookie> cookie(cookies_helpers::CreateCookie( 146 cookies::Cookie cookie = cookies_helpers::CreateCookie(
147 *details->cookie, cookies_helpers::GetStoreIdFromProfile(profile))); 147 *details->cookie, cookies_helpers::GetStoreIdFromProfile(profile));
148 dict->Set(keys::kCookieKey, cookie->ToValue().release()); 148 dict->Set(keys::kCookieKey, cookie.ToValue());
149 149
150 // Map the internal cause to an external string. 150 // Map the internal cause to an external string.
151 std::string cause; 151 std::string cause;
152 switch (details->cause) { 152 switch (details->cause) {
153 case net::CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT: 153 case net::CookieMonsterDelegate::CHANGE_COOKIE_EXPLICIT:
154 cause = keys::kExplicitChangeCause; 154 cause = keys::kExplicitChangeCause;
155 break; 155 break;
156 156
157 case net::CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE: 157 case net::CookieMonsterDelegate::CHANGE_COOKIE_OVERWRITE:
158 cause = keys::kOverwriteChangeCause; 158 cause = keys::kOverwriteChangeCause;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 void CookiesGetFunction::GetCookieOnIOThread() { 236 void CookiesGetFunction::GetCookieOnIOThread() {
237 DCHECK_CURRENTLY_ON(BrowserThread::IO); 237 DCHECK_CURRENTLY_ON(BrowserThread::IO);
238 net::CookieStore* cookie_store = 238 net::CookieStore* cookie_store =
239 store_browser_context_->GetURLRequestContext()->cookie_store(); 239 store_browser_context_->GetURLRequestContext()->cookie_store();
240 cookies_helpers::GetCookieListFromStore( 240 cookies_helpers::GetCookieListFromStore(
241 cookie_store, url_, 241 cookie_store, url_,
242 base::Bind(&CookiesGetFunction::GetCookieCallback, this)); 242 base::Bind(&CookiesGetFunction::GetCookieCallback, this));
243 } 243 }
244 244
245 void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) { 245 void CookiesGetFunction::GetCookieCallback(const net::CookieList& cookie_list) {
246 net::CookieList::const_iterator it; 246 for (const net::CanonicalCookie& cookie : cookie_list) {
247 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) {
248 // Return the first matching cookie. Relies on the fact that the 247 // Return the first matching cookie. Relies on the fact that the
249 // CookieMonster returns them in canonical order (longest path, then 248 // CookieMonster returns them in canonical order (longest path, then
250 // earliest creation time). 249 // earliest creation time).
251 if (it->Name() == parsed_args_->details.name) { 250 if (cookie.Name() == parsed_args_->details.name) {
252 scoped_ptr<cookies::Cookie> cookie( 251 cookies::Cookie api_cookie = cookies_helpers::CreateCookie(
253 cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); 252 cookie, *parsed_args_->details.store_id);
254 results_ = Get::Results::Create(*cookie); 253 results_ = Get::Results::Create(api_cookie);
255 break; 254 break;
256 } 255 }
257 } 256 }
258 257
259 // The cookie doesn't exist; return null. 258 // The cookie doesn't exist; return null.
260 if (it == cookie_list.end()) 259 if (!results_)
261 SetResult(base::Value::CreateNullValue()); 260 SetResult(base::Value::CreateNullValue());
262 261
263 bool rv = BrowserThread::PostTask( 262 bool rv = BrowserThread::PostTask(
264 BrowserThread::UI, FROM_HERE, 263 BrowserThread::UI, FROM_HERE,
265 base::Bind(&CookiesGetFunction::RespondOnUIThread, this)); 264 base::Bind(&CookiesGetFunction::RespondOnUIThread, this));
266 DCHECK(rv); 265 DCHECK(rv);
267 } 266 }
268 267
269 void CookiesGetFunction::RespondOnUIThread() { 268 void CookiesGetFunction::RespondOnUIThread() {
270 DCHECK_CURRENTLY_ON(BrowserThread::UI); 269 DCHECK_CURRENTLY_ON(BrowserThread::UI);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 net::CookieStore* cookie_store = 309 net::CookieStore* cookie_store =
311 store_browser_context_->GetURLRequestContext()->cookie_store(); 310 store_browser_context_->GetURLRequestContext()->cookie_store();
312 cookies_helpers::GetCookieListFromStore( 311 cookies_helpers::GetCookieListFromStore(
313 cookie_store, url_, 312 cookie_store, url_,
314 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this)); 313 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this));
315 } 314 }
316 315
317 void CookiesGetAllFunction::GetAllCookiesCallback( 316 void CookiesGetAllFunction::GetAllCookiesCallback(
318 const net::CookieList& cookie_list) { 317 const net::CookieList& cookie_list) {
319 if (extension()) { 318 if (extension()) {
320 std::vector<linked_ptr<cookies::Cookie>> match_vector; 319 std::vector<cookies::Cookie> match_vector;
321 cookies_helpers::AppendMatchingCookiesToVector( 320 cookies_helpers::AppendMatchingCookiesToVector(
322 cookie_list, url_, &parsed_args_->details, extension(), &match_vector); 321 cookie_list, url_, &parsed_args_->details, extension(), &match_vector);
323 322
324 results_ = GetAll::Results::Create(match_vector); 323 results_ = GetAll::Results::Create(match_vector);
325 } 324 }
326 bool rv = BrowserThread::PostTask( 325 bool rv = BrowserThread::PostTask(
327 BrowserThread::UI, FROM_HERE, 326 BrowserThread::UI, FROM_HERE,
328 base::Bind(&CookiesGetAllFunction::RespondOnUIThread, this)); 327 base::Bind(&CookiesGetAllFunction::RespondOnUIThread, this));
329 DCHECK(rv); 328 DCHECK(rv);
330 } 329 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 net::CookieStore* cookie_store = 428 net::CookieStore* cookie_store =
430 store_browser_context_->GetURLRequestContext()->cookie_store(); 429 store_browser_context_->GetURLRequestContext()->cookie_store();
431 success_ = set_cookie_result; 430 success_ = set_cookie_result;
432 cookies_helpers::GetCookieListFromStore( 431 cookies_helpers::GetCookieListFromStore(
433 cookie_store, url_, 432 cookie_store, url_,
434 base::Bind(&CookiesSetFunction::PullCookieCallback, this)); 433 base::Bind(&CookiesSetFunction::PullCookieCallback, this));
435 } 434 }
436 435
437 void CookiesSetFunction::PullCookieCallback( 436 void CookiesSetFunction::PullCookieCallback(
438 const net::CookieList& cookie_list) { 437 const net::CookieList& cookie_list) {
439 net::CookieList::const_iterator it; 438 for (const net::CanonicalCookie& cookie : cookie_list) {
440 for (it = cookie_list.begin(); it != cookie_list.end(); ++it) {
441 // Return the first matching cookie. Relies on the fact that the 439 // Return the first matching cookie. Relies on the fact that the
442 // CookieMonster returns them in canonical order (longest path, then 440 // CookieMonster returns them in canonical order (longest path, then
443 // earliest creation time). 441 // earliest creation time).
444 std::string name = 442 std::string name =
445 parsed_args_->details.name.get() ? *parsed_args_->details.name 443 parsed_args_->details.name.get() ? *parsed_args_->details.name
446 : std::string(); 444 : std::string();
447 if (it->Name() == name) { 445 if (cookie.Name() == name) {
448 scoped_ptr<cookies::Cookie> cookie( 446 cookies::Cookie api_cookie = cookies_helpers::CreateCookie(
449 cookies_helpers::CreateCookie(*it, *parsed_args_->details.store_id)); 447 cookie, *parsed_args_->details.store_id);
450 results_ = Set::Results::Create(*cookie); 448 results_ = Set::Results::Create(api_cookie);
451 break; 449 break;
452 } 450 }
453 } 451 }
454 452
455 bool rv = BrowserThread::PostTask( 453 bool rv = BrowserThread::PostTask(
456 BrowserThread::UI, FROM_HERE, 454 BrowserThread::UI, FROM_HERE,
457 base::Bind(&CookiesSetFunction::RespondOnUIThread, this)); 455 base::Bind(&CookiesSetFunction::RespondOnUIThread, this));
458 DCHECK(rv); 456 DCHECK(rv);
459 } 457 }
460 458
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 // whether the browser is regular or incognito. 550 // whether the browser is regular or incognito.
553 for (auto* browser : *BrowserList::GetInstance()) { 551 for (auto* browser : *BrowserList::GetInstance()) {
554 if (browser->profile() == original_profile) { 552 if (browser->profile() == original_profile) {
555 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get()); 553 cookies_helpers::AppendToTabIdList(browser, original_tab_ids.get());
556 } else if (incognito_tab_ids.get() && 554 } else if (incognito_tab_ids.get() &&
557 browser->profile() == incognito_profile) { 555 browser->profile() == incognito_profile) {
558 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get()); 556 cookies_helpers::AppendToTabIdList(browser, incognito_tab_ids.get());
559 } 557 }
560 } 558 }
561 // Return a list of all cookie stores with at least one open tab. 559 // Return a list of all cookie stores with at least one open tab.
562 std::vector<linked_ptr<cookies::CookieStore>> cookie_stores; 560 std::vector<cookies::CookieStore> cookie_stores;
563 if (original_tab_ids->GetSize() > 0) { 561 if (original_tab_ids->GetSize() > 0) {
564 cookie_stores.push_back(make_linked_ptr( 562 cookie_stores.push_back(cookies_helpers::CreateCookieStore(
565 cookies_helpers::CreateCookieStore( 563 original_profile, original_tab_ids.release()));
566 original_profile, original_tab_ids.release()).release()));
567 } 564 }
568 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 && 565 if (incognito_tab_ids.get() && incognito_tab_ids->GetSize() > 0 &&
569 incognito_profile) { 566 incognito_profile) {
570 cookie_stores.push_back(make_linked_ptr( 567 cookie_stores.push_back(cookies_helpers::CreateCookieStore(
571 cookies_helpers::CreateCookieStore( 568 incognito_profile, incognito_tab_ids.release()));
572 incognito_profile, incognito_tab_ids.release()).release()));
573 } 569 }
574 results_ = GetAllCookieStores::Results::Create(cookie_stores); 570 results_ = GetAllCookieStores::Results::Create(cookie_stores);
575 return true; 571 return true;
576 } 572 }
577 573
578 CookiesAPI::CookiesAPI(content::BrowserContext* context) 574 CookiesAPI::CookiesAPI(content::BrowserContext* context)
579 : browser_context_(context) { 575 : browser_context_(context) {
580 EventRouter::Get(browser_context_) 576 EventRouter::Get(browser_context_)
581 ->RegisterObserver(this, cookies::OnChanged::kEventName); 577 ->RegisterObserver(this, cookies::OnChanged::kEventName);
582 } 578 }
(...skipping 12 matching lines...) Expand all
595 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { 591 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() {
596 return g_factory.Pointer(); 592 return g_factory.Pointer();
597 } 593 }
598 594
599 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) { 595 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) {
600 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); 596 cookies_event_router_.reset(new CookiesEventRouter(browser_context_));
601 EventRouter::Get(browser_context_)->UnregisterObserver(this); 597 EventRouter::Get(browser_context_)->UnregisterObserver(this);
602 } 598 }
603 599
604 } // namespace extensions 600 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698