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

Side by Side Diff: ios/net/cookies/cookie_store_ios.mm

Issue 2937963003: Shift cookie system callbacks to OnceCallback to impedance match mojo. (Closed)
Patch Set: Finish Merge Created 3 years, 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "ios/net/cookies/cookie_store_ios.h" 5 #include "ios/net/cookies/cookie_store_ios.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 metrics_enabled_ = true; 296 metrics_enabled_ = true;
297 } 297 }
298 298
299 #pragma mark - 299 #pragma mark -
300 #pragma mark CookieStore methods 300 #pragma mark CookieStore methods
301 301
302 void CookieStoreIOS::SetCookieWithOptionsAsync( 302 void CookieStoreIOS::SetCookieWithOptionsAsync(
303 const GURL& url, 303 const GURL& url,
304 const std::string& cookie_line, 304 const std::string& cookie_line,
305 const net::CookieOptions& options, 305 const net::CookieOptions& options,
306 const SetCookiesCallback& callback) { 306 SetCookiesCallback callback) {
307 DCHECK(thread_checker_.CalledOnValidThread()); 307 DCHECK(thread_checker_.CalledOnValidThread());
308 308
309 // The exclude_httponly() option would only be used by a javascript 309 // The exclude_httponly() option would only be used by a javascript
310 // engine. 310 // engine.
311 DCHECK(!options.exclude_httponly()); 311 DCHECK(!options.exclude_httponly());
312 312
313 // If cookies are not allowed, they are stashed in the CookieMonster, and 313 // If cookies are not allowed, they are stashed in the CookieMonster, and
314 // should be written there instead. 314 // should be written there instead.
315 DCHECK(SystemCookiesAllowed()); 315 DCHECK(SystemCookiesAllowed());
316 316
(...skipping 24 matching lines...) Expand all
341 (!has_explicit_domain || has_valid_domain); 341 (!has_explicit_domain || has_valid_domain);
342 342
343 if (success) { 343 if (success) {
344 [system_store_ setCookie:cookie]; 344 [system_store_ setCookie:cookie];
345 creation_time_manager_->SetCreationTime( 345 creation_time_manager_->SetCreationTime(
346 cookie, 346 cookie,
347 creation_time_manager_->MakeUniqueCreationTime(base::Time::Now())); 347 creation_time_manager_->MakeUniqueCreationTime(base::Time::Now()));
348 } 348 }
349 349
350 if (!callback.is_null()) 350 if (!callback.is_null())
351 callback.Run(success); 351 std::move(callback).Run(success);
352 } 352 }
353 353
354 void CookieStoreIOS::SetCookieWithDetailsAsync( 354 void CookieStoreIOS::SetCookieWithDetailsAsync(const GURL& url,
355 const GURL& url, 355 const std::string& name,
356 const std::string& name, 356 const std::string& value,
357 const std::string& value, 357 const std::string& domain,
358 const std::string& domain, 358 const std::string& path,
359 const std::string& path, 359 base::Time creation_time,
360 base::Time creation_time, 360 base::Time expiration_time,
361 base::Time expiration_time, 361 base::Time last_access_time,
362 base::Time last_access_time, 362 bool secure,
363 bool secure, 363 bool http_only,
364 bool http_only, 364 CookieSameSite same_site,
365 CookieSameSite same_site, 365 CookiePriority priority,
366 CookiePriority priority, 366 SetCookiesCallback callback) {
367 const SetCookiesCallback& callback) {
368 DCHECK(thread_checker_.CalledOnValidThread()); 367 DCHECK(thread_checker_.CalledOnValidThread());
369 // If cookies are not allowed, they are stashed in the CookieMonster, and 368 // If cookies are not allowed, they are stashed in the CookieMonster, and
370 // should be written there instead. 369 // should be written there instead.
371 DCHECK(SystemCookiesAllowed()); 370 DCHECK(SystemCookiesAllowed());
372 371
373 bool success = false; 372 bool success = false;
374 373
375 if (creation_time.is_null()) 374 if (creation_time.is_null())
376 creation_time = base::Time::Now(); 375 creation_time = base::Time::Now();
377 376
378 // Validate consistency of passed arguments. 377 // Validate consistency of passed arguments.
379 if (ParsedCookie::ParseTokenString(name) != name || 378 if (ParsedCookie::ParseTokenString(name) != name ||
380 ParsedCookie::ParseValueString(value) != value || 379 ParsedCookie::ParseValueString(value) != value ||
381 ParsedCookie::ParseValueString(domain) != domain || 380 ParsedCookie::ParseValueString(domain) != domain ||
382 ParsedCookie::ParseValueString(path) != path) { 381 ParsedCookie::ParseValueString(path) != path) {
383 if (!callback.is_null()) 382 if (!callback.is_null())
384 callback.Run(false); 383 std::move(callback).Run(false);
385 return; 384 return;
386 } 385 }
387 386
388 // Validate passed arguments against URL. 387 // Validate passed arguments against URL.
389 std::string cookie_domain; 388 std::string cookie_domain;
390 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path); 389 std::string cookie_path = CanonicalCookie::CanonPathWithString(url, path);
391 if ((secure && !url.SchemeIsCryptographic()) || 390 if ((secure && !url.SchemeIsCryptographic()) ||
392 !cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain) || 391 !cookie_util::GetCookieDomainWithString(url, domain, &cookie_domain) ||
393 (!path.empty() && cookie_path != path)) { 392 (!path.empty() && cookie_path != path)) {
394 if (!callback.is_null()) 393 if (!callback.is_null())
395 callback.Run(false); 394 std::move(callback).Run(false);
396 return; 395 return;
397 } 396 }
398 397
399 // Canonicalize path again to make sure it escapes characters as needed. 398 // Canonicalize path again to make sure it escapes characters as needed.
400 url::Component path_component(0, cookie_path.length()); 399 url::Component path_component(0, cookie_path.length());
401 url::RawCanonOutputT<char> canon_path; 400 url::RawCanonOutputT<char> canon_path;
402 url::Component canon_path_component; 401 url::Component canon_path_component;
403 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path, 402 url::CanonicalizePath(cookie_path.data(), path_component, &canon_path,
404 &canon_path_component); 403 &canon_path_component);
405 cookie_path = std::string(canon_path.data() + canon_path_component.begin, 404 cookie_path = std::string(canon_path.data() + canon_path_component.begin,
(...skipping 11 matching lines...) Expand all
417 if (cookie != nil) { 416 if (cookie != nil) {
418 [system_store_ setCookie:cookie]; 417 [system_store_ setCookie:cookie];
419 creation_time_manager_->SetCreationTime( 418 creation_time_manager_->SetCreationTime(
420 cookie, creation_time_manager_->MakeUniqueCreationTime( 419 cookie, creation_time_manager_->MakeUniqueCreationTime(
421 canonical_cookie->CreationDate())); 420 canonical_cookie->CreationDate()));
422 success = true; 421 success = true;
423 } 422 }
424 } 423 }
425 424
426 if (!callback.is_null()) 425 if (!callback.is_null())
427 callback.Run(success); 426 std::move(callback).Run(success);
428 } 427 }
429 428
430 void CookieStoreIOS::SetCanonicalCookieAsync( 429 void CookieStoreIOS::SetCanonicalCookieAsync(
431 std::unique_ptr<net::CanonicalCookie> cookie, 430 std::unique_ptr<net::CanonicalCookie> cookie,
432 bool secure_source, 431 bool secure_source,
433 bool modify_http_only, 432 bool modify_http_only,
434 const SetCookiesCallback& callback) { 433 SetCookiesCallback callback) {
435 DCHECK(cookie->IsCanonical()); 434 DCHECK(cookie->IsCanonical());
436 // The exclude_httponly() option would only be used by a javascript 435 // The exclude_httponly() option would only be used by a javascript
437 // engine. 436 // engine.
438 DCHECK(modify_http_only); 437 DCHECK(modify_http_only);
439 438
440 if (cookie->IsSecure() && !secure_source) { 439 if (cookie->IsSecure() && !secure_source) {
441 if (!callback.is_null()) 440 if (!callback.is_null())
442 callback.Run(false); 441 std::move(callback).Run(false);
443 return; 442 return;
444 } 443 }
445 444
446 NSHTTPCookie* ns_cookie = SystemCookieFromCanonicalCookie(*cookie.get()); 445 NSHTTPCookie* ns_cookie = SystemCookieFromCanonicalCookie(*cookie.get());
447 446
448 if (ns_cookie != nil) { 447 if (ns_cookie != nil) {
449 [system_store_ setCookie:ns_cookie]; 448 [system_store_ setCookie:ns_cookie];
450 creation_time_manager_->SetCreationTime( 449 creation_time_manager_->SetCreationTime(
451 ns_cookie, 450 ns_cookie,
452 creation_time_manager_->MakeUniqueCreationTime( 451 creation_time_manager_->MakeUniqueCreationTime(
453 cookie->CreationDate().is_null() ? base::Time::Now() 452 cookie->CreationDate().is_null() ? base::Time::Now()
454 : cookie->CreationDate())); 453 : cookie->CreationDate()));
455 if (!callback.is_null()) 454 if (!callback.is_null())
456 callback.Run(true); 455 std::move(callback).Run(true);
457 return; 456 return;
458 } 457 }
459 458
460 if (!callback.is_null()) 459 if (!callback.is_null())
461 callback.Run(false); 460 std::move(callback).Run(false);
462 } 461 }
463 462
464 void CookieStoreIOS::GetCookiesWithOptionsAsync( 463 void CookieStoreIOS::GetCookiesWithOptionsAsync(
465 const GURL& url, 464 const GURL& url,
466 const net::CookieOptions& options, 465 const net::CookieOptions& options,
467 const GetCookiesCallback& callback) { 466 GetCookiesCallback callback) {
468 DCHECK(thread_checker_.CalledOnValidThread()); 467 DCHECK(thread_checker_.CalledOnValidThread());
469 468
470 // If cookies are not allowed, they are stashed in the CookieMonster, and 469 // If cookies are not allowed, they are stashed in the CookieMonster, and
471 // should be read from there instead. 470 // should be read from there instead.
472 DCHECK(SystemCookiesAllowed()); 471 DCHECK(SystemCookiesAllowed());
473 // The exclude_httponly() option would only be used by a javascript 472 // The exclude_httponly() option would only be used by a javascript
474 // engine. 473 // engine.
475 DCHECK(!options.exclude_httponly()); 474 DCHECK(!options.exclude_httponly());
476 475
477 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass 476 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass
478 // options in here as well. https://crbug.com/459154 477 // options in here as well. https://crbug.com/459154
479 NSArray* cookies = 478 NSArray* cookies =
480 GetCookiesForURL(system_store_, url, creation_time_manager_.get()); 479 GetCookiesForURL(system_store_, url, creation_time_manager_.get());
481 if (!callback.is_null()) 480 if (!callback.is_null())
482 callback.Run(BuildCookieLineWithOptions(cookies, options)); 481 std::move(callback).Run(BuildCookieLineWithOptions(cookies, options));
483 } 482 }
484 483
485 void CookieStoreIOS::GetCookieListWithOptionsAsync( 484 void CookieStoreIOS::GetCookieListWithOptionsAsync(
486 const GURL& url, 485 const GURL& url,
487 const net::CookieOptions& options, 486 const net::CookieOptions& options,
488 const GetCookieListCallback& callback) { 487 GetCookieListCallback callback) {
489 DCHECK(thread_checker_.CalledOnValidThread()); 488 DCHECK(thread_checker_.CalledOnValidThread());
490 if (!SystemCookiesAllowed()) { 489 if (!SystemCookiesAllowed()) {
491 // If cookies are not allowed, the cookies are stashed in the 490 // If cookies are not allowed, the cookies are stashed in the
492 // CookieMonster, so get them from there. 491 // CookieMonster, so get them from there.
493 cookie_monster_->GetCookieListWithOptionsAsync(url, options, callback); 492 cookie_monster_->GetCookieListWithOptionsAsync(url, options,
493 std::move(callback));
494 return; 494 return;
495 } 495 }
496 496
497 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass 497 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass
498 // options in here as well. https://crbug.com/459154 498 // options in here as well. https://crbug.com/459154
499 NSArray* cookies = 499 NSArray* cookies =
500 GetCookiesForURL(system_store_, url, creation_time_manager_.get()); 500 GetCookiesForURL(system_store_, url, creation_time_manager_.get());
501 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(cookies); 501 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(cookies);
502 if (!callback.is_null()) 502 if (!callback.is_null())
503 callback.Run(cookie_list); 503 std::move(callback).Run(cookie_list);
504 } 504 }
505 505
506 void CookieStoreIOS::GetAllCookiesAsync(const GetCookieListCallback& callback) { 506 void CookieStoreIOS::GetAllCookiesAsync(GetCookieListCallback callback) {
507 DCHECK(thread_checker_.CalledOnValidThread()); 507 DCHECK(thread_checker_.CalledOnValidThread());
508 508
509 if (!SystemCookiesAllowed()) { 509 if (!SystemCookiesAllowed()) {
510 // If cookies are not allowed, the cookies are stashed in the 510 // If cookies are not allowed, the cookies are stashed in the
511 // CookieMonster, so get them from there. 511 // CookieMonster, so get them from there.
512 cookie_monster_->GetAllCookiesAsync(callback); 512 cookie_monster_->GetAllCookiesAsync(std::move(callback));
513 return; 513 return;
514 } 514 }
515 515
516 NSArray* cookies = GetAllCookies(system_store_, creation_time_manager_.get()); 516 NSArray* cookies = GetAllCookies(system_store_, creation_time_manager_.get());
517 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(cookies); 517 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(cookies);
518 if (!callback.is_null()) { 518 if (!callback.is_null()) {
519 callback.Run(cookie_list); 519 std::move(callback).Run(cookie_list);
520 } 520 }
521 } 521 }
522 522
523 void CookieStoreIOS::DeleteCookieAsync(const GURL& url, 523 void CookieStoreIOS::DeleteCookieAsync(const GURL& url,
524 const std::string& cookie_name, 524 const std::string& cookie_name,
525 const base::Closure& callback) { 525 base::OnceClosure callback) {
526 DCHECK(thread_checker_.CalledOnValidThread()); 526 DCHECK(thread_checker_.CalledOnValidThread());
527 527
528 NSArray* cookies = 528 NSArray* cookies =
529 GetCookiesForURL(system_store_, url, creation_time_manager_.get()); 529 GetCookiesForURL(system_store_, url, creation_time_manager_.get());
530 for (NSHTTPCookie* cookie in cookies) { 530 for (NSHTTPCookie* cookie in cookies) {
531 if ([[cookie name] isEqualToString:base::SysUTF8ToNSString(cookie_name)]) { 531 if ([[cookie name] isEqualToString:base::SysUTF8ToNSString(cookie_name)]) {
532 [system_store_ deleteCookie:cookie]; 532 [system_store_ deleteCookie:cookie];
533 creation_time_manager_->DeleteCreationTime(cookie); 533 creation_time_manager_->DeleteCreationTime(cookie);
534 } 534 }
535 } 535 }
536 536
537 if (!callback.is_null()) 537 if (!callback.is_null())
538 callback.Run(); 538 std::move(callback).Run();
539 } 539 }
540 540
541 void CookieStoreIOS::DeleteCanonicalCookieAsync( 541 void CookieStoreIOS::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
542 const CanonicalCookie& cookie, 542 DeleteCallback callback) {
543 const DeleteCallback& callback) {
544 DCHECK(thread_checker_.CalledOnValidThread()); 543 DCHECK(thread_checker_.CalledOnValidThread());
545 544
546 // This relies on the fact cookies are given unique creation dates. 545 // This relies on the fact cookies are given unique creation dates.
547 CookieFilterFunction filter = base::Bind( 546 CookieFilterFunction filter = base::Bind(
548 IsCookieCreatedBetween, cookie.CreationDate(), cookie.CreationDate()); 547 IsCookieCreatedBetween, cookie.CreationDate(), cookie.CreationDate());
549 DeleteCookiesWithFilter(filter, callback); 548 DeleteCookiesWithFilter(filter, std::move(callback));
550 } 549 }
551 550
552 void CookieStoreIOS::DeleteAllCreatedBetweenAsync( 551 void CookieStoreIOS::DeleteAllCreatedBetweenAsync(
553 const base::Time& delete_begin, 552 const base::Time& delete_begin,
554 const base::Time& delete_end, 553 const base::Time& delete_end,
555 const DeleteCallback& callback) { 554 DeleteCallback callback) {
556 DCHECK(thread_checker_.CalledOnValidThread()); 555 DCHECK(thread_checker_.CalledOnValidThread());
557 556
558 if (metrics_enabled_) 557 if (metrics_enabled_)
559 ResetCookieCountMetrics(); 558 ResetCookieCountMetrics();
560 559
561 CookieFilterFunction filter = base::Bind( 560 CookieFilterFunction filter = base::Bind(
562 &IsCookieCreatedBetween, delete_begin, delete_end); 561 &IsCookieCreatedBetween, delete_begin, delete_end);
563 DeleteCookiesWithFilter(filter, callback); 562 DeleteCookiesWithFilter(filter, std::move(callback));
564 } 563 }
565 564
566 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync( 565 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync(
567 const base::Time& delete_begin, 566 const base::Time& delete_begin,
568 const base::Time& delete_end, 567 const base::Time& delete_end,
569 const CookiePredicate& predicate, 568 const CookiePredicate& predicate,
570 const DeleteCallback& callback) { 569 DeleteCallback callback) {
571 DCHECK(thread_checker_.CalledOnValidThread()); 570 DCHECK(thread_checker_.CalledOnValidThread());
572 571
573 if (metrics_enabled_) 572 if (metrics_enabled_)
574 ResetCookieCountMetrics(); 573 ResetCookieCountMetrics();
575 574
576 CookieFilterFunction filter = base::Bind( 575 CookieFilterFunction filter = base::Bind(
577 IsCookieCreatedBetweenWithPredicate, delete_begin, delete_end, predicate); 576 IsCookieCreatedBetweenWithPredicate, delete_begin, delete_end, predicate);
578 DeleteCookiesWithFilter(filter, callback); 577 DeleteCookiesWithFilter(filter, std::move(callback));
579 } 578 }
580 579
581 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { 580 void CookieStoreIOS::DeleteSessionCookiesAsync(DeleteCallback callback) {
582 DCHECK(thread_checker_.CalledOnValidThread()); 581 DCHECK(thread_checker_.CalledOnValidThread());
583 582
584 if (metrics_enabled_) 583 if (metrics_enabled_)
585 ResetCookieCountMetrics(); 584 ResetCookieCountMetrics();
586 585
587 CookieFilterFunction filter = base::Bind(&IsCookieSessionCookie); 586 CookieFilterFunction filter = base::Bind(&IsCookieSessionCookie);
588 DeleteCookiesWithFilter(filter, callback); 587 DeleteCookiesWithFilter(filter, std::move(callback));
589 } 588 }
590 589
591 void CookieStoreIOS::FlushStore(const base::Closure& closure) { 590 void CookieStoreIOS::FlushStore(base::OnceClosure closure) {
592 DCHECK(thread_checker_.CalledOnValidThread()); 591 DCHECK(thread_checker_.CalledOnValidThread());
593 592
594 if (SystemCookiesAllowed()) { 593 if (SystemCookiesAllowed()) {
595 // If cookies are disabled, the system store is empty, and the cookies are 594 // If cookies are disabled, the system store is empty, and the cookies are
596 // stashed on disk. Do not delete the cookies on the disk in this case. 595 // stashed on disk. Do not delete the cookies on the disk in this case.
597 WriteToCookieMonster([system_store_ cookies]); 596 WriteToCookieMonster([system_store_ cookies]);
598 } 597 }
599 cookie_monster_->FlushStore(closure); 598 cookie_monster_->FlushStore(std::move(closure));
600 flush_closure_.Cancel(); 599 flush_closure_.Cancel();
601 } 600 }
602 601
603 #pragma mark - 602 #pragma mark -
604 #pragma mark Protected methods 603 #pragma mark Protected methods
605 604
606 CookieStoreIOS::CookieStoreIOS( 605 CookieStoreIOS::CookieStoreIOS(
607 net::CookieMonster::PersistentCookieStore* persistent_store, 606 net::CookieMonster::PersistentCookieStore* persistent_store,
608 NSHTTPCookieStorage* system_store) 607 NSHTTPCookieStorage* system_store)
609 : cookie_monster_(new net::CookieMonster(persistent_store, nullptr)), 608 : cookie_monster_(new net::CookieMonster(persistent_store, nullptr)),
610 system_store_(system_store), 609 system_store_(system_store),
611 creation_time_manager_(new CookieCreationTimeManager), 610 creation_time_manager_(new CookieCreationTimeManager),
612 metrics_enabled_(false), 611 metrics_enabled_(false),
613 cookie_cache_(new CookieCache()), 612 cookie_cache_(new CookieCache()),
614 weak_factory_(this) { 613 weak_factory_(this) {
615 DCHECK(system_store); 614 DCHECK(system_store);
616 615
617 NotificationTrampoline::GetInstance()->AddObserver(this); 616 NotificationTrampoline::GetInstance()->AddObserver(this);
618 617
619 cookie_monster_->SetPersistSessionCookies(true); 618 cookie_monster_->SetPersistSessionCookies(true);
620 cookie_monster_->SetForceKeepSessionState(); 619 cookie_monster_->SetForceKeepSessionState();
621 } 620 }
622 621
623 CookieStoreIOS::SetCookiesCallback CookieStoreIOS::WrapSetCallback( 622 CookieStoreIOS::SetCookiesCallback CookieStoreIOS::WrapSetCallback(
624 const SetCookiesCallback& callback) { 623 SetCookiesCallback callback) {
625 DCHECK(thread_checker_.CalledOnValidThread()); 624 DCHECK(thread_checker_.CalledOnValidThread());
626 return base::Bind(&CookieStoreIOS::UpdateCachesAfterSet, 625 return base::BindOnce(&CookieStoreIOS::UpdateCachesAfterSet,
627 weak_factory_.GetWeakPtr(), callback); 626 weak_factory_.GetWeakPtr(), std::move(callback));
628 } 627 }
629 628
630 CookieStoreIOS::DeleteCallback CookieStoreIOS::WrapDeleteCallback( 629 CookieStoreIOS::DeleteCallback CookieStoreIOS::WrapDeleteCallback(
631 const DeleteCallback& callback) { 630 DeleteCallback callback) {
632 DCHECK(thread_checker_.CalledOnValidThread()); 631 DCHECK(thread_checker_.CalledOnValidThread());
633 return base::Bind(&CookieStoreIOS::UpdateCachesAfterDelete, 632 return base::BindOnce(&CookieStoreIOS::UpdateCachesAfterDelete,
634 weak_factory_.GetWeakPtr(), callback); 633 weak_factory_.GetWeakPtr(), std::move(callback));
635 } 634 }
636 635
637 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { 636 base::OnceClosure CookieStoreIOS::WrapClosure(base::OnceClosure callback) {
638 DCHECK(thread_checker_.CalledOnValidThread()); 637 DCHECK(thread_checker_.CalledOnValidThread());
639 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, 638 return base::BindOnce(&CookieStoreIOS::UpdateCachesAfterClosure,
640 weak_factory_.GetWeakPtr(), callback); 639 weak_factory_.GetWeakPtr(), std::move(callback));
641 } 640 }
642 641
643 #pragma mark - 642 #pragma mark -
644 #pragma mark Private methods 643 #pragma mark Private methods
645 644
646 void CookieStoreIOS::ClearSystemStore() { 645 void CookieStoreIOS::ClearSystemStore() {
647 DCHECK(thread_checker_.CalledOnValidThread()); 646 DCHECK(thread_checker_.CalledOnValidThread());
648 base::scoped_nsobject<NSArray> copy( 647 base::scoped_nsobject<NSArray> copy(
649 [[NSArray alloc] initWithArray:[system_store_ cookies]]); 648 [[NSArray alloc] initWithArray:[system_store_ cookies]]);
650 for (NSHTTPCookie* cookie in copy.get()) 649 for (NSHTTPCookie* cookie in copy.get())
(...skipping 19 matching lines...) Expand all
670 cookie, creation_time_manager_->GetCreationTime(cookie))); 669 cookie, creation_time_manager_->GetCreationTime(cookie)));
671 } 670 }
672 cookie_monster_->SetAllCookiesAsync(cookie_list, SetCookiesCallback()); 671 cookie_monster_->SetAllCookiesAsync(cookie_list, SetCookiesCallback());
673 672
674 // Update metrics. 673 // Update metrics.
675 if (metrics_enabled_) 674 if (metrics_enabled_)
676 UMA_HISTOGRAM_COUNTS_10000("CookieIOS.CookieWrittenCount", cookie_count); 675 UMA_HISTOGRAM_COUNTS_10000("CookieIOS.CookieWrittenCount", cookie_count);
677 } 676 }
678 677
679 void CookieStoreIOS::DeleteCookiesWithFilter(const CookieFilterFunction& filter, 678 void CookieStoreIOS::DeleteCookiesWithFilter(const CookieFilterFunction& filter,
680 const DeleteCallback& callback) { 679 DeleteCallback callback) {
681 DCHECK(thread_checker_.CalledOnValidThread()); 680 DCHECK(thread_checker_.CalledOnValidThread());
682 NSArray* cookies = [system_store_ cookies]; 681 NSArray* cookies = [system_store_ cookies];
683 682
684 // Collect the cookies to delete. 683 // Collect the cookies to delete.
685 base::scoped_nsobject<NSMutableArray> to_delete( 684 base::scoped_nsobject<NSMutableArray> to_delete(
686 [[NSMutableArray alloc] init]); 685 [[NSMutableArray alloc] init]);
687 for (NSHTTPCookie* cookie in cookies) { 686 for (NSHTTPCookie* cookie in cookies) {
688 base::Time creation_time = creation_time_manager_->GetCreationTime(cookie); 687 base::Time creation_time = creation_time_manager_->GetCreationTime(cookie);
689 if (filter.Run(cookie, creation_time)) 688 if (filter.Run(cookie, creation_time))
690 [to_delete addObject:cookie]; 689 [to_delete addObject:cookie];
691 } 690 }
692 691
693 // Delete them. 692 // Delete them.
694 for (NSHTTPCookie* cookie in to_delete.get()) { 693 for (NSHTTPCookie* cookie in to_delete.get()) {
695 [system_store_ deleteCookie:cookie]; 694 [system_store_ deleteCookie:cookie];
696 creation_time_manager_->DeleteCreationTime(cookie); 695 creation_time_manager_->DeleteCreationTime(cookie);
697 } 696 }
698 697
699 if (!callback.is_null()) 698 if (!callback.is_null())
700 callback.Run([to_delete count]); 699 std::move(callback).Run([to_delete count]);
701 } 700 }
702 701
703 void CookieStoreIOS::OnSystemCookiesChanged() { 702 void CookieStoreIOS::OnSystemCookiesChanged() {
704 DCHECK(thread_checker_.CalledOnValidThread()); 703 DCHECK(thread_checker_.CalledOnValidThread());
705 704
706 for (const auto& hook_map_entry : hook_map_) { 705 for (const auto& hook_map_entry : hook_map_) {
707 std::pair<GURL, std::string> key = hook_map_entry.first; 706 std::pair<GURL, std::string> key = hook_map_entry.first;
708 std::vector<net::CanonicalCookie> removed_cookies; 707 std::vector<net::CanonicalCookie> removed_cookies;
709 std::vector<net::CanonicalCookie> added_cookies; 708 std::vector<net::CanonicalCookie> added_cookies;
710 if (UpdateCacheForCookieFromSystem(key.first, key.second, &removed_cookies, 709 if (UpdateCacheForCookieFromSystem(key.first, key.second, &removed_cookies,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (cookie_cache_->Update(key.first, key.second, filtered, &removed_cookies, 806 if (cookie_cache_->Update(key.first, key.second, filtered, &removed_cookies,
808 &added_cookies)) { 807 &added_cookies)) {
809 RunCallbacksForCookies(key.first, key.second, removed_cookies, 808 RunCallbacksForCookies(key.first, key.second, removed_cookies,
810 net::CookieStore::ChangeCause::UNKNOWN_DELETION); 809 net::CookieStore::ChangeCause::UNKNOWN_DELETION);
811 RunCallbacksForCookies(key.first, key.second, added_cookies, 810 RunCallbacksForCookies(key.first, key.second, added_cookies,
812 net::CookieStore::ChangeCause::INSERTED); 811 net::CookieStore::ChangeCause::INSERTED);
813 } 812 }
814 } 813 }
815 814
816 void CookieStoreIOS::DidClearNSHTTPCookieStorageCookies( 815 void CookieStoreIOS::DidClearNSHTTPCookieStorageCookies(
817 const DeleteCallback& delete_callback, 816 DeleteCallback delete_callback,
818 int num_deleted) { 817 int num_deleted) {
819 DCHECK(thread_checker_.CalledOnValidThread()); 818 DCHECK(thread_checker_.CalledOnValidThread());
820 819
821 CookieStoreIOSClient* client = net::GetCookieStoreIOSClient(); 820 CookieStoreIOSClient* client = net::GetCookieStoreIOSClient();
822 DCHECK(client); 821 DCHECK(client);
823 auto sequenced_task_runner = client->GetTaskRunner(); 822 auto sequenced_task_runner = client->GetTaskRunner();
824 DCHECK(sequenced_task_runner); 823 DCHECK(sequenced_task_runner);
825 auto callback = 824 auto callback = base::BindOnce(
826 base::Bind(&CookieStoreIOS::DidClearBinaryCookiesFileCookies, 825 &CookieStoreIOS::DidClearBinaryCookiesFileCookies,
827 weak_factory_.GetWeakPtr(), delete_callback, num_deleted); 826 weak_factory_.GetWeakPtr(), std::move(delete_callback), num_deleted);
828 sequenced_task_runner.get()->PostTaskAndReply( 827 sequenced_task_runner.get()->PostTaskAndReply(
829 FROM_HERE, base::Bind(&ClearAllCookiesFromBinaryCookiesFile), callback); 828 FROM_HERE, base::Bind(&ClearAllCookiesFromBinaryCookiesFile),
829 std::move(callback));
830 } 830 }
831 831
832 void CookieStoreIOS::DidClearBinaryCookiesFileCookies( 832 void CookieStoreIOS::DidClearBinaryCookiesFileCookies(
833 const DeleteCallback& callback, 833 DeleteCallback callback,
834 int num_deleted_from_nshttp_cookie_storage) { 834 int num_deleted_from_nshttp_cookie_storage) {
835 DCHECK(thread_checker_.CalledOnValidThread()); 835 DCHECK(thread_checker_.CalledOnValidThread());
836 836
837 CookieStoreIOSClient* client = net::GetCookieStoreIOSClient(); 837 CookieStoreIOSClient* client = net::GetCookieStoreIOSClient();
838 DCHECK(client); 838 DCHECK(client);
839 client->DidChangeCookieStorage(); 839 client->DidChangeCookieStorage();
840 if (!callback.is_null()) 840 if (!callback.is_null())
841 callback.Run(num_deleted_from_nshttp_cookie_storage); 841 std::move(callback).Run(num_deleted_from_nshttp_cookie_storage);
842 } 842 }
843 843
844 void CookieStoreIOS::UpdateCachesFromCookieMonster() { 844 void CookieStoreIOS::UpdateCachesFromCookieMonster() {
845 DCHECK(thread_checker_.CalledOnValidThread()); 845 DCHECK(thread_checker_.CalledOnValidThread());
846 for (const auto& hook_map_entry : hook_map_) { 846 for (const auto& hook_map_entry : hook_map_) {
847 std::pair<GURL, std::string> key = hook_map_entry.first; 847 std::pair<GURL, std::string> key = hook_map_entry.first;
848 GetCookieListCallback callback = base::Bind( 848 GetCookieListCallback callback = base::BindOnce(
849 &CookieStoreIOS::GotCookieListFor, weak_factory_.GetWeakPtr(), key); 849 &CookieStoreIOS::GotCookieListFor, weak_factory_.GetWeakPtr(), key);
850 cookie_monster_->GetAllCookiesForURLAsync(key.first, callback); 850 cookie_monster_->GetAllCookiesForURLAsync(key.first, std::move(callback));
851 } 851 }
852 } 852 }
853 853
854 void CookieStoreIOS::UpdateCachesAfterSet(const SetCookiesCallback& callback, 854 void CookieStoreIOS::UpdateCachesAfterSet(SetCookiesCallback callback,
855 bool success) { 855 bool success) {
856 DCHECK(thread_checker_.CalledOnValidThread()); 856 DCHECK(thread_checker_.CalledOnValidThread());
857 if (success) 857 if (success)
858 UpdateCachesFromCookieMonster(); 858 UpdateCachesFromCookieMonster();
859 if (!callback.is_null()) 859 if (!callback.is_null())
860 callback.Run(success); 860 std::move(callback).Run(success);
861 } 861 }
862 862
863 void CookieStoreIOS::UpdateCachesAfterDelete(const DeleteCallback& callback, 863 void CookieStoreIOS::UpdateCachesAfterDelete(DeleteCallback callback,
864 int num_deleted) { 864 int num_deleted) {
865 DCHECK(thread_checker_.CalledOnValidThread()); 865 DCHECK(thread_checker_.CalledOnValidThread());
866 UpdateCachesFromCookieMonster(); 866 UpdateCachesFromCookieMonster();
867 if (!callback.is_null()) 867 if (!callback.is_null())
868 callback.Run(num_deleted); 868 std::move(callback).Run(num_deleted);
869 } 869 }
870 870
871 void CookieStoreIOS::UpdateCachesAfterClosure(const base::Closure& callback) { 871 void CookieStoreIOS::UpdateCachesAfterClosure(base::OnceClosure callback) {
872 DCHECK(thread_checker_.CalledOnValidThread()); 872 DCHECK(thread_checker_.CalledOnValidThread());
873 UpdateCachesFromCookieMonster(); 873 UpdateCachesFromCookieMonster();
874 if (!callback.is_null()) 874 if (!callback.is_null())
875 callback.Run(); 875 std::move(callback).Run();
876 } 876 }
877 877
878 net::CookieList 878 net::CookieList
879 CookieStoreIOS::CanonicalCookieListFromSystemCookies(NSArray* cookies) { 879 CookieStoreIOS::CanonicalCookieListFromSystemCookies(NSArray* cookies) {
880 net::CookieList cookie_list; 880 net::CookieList cookie_list;
881 cookie_list.reserve([cookies count]); 881 cookie_list.reserve([cookies count]);
882 for (NSHTTPCookie* cookie in cookies) { 882 for (NSHTTPCookie* cookie in cookies) {
883 base::Time created = creation_time_manager_->GetCreationTime(cookie); 883 base::Time created = creation_time_manager_->GetCreationTime(cookie);
884 cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created)); 884 cookie_list.push_back(CanonicalCookieFromSystemCookie(cookie, created));
885 } 885 }
886 return cookie_list; 886 return cookie_list;
887 } 887 }
888 888
889 } // namespace net 889 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698