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

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

Issue 2618293003: [ios] Removed CookieStoreIOS::SynchronizationState::SYNCHRONIZING. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 const std::string& cookie_line, 321 const std::string& cookie_line,
322 const net::CookieOptions& options, 322 const net::CookieOptions& options,
323 const SetCookiesCallback& callback) { 323 const SetCookiesCallback& callback) {
324 DCHECK(thread_checker_.CalledOnValidThread()); 324 DCHECK(thread_checker_.CalledOnValidThread());
325 325
326 switch (synchronization_state_) { 326 switch (synchronization_state_) {
327 case NOT_SYNCHRONIZED: 327 case NOT_SYNCHRONIZED:
328 cookie_monster_->SetCookieWithOptionsAsync(url, cookie_line, options, 328 cookie_monster_->SetCookieWithOptionsAsync(url, cookie_line, options,
329 WrapSetCallback(callback)); 329 WrapSetCallback(callback));
330 break; 330 break;
331 case SYNCHRONIZING:
332 tasks_pending_synchronization_.push_back(
333 base::Bind(&CookieStoreIOS::SetCookieWithOptionsAsync,
334 weak_factory_.GetWeakPtr(), url, cookie_line, options,
335 WrapSetCallback(callback)));
336 break;
337 case SYNCHRONIZED: 331 case SYNCHRONIZED:
338 // The exclude_httponly() option would only be used by a javascript 332 // The exclude_httponly() option would only be used by a javascript
339 // engine. 333 // engine.
340 DCHECK(!options.exclude_httponly()); 334 DCHECK(!options.exclude_httponly());
341 // If cookies are not allowed, they are stashed in the CookieMonster, and 335 // If cookies are not allowed, they are stashed in the CookieMonster, and
342 // should be written there instead. 336 // should be written there instead.
343 DCHECK(SystemCookiesAllowed()); 337 DCHECK(SystemCookiesAllowed());
344 338
345 base::Time server_time = 339 base::Time server_time =
346 options.has_server_time() ? options.server_time() : base::Time(); 340 options.has_server_time() ? options.server_time() : base::Time();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const SetCookiesCallback& callback) { 393 const SetCookiesCallback& callback) {
400 DCHECK(thread_checker_.CalledOnValidThread()); 394 DCHECK(thread_checker_.CalledOnValidThread());
401 395
402 switch (synchronization_state_) { 396 switch (synchronization_state_) {
403 case NOT_SYNCHRONIZED: 397 case NOT_SYNCHRONIZED:
404 cookie_monster_->SetCookieWithDetailsAsync( 398 cookie_monster_->SetCookieWithDetailsAsync(
405 url, name, value, domain, path, creation_time, expiration_time, 399 url, name, value, domain, path, creation_time, expiration_time,
406 last_access_time, secure, http_only, same_site, enforce_strict_secure, 400 last_access_time, secure, http_only, same_site, enforce_strict_secure,
407 priority, WrapSetCallback(callback)); 401 priority, WrapSetCallback(callback));
408 break; 402 break;
409 case SYNCHRONIZING:
410 tasks_pending_synchronization_.push_back(
411 base::Bind(&CookieStoreIOS::SetCookieWithDetailsAsync,
412 weak_factory_.GetWeakPtr(), url, name, value, domain, path,
413 creation_time, expiration_time, last_access_time, secure,
414 http_only, same_site, enforce_strict_secure, priority,
415 WrapSetCallback(callback)));
416 break;
417 case SYNCHRONIZED: 403 case SYNCHRONIZED:
418 // If cookies are not allowed, they are stashed in the CookieMonster, and 404 // If cookies are not allowed, they are stashed in the CookieMonster, and
419 // should be written there instead. 405 // should be written there instead.
420 DCHECK(SystemCookiesAllowed()); 406 DCHECK(SystemCookiesAllowed());
421 407
422 bool success = false; 408 bool success = false;
423 409
424 if (creation_time.is_null()) 410 if (creation_time.is_null())
425 creation_time = base::Time::Now(); 411 creation_time = base::Time::Now();
426 412
(...skipping 26 matching lines...) Expand all
453 void CookieStoreIOS::GetCookiesWithOptionsAsync( 439 void CookieStoreIOS::GetCookiesWithOptionsAsync(
454 const GURL& url, 440 const GURL& url,
455 const net::CookieOptions& options, 441 const net::CookieOptions& options,
456 const GetCookiesCallback& callback) { 442 const GetCookiesCallback& callback) {
457 DCHECK(thread_checker_.CalledOnValidThread()); 443 DCHECK(thread_checker_.CalledOnValidThread());
458 444
459 switch (synchronization_state_) { 445 switch (synchronization_state_) {
460 case NOT_SYNCHRONIZED: 446 case NOT_SYNCHRONIZED:
461 cookie_monster_->GetCookiesWithOptionsAsync(url, options, callback); 447 cookie_monster_->GetCookiesWithOptionsAsync(url, options, callback);
462 break; 448 break;
463 case SYNCHRONIZING:
464 tasks_pending_synchronization_.push_back(
465 base::Bind(&CookieStoreIOS::GetCookiesWithOptionsAsync,
466 weak_factory_.GetWeakPtr(), url, options, callback));
467 break;
468 case SYNCHRONIZED: 449 case SYNCHRONIZED:
469 // If cookies are not allowed, they are stashed in the CookieMonster, and 450 // If cookies are not allowed, they are stashed in the CookieMonster, and
470 // should be read from there instead. 451 // should be read from there instead.
471 DCHECK(SystemCookiesAllowed()); 452 DCHECK(SystemCookiesAllowed());
472 // The exclude_httponly() option would only be used by a javascript 453 // The exclude_httponly() option would only be used by a javascript
473 // engine. 454 // engine.
474 DCHECK(!options.exclude_httponly()); 455 DCHECK(!options.exclude_httponly());
475 456
476 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass 457 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass
477 // options in here as well. https://crbug.com/459154 458 // options in here as well. https://crbug.com/459154
478 NSArray* cookies = GetCookiesForURL(system_store_, 459 NSArray* cookies = GetCookiesForURL(system_store_,
479 url, creation_time_manager_.get()); 460 url, creation_time_manager_.get());
480 if (!callback.is_null()) 461 if (!callback.is_null())
481 callback.Run(BuildCookieLineWithOptions(cookies, options)); 462 callback.Run(BuildCookieLineWithOptions(cookies, options));
482 break; 463 break;
483 } 464 }
484 } 465 }
485 466
486 void CookieStoreIOS::GetCookieListWithOptionsAsync( 467 void CookieStoreIOS::GetCookieListWithOptionsAsync(
487 const GURL& url, 468 const GURL& url,
488 const net::CookieOptions& options, 469 const net::CookieOptions& options,
489 const GetCookieListCallback& callback) { 470 const GetCookieListCallback& callback) {
490 DCHECK(thread_checker_.CalledOnValidThread()); 471 DCHECK(thread_checker_.CalledOnValidThread());
491 472
492 switch (synchronization_state_) { 473 switch (synchronization_state_) {
493 case NOT_SYNCHRONIZED: 474 case NOT_SYNCHRONIZED:
494 cookie_monster_->GetCookieListWithOptionsAsync(url, options, callback); 475 cookie_monster_->GetCookieListWithOptionsAsync(url, options, callback);
495 break; 476 break;
496 case SYNCHRONIZING:
497 tasks_pending_synchronization_.push_back(
498 base::Bind(&CookieStoreIOS::GetCookieListWithOptionsAsync,
499 weak_factory_.GetWeakPtr(), url, options, callback));
500 break;
501 case SYNCHRONIZED: 477 case SYNCHRONIZED:
502 if (!SystemCookiesAllowed()) { 478 if (!SystemCookiesAllowed()) {
503 // If cookies are not allowed, the cookies are stashed in the 479 // If cookies are not allowed, the cookies are stashed in the
504 // CookieMonster, so get them from there. 480 // CookieMonster, so get them from there.
505 cookie_monster_->GetCookieListWithOptionsAsync(url, options, callback); 481 cookie_monster_->GetCookieListWithOptionsAsync(url, options, callback);
506 return; 482 return;
507 } 483 }
508 484
509 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass 485 // TODO(mkwst): If/when iOS supports Same-Site cookies, we'll need to pass
510 // options in here as well. https://crbug.com/459154 486 // options in here as well. https://crbug.com/459154
511 NSArray* cookies = GetCookiesForURL(system_store_, 487 NSArray* cookies = GetCookiesForURL(system_store_,
512 url, creation_time_manager_.get()); 488 url, creation_time_manager_.get());
513 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies( 489 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(
514 cookies); 490 cookies);
515 if (!callback.is_null()) 491 if (!callback.is_null())
516 callback.Run(cookie_list); 492 callback.Run(cookie_list);
517 break; 493 break;
518 } 494 }
519 } 495 }
520 496
521 void CookieStoreIOS::GetAllCookiesAsync(const GetCookieListCallback& callback) { 497 void CookieStoreIOS::GetAllCookiesAsync(const GetCookieListCallback& callback) {
522 DCHECK(thread_checker_.CalledOnValidThread()); 498 DCHECK(thread_checker_.CalledOnValidThread());
523 499
524 switch (synchronization_state_) { 500 switch (synchronization_state_) {
525 case NOT_SYNCHRONIZED: 501 case NOT_SYNCHRONIZED:
526 cookie_monster_->GetAllCookiesAsync(callback); 502 cookie_monster_->GetAllCookiesAsync(callback);
527 break; 503 break;
528 case SYNCHRONIZING:
529 tasks_pending_synchronization_.push_back(
530 base::Bind(&CookieStoreIOS::GetAllCookiesAsync,
531 weak_factory_.GetWeakPtr(), callback));
532 break;
533 case SYNCHRONIZED: 504 case SYNCHRONIZED:
534 if (!SystemCookiesAllowed()) { 505 if (!SystemCookiesAllowed()) {
535 // If cookies are not allowed, the cookies are stashed in the 506 // If cookies are not allowed, the cookies are stashed in the
536 // CookieMonster, so get them from there. 507 // CookieMonster, so get them from there.
537 cookie_monster_->GetAllCookiesAsync(callback); 508 cookie_monster_->GetAllCookiesAsync(callback);
538 return; 509 return;
539 } 510 }
540 511
541 NSArray* cookies = GetAllCookies(system_store_, 512 NSArray* cookies = GetAllCookies(system_store_,
542 creation_time_manager_.get()); 513 creation_time_manager_.get());
543 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies( 514 net::CookieList cookie_list = CanonicalCookieListFromSystemCookies(
544 cookies); 515 cookies);
545 if (!callback.is_null()) { 516 if (!callback.is_null()) {
546 callback.Run(cookie_list); 517 callback.Run(cookie_list);
547 } 518 }
548 break; 519 break;
549 } 520 }
550 } 521 }
551 522
552 void CookieStoreIOS::DeleteCookieAsync(const GURL& url, 523 void CookieStoreIOS::DeleteCookieAsync(const GURL& url,
553 const std::string& cookie_name, 524 const std::string& cookie_name,
554 const base::Closure& callback) { 525 const base::Closure& callback) {
555 DCHECK(thread_checker_.CalledOnValidThread()); 526 DCHECK(thread_checker_.CalledOnValidThread());
556 527
557 switch (synchronization_state_) { 528 switch (synchronization_state_) {
558 case NOT_SYNCHRONIZED: 529 case NOT_SYNCHRONIZED:
559 cookie_monster_->DeleteCookieAsync(url, cookie_name, 530 cookie_monster_->DeleteCookieAsync(url, cookie_name,
560 WrapClosure(callback)); 531 WrapClosure(callback));
561 break; 532 break;
562 case SYNCHRONIZING:
563 tasks_pending_synchronization_.push_back(base::Bind(
564 &CookieStoreIOS::DeleteCookieAsync, weak_factory_.GetWeakPtr(), url,
565 cookie_name, WrapClosure(callback)));
566 break;
567 case SYNCHRONIZED: 533 case SYNCHRONIZED:
568 NSArray* cookies = GetCookiesForURL(system_store_, 534 NSArray* cookies = GetCookiesForURL(system_store_,
569 url, creation_time_manager_.get()); 535 url, creation_time_manager_.get());
570 for (NSHTTPCookie* cookie in cookies) { 536 for (NSHTTPCookie* cookie in cookies) {
571 if ([[cookie name] 537 if ([[cookie name]
572 isEqualToString:base::SysUTF8ToNSString(cookie_name)]) { 538 isEqualToString:base::SysUTF8ToNSString(cookie_name)]) {
573 [system_store_ deleteCookie:cookie]; 539 [system_store_ deleteCookie:cookie];
574 creation_time_manager_->DeleteCreationTime(cookie); 540 creation_time_manager_->DeleteCreationTime(cookie);
575 } 541 }
576 } 542 }
577 if (!callback.is_null()) 543 if (!callback.is_null())
578 callback.Run(); 544 callback.Run();
579 break; 545 break;
580 } 546 }
581 } 547 }
582 548
583 void CookieStoreIOS::DeleteCanonicalCookieAsync( 549 void CookieStoreIOS::DeleteCanonicalCookieAsync(
584 const CanonicalCookie& cookie, 550 const CanonicalCookie& cookie,
585 const DeleteCallback& callback) { 551 const DeleteCallback& callback) {
586 DCHECK(thread_checker_.CalledOnValidThread()); 552 DCHECK(thread_checker_.CalledOnValidThread());
587 553
588 switch (synchronization_state_) { 554 switch (synchronization_state_) {
589 case NOT_SYNCHRONIZED: 555 case NOT_SYNCHRONIZED:
590 cookie_monster_->DeleteCanonicalCookieAsync(cookie, 556 cookie_monster_->DeleteCanonicalCookieAsync(cookie,
591 WrapDeleteCallback(callback)); 557 WrapDeleteCallback(callback));
592 break; 558 break;
593 case SYNCHRONIZING:
594 tasks_pending_synchronization_.push_back(base::Bind(
595 &CookieStoreIOS::DeleteCanonicalCookieAsync,
596 weak_factory_.GetWeakPtr(), cookie, WrapDeleteCallback(callback)));
597 break;
598 case SYNCHRONIZED: 559 case SYNCHRONIZED:
599 // This relies on the fact cookies are given unique creation dates. 560 // This relies on the fact cookies are given unique creation dates.
600 CookieFilterFunction filter = base::Bind( 561 CookieFilterFunction filter = base::Bind(
601 IsCookieCreatedBetween, cookie.CreationDate(), cookie.CreationDate()); 562 IsCookieCreatedBetween, cookie.CreationDate(), cookie.CreationDate());
602 DeleteCookiesWithFilter(filter, callback); 563 DeleteCookiesWithFilter(filter, callback);
603 } 564 }
604 } 565 }
605 566
606 void CookieStoreIOS::DeleteAllCreatedBetweenAsync( 567 void CookieStoreIOS::DeleteAllCreatedBetweenAsync(
607 const base::Time& delete_begin, 568 const base::Time& delete_begin,
608 const base::Time& delete_end, 569 const base::Time& delete_end,
609 const DeleteCallback& callback) { 570 const DeleteCallback& callback) {
610 DCHECK(thread_checker_.CalledOnValidThread()); 571 DCHECK(thread_checker_.CalledOnValidThread());
611 572
612 if (metrics_enabled_) 573 if (metrics_enabled_)
613 ResetCookieCountMetrics(); 574 ResetCookieCountMetrics();
614 575
615 switch (synchronization_state_) { 576 switch (synchronization_state_) {
616 case NOT_SYNCHRONIZED: 577 case NOT_SYNCHRONIZED:
617 cookie_monster_->DeleteAllCreatedBetweenAsync( 578 cookie_monster_->DeleteAllCreatedBetweenAsync(
618 delete_begin, delete_end, WrapDeleteCallback(callback)); 579 delete_begin, delete_end, WrapDeleteCallback(callback));
619 break; 580 break;
620 case SYNCHRONIZING:
621 tasks_pending_synchronization_.push_back(
622 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenAsync,
623 weak_factory_.GetWeakPtr(), delete_begin, delete_end,
624 WrapDeleteCallback(callback)));
625 break;
626 case SYNCHRONIZED: 581 case SYNCHRONIZED:
627 CookieFilterFunction filter = 582 CookieFilterFunction filter =
628 base::Bind(&IsCookieCreatedBetween, delete_begin, delete_end); 583 base::Bind(&IsCookieCreatedBetween, delete_begin, delete_end);
629 DeleteCookiesWithFilter(filter, callback); 584 DeleteCookiesWithFilter(filter, callback);
630 break; 585 break;
631 } 586 }
632 } 587 }
633 588
634 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync( 589 void CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync(
635 const base::Time& delete_begin, 590 const base::Time& delete_begin,
636 const base::Time& delete_end, 591 const base::Time& delete_end,
637 const CookiePredicate& predicate, 592 const CookiePredicate& predicate,
638 const DeleteCallback& callback) { 593 const DeleteCallback& callback) {
639 DCHECK(thread_checker_.CalledOnValidThread()); 594 DCHECK(thread_checker_.CalledOnValidThread());
640 595
641 if (metrics_enabled_) 596 if (metrics_enabled_)
642 ResetCookieCountMetrics(); 597 ResetCookieCountMetrics();
643 598
644 switch (synchronization_state_) { 599 switch (synchronization_state_) {
645 case NOT_SYNCHRONIZED: 600 case NOT_SYNCHRONIZED:
646 cookie_monster_->DeleteAllCreatedBetweenWithPredicateAsync( 601 cookie_monster_->DeleteAllCreatedBetweenWithPredicateAsync(
647 delete_begin, delete_end, predicate, WrapDeleteCallback(callback)); 602 delete_begin, delete_end, predicate, WrapDeleteCallback(callback));
648 break; 603 break;
649 case SYNCHRONIZING:
650 tasks_pending_synchronization_.push_back(
651 base::Bind(&CookieStoreIOS::DeleteAllCreatedBetweenWithPredicateAsync,
652 weak_factory_.GetWeakPtr(), delete_begin, delete_end,
653 predicate, WrapDeleteCallback(callback)));
654 break;
655 case SYNCHRONIZED: 604 case SYNCHRONIZED:
656 CookieFilterFunction filter = 605 CookieFilterFunction filter =
657 base::Bind(IsCookieCreatedBetweenWithPredicate, delete_begin, 606 base::Bind(IsCookieCreatedBetweenWithPredicate, delete_begin,
658 delete_end, predicate); 607 delete_end, predicate);
659 DeleteCookiesWithFilter(filter, callback); 608 DeleteCookiesWithFilter(filter, callback);
660 break; 609 break;
661 } 610 }
662 } 611 }
663 612
664 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) { 613 void CookieStoreIOS::DeleteSessionCookiesAsync(const DeleteCallback& callback) {
665 DCHECK(thread_checker_.CalledOnValidThread()); 614 DCHECK(thread_checker_.CalledOnValidThread());
666 615
667 if (metrics_enabled_) 616 if (metrics_enabled_)
668 ResetCookieCountMetrics(); 617 ResetCookieCountMetrics();
669 618
670 switch (synchronization_state_) { 619 switch (synchronization_state_) {
671 case NOT_SYNCHRONIZED: 620 case NOT_SYNCHRONIZED:
672 cookie_monster_->DeleteSessionCookiesAsync(WrapDeleteCallback(callback)); 621 cookie_monster_->DeleteSessionCookiesAsync(WrapDeleteCallback(callback));
673 break; 622 break;
674 case SYNCHRONIZING:
675 tasks_pending_synchronization_.push_back(
676 base::Bind(&CookieStoreIOS::DeleteSessionCookiesAsync,
677 weak_factory_.GetWeakPtr(), WrapDeleteCallback(callback)));
678 break;
679 case SYNCHRONIZED: 623 case SYNCHRONIZED:
680 CookieFilterFunction filter = base::Bind(&IsCookieSessionCookie); 624 CookieFilterFunction filter = base::Bind(&IsCookieSessionCookie);
681 DeleteCookiesWithFilter(filter, callback); 625 DeleteCookiesWithFilter(filter, callback);
682 break; 626 break;
683 } 627 }
684 } 628 }
685 629
686 void CookieStoreIOS::FlushStore(const base::Closure& closure) { 630 void CookieStoreIOS::FlushStore(const base::Closure& closure) {
687 DCHECK(thread_checker_.CalledOnValidThread()); 631 DCHECK(thread_checker_.CalledOnValidThread());
688 632
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 weak_factory_.GetWeakPtr(), callback); 930 weak_factory_.GetWeakPtr(), callback);
987 } 931 }
988 932
989 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) { 933 base::Closure CookieStoreIOS::WrapClosure(const base::Closure& callback) {
990 DCHECK(thread_checker_.CalledOnValidThread()); 934 DCHECK(thread_checker_.CalledOnValidThread());
991 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure, 935 return base::Bind(&CookieStoreIOS::UpdateCachesAfterClosure,
992 weak_factory_.GetWeakPtr(), callback); 936 weak_factory_.GetWeakPtr(), callback);
993 } 937 }
994 938
995 } // namespace net 939 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/cookies/cookie_store_ios.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698