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

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

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 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 <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (!ParseStoreContext(this, &store_id, &store_context)) 221 if (!ParseStoreContext(this, &store_id, &store_context))
222 return false; 222 return false;
223 store_browser_context_ = store_context; 223 store_browser_context_ = store_context;
224 if (!parsed_args_->details.store_id.get()) 224 if (!parsed_args_->details.store_id.get())
225 parsed_args_->details.store_id.reset(new std::string(store_id)); 225 parsed_args_->details.store_id.reset(new std::string(store_id));
226 226
227 store_browser_context_ = store_context; 227 store_browser_context_ = store_context;
228 228
229 bool rv = BrowserThread::PostTask( 229 bool rv = BrowserThread::PostTask(
230 BrowserThread::IO, FROM_HERE, 230 BrowserThread::IO, FROM_HERE,
231 base::Bind(&CookiesGetFunction::GetCookieOnIOThread, this)); 231 base::BindOnce(&CookiesGetFunction::GetCookieOnIOThread, this));
232 DCHECK(rv); 232 DCHECK(rv);
233 233
234 // Will finish asynchronously. 234 // Will finish asynchronously.
235 return true; 235 return true;
236 } 236 }
237 237
238 void CookiesGetFunction::GetCookieOnIOThread() { 238 void CookiesGetFunction::GetCookieOnIOThread() {
239 DCHECK_CURRENTLY_ON(BrowserThread::IO); 239 DCHECK_CURRENTLY_ON(BrowserThread::IO);
240 net::CookieStore* cookie_store = 240 net::CookieStore* cookie_store =
241 store_browser_context_->GetURLRequestContext()->cookie_store(); 241 store_browser_context_->GetURLRequestContext()->cookie_store();
(...skipping 14 matching lines...) Expand all
256 break; 256 break;
257 } 257 }
258 } 258 }
259 259
260 // The cookie doesn't exist; return null. 260 // The cookie doesn't exist; return null.
261 if (!results_) 261 if (!results_)
262 SetResult(base::MakeUnique<base::Value>()); 262 SetResult(base::MakeUnique<base::Value>());
263 263
264 bool rv = BrowserThread::PostTask( 264 bool rv = BrowserThread::PostTask(
265 BrowserThread::UI, FROM_HERE, 265 BrowserThread::UI, FROM_HERE,
266 base::Bind(&CookiesGetFunction::RespondOnUIThread, this)); 266 base::BindOnce(&CookiesGetFunction::RespondOnUIThread, this));
267 DCHECK(rv); 267 DCHECK(rv);
268 } 268 }
269 269
270 void CookiesGetFunction::RespondOnUIThread() { 270 void CookiesGetFunction::RespondOnUIThread() {
271 DCHECK_CURRENTLY_ON(BrowserThread::UI); 271 DCHECK_CURRENTLY_ON(BrowserThread::UI);
272 SendResponse(true); 272 SendResponse(true);
273 } 273 }
274 274
275 CookiesGetAllFunction::CookiesGetAllFunction() { 275 CookiesGetAllFunction::CookiesGetAllFunction() {
276 } 276 }
(...skipping 15 matching lines...) Expand all
292 : std::string(); 292 : std::string();
293 net::URLRequestContextGetter* store_context = NULL; 293 net::URLRequestContextGetter* store_context = NULL;
294 if (!ParseStoreContext(this, &store_id, &store_context)) 294 if (!ParseStoreContext(this, &store_id, &store_context))
295 return false; 295 return false;
296 store_browser_context_ = store_context; 296 store_browser_context_ = store_context;
297 if (!parsed_args_->details.store_id.get()) 297 if (!parsed_args_->details.store_id.get())
298 parsed_args_->details.store_id.reset(new std::string(store_id)); 298 parsed_args_->details.store_id.reset(new std::string(store_id));
299 299
300 bool rv = BrowserThread::PostTask( 300 bool rv = BrowserThread::PostTask(
301 BrowserThread::IO, FROM_HERE, 301 BrowserThread::IO, FROM_HERE,
302 base::Bind(&CookiesGetAllFunction::GetAllCookiesOnIOThread, this)); 302 base::BindOnce(&CookiesGetAllFunction::GetAllCookiesOnIOThread, this));
303 DCHECK(rv); 303 DCHECK(rv);
304 304
305 // Will finish asynchronously. 305 // Will finish asynchronously.
306 return true; 306 return true;
307 } 307 }
308 308
309 void CookiesGetAllFunction::GetAllCookiesOnIOThread() { 309 void CookiesGetAllFunction::GetAllCookiesOnIOThread() {
310 DCHECK_CURRENTLY_ON(BrowserThread::IO); 310 DCHECK_CURRENTLY_ON(BrowserThread::IO);
311 net::CookieStore* cookie_store = 311 net::CookieStore* cookie_store =
312 store_browser_context_->GetURLRequestContext()->cookie_store(); 312 store_browser_context_->GetURLRequestContext()->cookie_store();
313 cookies_helpers::GetCookieListFromStore( 313 cookies_helpers::GetCookieListFromStore(
314 cookie_store, url_, 314 cookie_store, url_,
315 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this)); 315 base::Bind(&CookiesGetAllFunction::GetAllCookiesCallback, this));
316 } 316 }
317 317
318 void CookiesGetAllFunction::GetAllCookiesCallback( 318 void CookiesGetAllFunction::GetAllCookiesCallback(
319 const net::CookieList& cookie_list) { 319 const net::CookieList& cookie_list) {
320 if (extension()) { 320 if (extension()) {
321 std::vector<cookies::Cookie> match_vector; 321 std::vector<cookies::Cookie> match_vector;
322 cookies_helpers::AppendMatchingCookiesToVector( 322 cookies_helpers::AppendMatchingCookiesToVector(
323 cookie_list, url_, &parsed_args_->details, extension(), &match_vector); 323 cookie_list, url_, &parsed_args_->details, extension(), &match_vector);
324 324
325 results_ = GetAll::Results::Create(match_vector); 325 results_ = GetAll::Results::Create(match_vector);
326 } 326 }
327 bool rv = BrowserThread::PostTask( 327 bool rv = BrowserThread::PostTask(
328 BrowserThread::UI, FROM_HERE, 328 BrowserThread::UI, FROM_HERE,
329 base::Bind(&CookiesGetAllFunction::RespondOnUIThread, this)); 329 base::BindOnce(&CookiesGetAllFunction::RespondOnUIThread, this));
330 DCHECK(rv); 330 DCHECK(rv);
331 } 331 }
332 332
333 void CookiesGetAllFunction::RespondOnUIThread() { 333 void CookiesGetAllFunction::RespondOnUIThread() {
334 DCHECK_CURRENTLY_ON(BrowserThread::UI); 334 DCHECK_CURRENTLY_ON(BrowserThread::UI);
335 SendResponse(true); 335 SendResponse(true);
336 } 336 }
337 337
338 CookiesSetFunction::CookiesSetFunction() : success_(false) { 338 CookiesSetFunction::CookiesSetFunction() : success_(false) {
339 } 339 }
(...skipping 14 matching lines...) Expand all
354 : std::string(); 354 : std::string();
355 net::URLRequestContextGetter* store_context = NULL; 355 net::URLRequestContextGetter* store_context = NULL;
356 if (!ParseStoreContext(this, &store_id, &store_context)) 356 if (!ParseStoreContext(this, &store_id, &store_context))
357 return false; 357 return false;
358 store_browser_context_ = store_context; 358 store_browser_context_ = store_context;
359 if (!parsed_args_->details.store_id.get()) 359 if (!parsed_args_->details.store_id.get())
360 parsed_args_->details.store_id.reset(new std::string(store_id)); 360 parsed_args_->details.store_id.reset(new std::string(store_id));
361 361
362 bool rv = BrowserThread::PostTask( 362 bool rv = BrowserThread::PostTask(
363 BrowserThread::IO, FROM_HERE, 363 BrowserThread::IO, FROM_HERE,
364 base::Bind(&CookiesSetFunction::SetCookieOnIOThread, this)); 364 base::BindOnce(&CookiesSetFunction::SetCookieOnIOThread, this));
365 DCHECK(rv); 365 DCHECK(rv);
366 366
367 // Will finish asynchronously. 367 // Will finish asynchronously.
368 return true; 368 return true;
369 } 369 }
370 370
371 void CookiesSetFunction::SetCookieOnIOThread() { 371 void CookiesSetFunction::SetCookieOnIOThread() {
372 DCHECK_CURRENTLY_ON(BrowserThread::IO); 372 DCHECK_CURRENTLY_ON(BrowserThread::IO);
373 net::CookieStore* cookie_store = 373 net::CookieStore* cookie_store =
374 store_browser_context_->GetURLRequestContext()->cookie_store(); 374 store_browser_context_->GetURLRequestContext()->cookie_store();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 if (cookie.Name() == name) { 441 if (cookie.Name() == name) {
442 cookies::Cookie api_cookie = cookies_helpers::CreateCookie( 442 cookies::Cookie api_cookie = cookies_helpers::CreateCookie(
443 cookie, *parsed_args_->details.store_id); 443 cookie, *parsed_args_->details.store_id);
444 results_ = Set::Results::Create(api_cookie); 444 results_ = Set::Results::Create(api_cookie);
445 break; 445 break;
446 } 446 }
447 } 447 }
448 448
449 bool rv = BrowserThread::PostTask( 449 bool rv = BrowserThread::PostTask(
450 BrowserThread::UI, FROM_HERE, 450 BrowserThread::UI, FROM_HERE,
451 base::Bind(&CookiesSetFunction::RespondOnUIThread, this)); 451 base::BindOnce(&CookiesSetFunction::RespondOnUIThread, this));
452 DCHECK(rv); 452 DCHECK(rv);
453 } 453 }
454 454
455 void CookiesSetFunction::RespondOnUIThread() { 455 void CookiesSetFunction::RespondOnUIThread() {
456 DCHECK_CURRENTLY_ON(BrowserThread::UI); 456 DCHECK_CURRENTLY_ON(BrowserThread::UI);
457 if (!success_) { 457 if (!success_) {
458 std::string name = 458 std::string name =
459 parsed_args_->details.name.get() ? *parsed_args_->details.name 459 parsed_args_->details.name.get() ? *parsed_args_->details.name
460 : std::string(); 460 : std::string();
461 error_ = ErrorUtils::FormatErrorMessage(keys::kCookieSetFailedError, name); 461 error_ = ErrorUtils::FormatErrorMessage(keys::kCookieSetFailedError, name);
(...skipping 21 matching lines...) Expand all
483 net::URLRequestContextGetter* store_context = NULL; 483 net::URLRequestContextGetter* store_context = NULL;
484 if (!ParseStoreContext(this, &store_id, &store_context)) 484 if (!ParseStoreContext(this, &store_id, &store_context))
485 return false; 485 return false;
486 store_browser_context_ = store_context; 486 store_browser_context_ = store_context;
487 if (!parsed_args_->details.store_id.get()) 487 if (!parsed_args_->details.store_id.get())
488 parsed_args_->details.store_id.reset(new std::string(store_id)); 488 parsed_args_->details.store_id.reset(new std::string(store_id));
489 489
490 // Pass the work off to the IO thread. 490 // Pass the work off to the IO thread.
491 bool rv = BrowserThread::PostTask( 491 bool rv = BrowserThread::PostTask(
492 BrowserThread::IO, FROM_HERE, 492 BrowserThread::IO, FROM_HERE,
493 base::Bind(&CookiesRemoveFunction::RemoveCookieOnIOThread, this)); 493 base::BindOnce(&CookiesRemoveFunction::RemoveCookieOnIOThread, this));
494 DCHECK(rv); 494 DCHECK(rv);
495 495
496 // Will return asynchronously. 496 // Will return asynchronously.
497 return true; 497 return true;
498 } 498 }
499 499
500 void CookiesRemoveFunction::RemoveCookieOnIOThread() { 500 void CookiesRemoveFunction::RemoveCookieOnIOThread() {
501 DCHECK_CURRENTLY_ON(BrowserThread::IO); 501 DCHECK_CURRENTLY_ON(BrowserThread::IO);
502 502
503 // Remove the cookie 503 // Remove the cookie
504 net::CookieStore* cookie_store = 504 net::CookieStore* cookie_store =
505 store_browser_context_->GetURLRequestContext()->cookie_store(); 505 store_browser_context_->GetURLRequestContext()->cookie_store();
506 cookie_store->DeleteCookieAsync( 506 cookie_store->DeleteCookieAsync(
507 url_, parsed_args_->details.name, 507 url_, parsed_args_->details.name,
508 base::Bind(&CookiesRemoveFunction::RemoveCookieCallback, this)); 508 base::Bind(&CookiesRemoveFunction::RemoveCookieCallback, this));
509 } 509 }
510 510
511 void CookiesRemoveFunction::RemoveCookieCallback() { 511 void CookiesRemoveFunction::RemoveCookieCallback() {
512 // Build the callback result 512 // Build the callback result
513 Remove::Results::Details details; 513 Remove::Results::Details details;
514 details.name = parsed_args_->details.name; 514 details.name = parsed_args_->details.name;
515 details.url = url_.spec(); 515 details.url = url_.spec();
516 details.store_id = *parsed_args_->details.store_id; 516 details.store_id = *parsed_args_->details.store_id;
517 results_ = Remove::Results::Create(details); 517 results_ = Remove::Results::Create(details);
518 518
519 // Return to UI thread 519 // Return to UI thread
520 bool rv = BrowserThread::PostTask( 520 bool rv = BrowserThread::PostTask(
521 BrowserThread::UI, FROM_HERE, 521 BrowserThread::UI, FROM_HERE,
522 base::Bind(&CookiesRemoveFunction::RespondOnUIThread, this)); 522 base::BindOnce(&CookiesRemoveFunction::RespondOnUIThread, this));
523 DCHECK(rv); 523 DCHECK(rv);
524 } 524 }
525 525
526 void CookiesRemoveFunction::RespondOnUIThread() { 526 void CookiesRemoveFunction::RespondOnUIThread() {
527 DCHECK_CURRENTLY_ON(BrowserThread::UI); 527 DCHECK_CURRENTLY_ON(BrowserThread::UI);
528 SendResponse(true); 528 SendResponse(true);
529 } 529 }
530 530
531 ExtensionFunction::ResponseAction CookiesGetAllCookieStoresFunction::Run() { 531 ExtensionFunction::ResponseAction CookiesGetAllCookieStoresFunction::Run() {
532 Profile* original_profile = Profile::FromBrowserContext(browser_context()); 532 Profile* original_profile = Profile::FromBrowserContext(browser_context());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() { 588 BrowserContextKeyedAPIFactory<CookiesAPI>* CookiesAPI::GetFactoryInstance() {
589 return g_factory.Pointer(); 589 return g_factory.Pointer();
590 } 590 }
591 591
592 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) { 592 void CookiesAPI::OnListenerAdded(const EventListenerInfo& details) {
593 cookies_event_router_.reset(new CookiesEventRouter(browser_context_)); 593 cookies_event_router_.reset(new CookiesEventRouter(browser_context_));
594 EventRouter::Get(browser_context_)->UnregisterObserver(this); 594 EventRouter::Get(browser_context_)->UnregisterObserver(this);
595 } 595 }
596 596
597 } // namespace extensions 597 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698