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

Side by Side Diff: content/browser/background_sync/background_sync_manager.cc

Issue 1774603002: [BackgroundSync] Remove RegistrationKey (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_reg_handle
Patch Set: Rebase 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
« no previous file with comments | « content/browser/background_sync/background_sync_manager.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/background_sync/background_sync_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/barrier_closure.h" 9 #include "base/barrier_closure.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 sync_manager->Init(); 142 sync_manager->Init();
143 return make_scoped_ptr(sync_manager); 143 return make_scoped_ptr(sync_manager);
144 } 144 }
145 145
146 BackgroundSyncManager::~BackgroundSyncManager() { 146 BackgroundSyncManager::~BackgroundSyncManager() {
147 DCHECK_CURRENTLY_ON(BrowserThread::IO); 147 DCHECK_CURRENTLY_ON(BrowserThread::IO);
148 148
149 service_worker_context_->RemoveObserver(this); 149 service_worker_context_->RemoveObserver(this);
150 } 150 }
151 151
152 BackgroundSyncManager::RegistrationKey::RegistrationKey(
153 const BackgroundSyncRegistration& registration)
154 : RegistrationKey(registration.options()->tag) {}
155
156 BackgroundSyncManager::RegistrationKey::RegistrationKey(
157 const BackgroundSyncRegistrationOptions& options)
158 : RegistrationKey(options.tag) {}
159
160 BackgroundSyncManager::RegistrationKey::RegistrationKey(const std::string& tag)
161 : value_("o_" + tag) {
162 // Note that the "o_" prefix on the key is because at one time one-shots were
163 // prefixed with an "o_" and periodic with a "p_". Removing the "o_" requires
164 // migration.
165 }
166
167 void BackgroundSyncManager::Register( 152 void BackgroundSyncManager::Register(
168 int64_t sw_registration_id, 153 int64_t sw_registration_id,
169 const BackgroundSyncRegistrationOptions& options, 154 const BackgroundSyncRegistrationOptions& options,
170 bool requested_from_service_worker, 155 bool requested_from_service_worker,
171 const StatusAndRegistrationCallback& callback) { 156 const StatusAndRegistrationCallback& callback) {
172 DCHECK_CURRENTLY_ON(BrowserThread::IO); 157 DCHECK_CURRENTLY_ON(BrowserThread::IO);
173 158
174 if (disabled_) { 159 if (disabled_) {
175 BackgroundSyncMetrics::CountRegisterFailure( 160 BackgroundSyncMetrics::CountRegisterFailure(
176 BACKGROUND_SYNC_STATUS_STORAGE_ERROR); 161 BACKGROUND_SYNC_STATUS_STORAGE_ERROR);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 for (int i = 0, max = registrations_proto.registration_size(); i < max; 325 for (int i = 0, max = registrations_proto.registration_size(); i < max;
341 ++i) { 326 ++i) {
342 const BackgroundSyncRegistrationProto& registration_proto = 327 const BackgroundSyncRegistrationProto& registration_proto =
343 registrations_proto.registration(i); 328 registrations_proto.registration(i);
344 329
345 if (registration_proto.id() >= registrations->next_id) { 330 if (registration_proto.id() >= registrations->next_id) {
346 corruption_detected = true; 331 corruption_detected = true;
347 break; 332 break;
348 } 333 }
349 334
350 RegistrationKey registration_key(registration_proto.tag());
351
352 BackgroundSyncRegistration* registration = 335 BackgroundSyncRegistration* registration =
353 &registrations->registration_map[registration_key]; 336 &registrations->registration_map[registration_proto.tag()];
354 337
355 BackgroundSyncRegistrationOptions* options = registration->options(); 338 BackgroundSyncRegistrationOptions* options = registration->options();
356 options->tag = registration_proto.tag(); 339 options->tag = registration_proto.tag();
357 options->network_state = registration_proto.network_state(); 340 options->network_state = registration_proto.network_state();
358 341
359 registration->set_id(registration_proto.id()); 342 registration->set_id(registration_proto.id());
360 registration->set_num_attempts(registration_proto.num_attempts()); 343 registration->set_num_attempts(registration_proto.num_attempts());
361 registration->set_delay_until( 344 registration->set_delay_until(
362 base::Time::FromInternalValue(registration_proto.delay_until())); 345 base::Time::FromInternalValue(registration_proto.delay_until()));
363 } 346 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback); 428 PostErrorResponse(BACKGROUND_SYNC_STATUS_NO_SERVICE_WORKER, callback);
446 return; 429 return;
447 } 430 }
448 431
449 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 432 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
450 base::Bind(&NotifyBackgroundSyncRegisteredOnUIThread, 433 base::Bind(&NotifyBackgroundSyncRegisteredOnUIThread,
451 service_worker_context_, 434 service_worker_context_,
452 sw_registration->pattern().GetOrigin())); 435 sw_registration->pattern().GetOrigin()));
453 436
454 BackgroundSyncRegistration* existing_registration = 437 BackgroundSyncRegistration* existing_registration =
455 LookupActiveRegistration(sw_registration_id, RegistrationKey(options)); 438 LookupActiveRegistration(sw_registration_id, options.tag);
456 if (existing_registration) { 439 if (existing_registration) {
457 DCHECK(existing_registration->options()->Equals(options)); 440 DCHECK(existing_registration->options()->Equals(options));
458 441
459 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire = 442 BackgroundSyncMetrics::RegistrationCouldFire registration_could_fire =
460 AreOptionConditionsMet(options) 443 AreOptionConditionsMet(options)
461 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE 444 ? BackgroundSyncMetrics::REGISTRATION_COULD_FIRE
462 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE; 445 : BackgroundSyncMetrics::REGISTRATION_COULD_NOT_FIRE;
463 BackgroundSyncMetrics::CountRegisterSuccess( 446 BackgroundSyncMetrics::CountRegisterSuccess(
464 registration_could_fire, 447 registration_could_fire,
465 BackgroundSyncMetrics::REGISTRATION_IS_DUPLICATE); 448 BackgroundSyncMetrics::REGISTRATION_IS_DUPLICATE);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 ServiceWorkerStatusCode status) { 530 ServiceWorkerStatusCode status) {
548 DCHECK_CURRENTLY_ON(BrowserThread::IO); 531 DCHECK_CURRENTLY_ON(BrowserThread::IO);
549 532
550 // The status doesn't matter at this point, there is nothing else to be done. 533 // The status doesn't matter at this point, there is nothing else to be done.
551 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 534 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
552 base::Bind(barrier_closure)); 535 base::Bind(barrier_closure));
553 } 536 }
554 537
555 BackgroundSyncRegistration* BackgroundSyncManager::LookupActiveRegistration( 538 BackgroundSyncRegistration* BackgroundSyncManager::LookupActiveRegistration(
556 int64_t sw_registration_id, 539 int64_t sw_registration_id,
557 const RegistrationKey& registration_key) { 540 const std::string& tag) {
558 DCHECK_CURRENTLY_ON(BrowserThread::IO); 541 DCHECK_CURRENTLY_ON(BrowserThread::IO);
559 542
560 SWIdToRegistrationsMap::iterator it = 543 SWIdToRegistrationsMap::iterator it =
561 active_registrations_.find(sw_registration_id); 544 active_registrations_.find(sw_registration_id);
562 if (it == active_registrations_.end()) 545 if (it == active_registrations_.end())
563 return nullptr; 546 return nullptr;
564 547
565 BackgroundSyncRegistrations& registrations = it->second; 548 BackgroundSyncRegistrations& registrations = it->second;
566 DCHECK_LE(BackgroundSyncRegistration::kInitialId, registrations.next_id); 549 DCHECK_LE(BackgroundSyncRegistration::kInitialId, registrations.next_id);
567 DCHECK(!registrations.origin.is_empty()); 550 DCHECK(!registrations.origin.is_empty());
568 551
569 auto key_and_registration_iter = 552 auto key_and_registration_iter = registrations.registration_map.find(tag);
570 registrations.registration_map.find(registration_key);
571 if (key_and_registration_iter == registrations.registration_map.end()) 553 if (key_and_registration_iter == registrations.registration_map.end())
572 return nullptr; 554 return nullptr;
573 555
574 return &key_and_registration_iter->second; 556 return &key_and_registration_iter->second;
575 } 557 }
576 558
577 void BackgroundSyncManager::StoreRegistrations( 559 void BackgroundSyncManager::StoreRegistrations(
578 int64_t sw_registration_id, 560 int64_t sw_registration_id,
579 const ServiceWorkerStorage::StatusCallback& callback) { 561 const ServiceWorkerStorage::StatusCallback& callback) {
580 DCHECK_CURRENTLY_ON(BrowserThread::IO); 562 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 626
645 FireReadyEvents(); 627 FireReadyEvents();
646 628
647 base::ThreadTaskRunnerHandle::Get()->PostTask( 629 base::ThreadTaskRunnerHandle::Get()->PostTask(
648 FROM_HERE, 630 FROM_HERE,
649 base::Bind(callback, BACKGROUND_SYNC_STATUS_OK, 631 base::Bind(callback, BACKGROUND_SYNC_STATUS_OK,
650 base::Passed(make_scoped_ptr( 632 base::Passed(make_scoped_ptr(
651 new BackgroundSyncRegistration(new_registration))))); 633 new BackgroundSyncRegistration(new_registration)))));
652 } 634 }
653 635
654 void BackgroundSyncManager::RemoveActiveRegistration( 636 void BackgroundSyncManager::RemoveActiveRegistration(int64_t sw_registration_id,
655 int64_t sw_registration_id, 637 const std::string& tag) {
656 const RegistrationKey& registration_key) {
657 DCHECK_CURRENTLY_ON(BrowserThread::IO); 638 DCHECK_CURRENTLY_ON(BrowserThread::IO);
658 DCHECK(LookupActiveRegistration(sw_registration_id, registration_key)); 639 DCHECK(LookupActiveRegistration(sw_registration_id, tag));
659 640
660 BackgroundSyncRegistrations* registrations = 641 BackgroundSyncRegistrations* registrations =
661 &active_registrations_[sw_registration_id]; 642 &active_registrations_[sw_registration_id];
662 643
663 registrations->registration_map.erase(registration_key); 644 registrations->registration_map.erase(tag);
664 } 645 }
665 646
666 void BackgroundSyncManager::AddActiveRegistration( 647 void BackgroundSyncManager::AddActiveRegistration(
667 int64_t sw_registration_id, 648 int64_t sw_registration_id,
668 const GURL& origin, 649 const GURL& origin,
669 const BackgroundSyncRegistration& sync_registration) { 650 const BackgroundSyncRegistration& sync_registration) {
670 DCHECK_CURRENTLY_ON(BrowserThread::IO); 651 DCHECK_CURRENTLY_ON(BrowserThread::IO);
671 DCHECK(sync_registration.IsValid()); 652 DCHECK(sync_registration.IsValid());
672 653
673 BackgroundSyncRegistrations* registrations = 654 BackgroundSyncRegistrations* registrations =
674 &active_registrations_[sw_registration_id]; 655 &active_registrations_[sw_registration_id];
675 registrations->origin = origin; 656 registrations->origin = origin;
676 657
677 RegistrationKey registration_key(sync_registration); 658 registrations->registration_map[sync_registration.options()->tag] =
678 registrations->registration_map[registration_key] = sync_registration; 659 sync_registration;
679 } 660 }
680 661
681 void BackgroundSyncManager::StoreDataInBackend( 662 void BackgroundSyncManager::StoreDataInBackend(
682 int64_t sw_registration_id, 663 int64_t sw_registration_id,
683 const GURL& origin, 664 const GURL& origin,
684 const std::string& backend_key, 665 const std::string& backend_key,
685 const std::string& data, 666 const std::string& data,
686 const ServiceWorkerStorage::StatusCallback& callback) { 667 const ServiceWorkerStorage::StatusCallback& callback) {
687 DCHECK_CURRENTLY_ON(BrowserThread::IO); 668 DCHECK_CURRENTLY_ON(BrowserThread::IO);
688 669
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) { 837 void BackgroundSyncManager::FireReadyEventsImpl(const base::Closure& callback) {
857 DCHECK_CURRENTLY_ON(BrowserThread::IO); 838 DCHECK_CURRENTLY_ON(BrowserThread::IO);
858 839
859 if (disabled_) { 840 if (disabled_) {
860 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 841 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
861 base::Bind(callback)); 842 base::Bind(callback));
862 return; 843 return;
863 } 844 }
864 845
865 // Find the registrations that are ready to run. 846 // Find the registrations that are ready to run.
866 std::vector<std::pair<int64_t, RegistrationKey>> sw_id_and_keys_to_fire; 847 std::vector<std::pair<int64_t, std::string>> sw_id_and_tags_to_fire;
867 848
868 for (auto& sw_id_and_registrations : active_registrations_) { 849 for (auto& sw_id_and_registrations : active_registrations_) {
869 const int64_t service_worker_id = sw_id_and_registrations.first; 850 const int64_t service_worker_id = sw_id_and_registrations.first;
870 for (auto& key_and_registration : 851 for (auto& key_and_registration :
871 sw_id_and_registrations.second.registration_map) { 852 sw_id_and_registrations.second.registration_map) {
872 BackgroundSyncRegistration* registration = &key_and_registration.second; 853 BackgroundSyncRegistration* registration = &key_and_registration.second;
873 if (IsRegistrationReadyToFire(*registration)) { 854 if (IsRegistrationReadyToFire(*registration)) {
874 sw_id_and_keys_to_fire.push_back( 855 sw_id_and_tags_to_fire.push_back(
875 std::make_pair(service_worker_id, key_and_registration.first)); 856 std::make_pair(service_worker_id, key_and_registration.first));
876 // The state change is not saved to persistent storage because 857 // The state change is not saved to persistent storage because
877 // if the sync event is killed mid-sync then it should return to 858 // if the sync event is killed mid-sync then it should return to
878 // SYNC_STATE_PENDING. 859 // SYNC_STATE_PENDING.
879 registration->set_sync_state(BackgroundSyncState::FIRING); 860 registration->set_sync_state(BackgroundSyncState::FIRING);
880 } 861 }
881 } 862 }
882 } 863 }
883 864
884 if (sw_id_and_keys_to_fire.empty()) { 865 if (sw_id_and_tags_to_fire.empty()) {
885 RunInBackgroundIfNecessary(); 866 RunInBackgroundIfNecessary();
886 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 867 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
887 base::Bind(callback)); 868 base::Bind(callback));
888 return; 869 return;
889 } 870 }
890 871
891 base::TimeTicks start_time = base::TimeTicks::Now(); 872 base::TimeTicks start_time = base::TimeTicks::Now();
892 873
893 // Fire the sync event of the ready registrations and run |callback| once 874 // Fire the sync event of the ready registrations and run |callback| once
894 // they're all done. 875 // they're all done.
895 base::Closure events_fired_barrier_closure = base::BarrierClosure( 876 base::Closure events_fired_barrier_closure = base::BarrierClosure(
896 sw_id_and_keys_to_fire.size(), 877 sw_id_and_tags_to_fire.size(),
897 base::Bind(&BackgroundSyncManager::FireReadyEventsAllEventsFiring, 878 base::Bind(&BackgroundSyncManager::FireReadyEventsAllEventsFiring,
898 weak_ptr_factory_.GetWeakPtr(), callback)); 879 weak_ptr_factory_.GetWeakPtr(), callback));
899 880
900 // Record the total time taken after all events have run to completion. 881 // Record the total time taken after all events have run to completion.
901 base::Closure events_completed_barrier_closure = 882 base::Closure events_completed_barrier_closure =
902 base::BarrierClosure(sw_id_and_keys_to_fire.size(), 883 base::BarrierClosure(sw_id_and_tags_to_fire.size(),
903 base::Bind(&OnAllSyncEventsCompleted, start_time, 884 base::Bind(&OnAllSyncEventsCompleted, start_time,
904 sw_id_and_keys_to_fire.size())); 885 sw_id_and_tags_to_fire.size()));
905 886
906 for (const auto& sw_id_and_key : sw_id_and_keys_to_fire) { 887 for (const auto& sw_id_and_tag : sw_id_and_tags_to_fire) {
907 int64_t service_worker_id = sw_id_and_key.first; 888 int64_t service_worker_id = sw_id_and_tag.first;
908 const BackgroundSyncRegistration* registration = 889 const BackgroundSyncRegistration* registration =
909 LookupActiveRegistration(service_worker_id, sw_id_and_key.second); 890 LookupActiveRegistration(service_worker_id, sw_id_and_tag.second);
910 DCHECK(registration); 891 DCHECK(registration);
911 892
912 service_worker_context_->FindReadyRegistrationForId( 893 service_worker_context_->FindReadyRegistrationForId(
913 service_worker_id, active_registrations_[service_worker_id].origin, 894 service_worker_id, active_registrations_[service_worker_id].origin,
914 base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration, 895 base::Bind(&BackgroundSyncManager::FireReadyEventsDidFindRegistration,
915 weak_ptr_factory_.GetWeakPtr(), sw_id_and_key.second, 896 weak_ptr_factory_.GetWeakPtr(), sw_id_and_tag.second,
916 registration->id(), events_fired_barrier_closure, 897 registration->id(), events_fired_barrier_closure,
917 events_completed_barrier_closure)); 898 events_completed_barrier_closure));
918 } 899 }
919 } 900 }
920 901
921 void BackgroundSyncManager::FireReadyEventsDidFindRegistration( 902 void BackgroundSyncManager::FireReadyEventsDidFindRegistration(
922 const RegistrationKey& registration_key, 903 const std::string& tag,
923 BackgroundSyncRegistration::RegistrationId registration_id, 904 BackgroundSyncRegistration::RegistrationId registration_id,
924 const base::Closure& event_fired_callback, 905 const base::Closure& event_fired_callback,
925 const base::Closure& event_completed_callback, 906 const base::Closure& event_completed_callback,
926 ServiceWorkerStatusCode service_worker_status, 907 ServiceWorkerStatusCode service_worker_status,
927 const scoped_refptr<ServiceWorkerRegistration>& 908 const scoped_refptr<ServiceWorkerRegistration>&
928 service_worker_registration) { 909 service_worker_registration) {
929 DCHECK_CURRENTLY_ON(BrowserThread::IO); 910 DCHECK_CURRENTLY_ON(BrowserThread::IO);
930 if (service_worker_status != SERVICE_WORKER_OK) { 911 if (service_worker_status != SERVICE_WORKER_OK) {
931 base::ThreadTaskRunnerHandle::Get()->PostTask( 912 base::ThreadTaskRunnerHandle::Get()->PostTask(
932 FROM_HERE, base::Bind(event_fired_callback)); 913 FROM_HERE, base::Bind(event_fired_callback));
933 base::ThreadTaskRunnerHandle::Get()->PostTask( 914 base::ThreadTaskRunnerHandle::Get()->PostTask(
934 FROM_HERE, base::Bind(event_completed_callback)); 915 FROM_HERE, base::Bind(event_completed_callback));
935 return; 916 return;
936 } 917 }
937 918
938 BackgroundSyncRegistration* registration = LookupActiveRegistration( 919 BackgroundSyncRegistration* registration =
939 service_worker_registration->id(), registration_key); 920 LookupActiveRegistration(service_worker_registration->id(), tag);
940 DCHECK(registration); 921 DCHECK(registration);
941 922
942 num_firing_registrations_ += 1; 923 num_firing_registrations_ += 1;
943 924
944 BackgroundSyncEventLastChance last_chance = 925 BackgroundSyncEventLastChance last_chance =
945 registration->num_attempts() == parameters_->max_sync_attempts - 1 926 registration->num_attempts() == parameters_->max_sync_attempts - 1
946 ? BackgroundSyncEventLastChance::IS_LAST_CHANCE 927 ? BackgroundSyncEventLastChance::IS_LAST_CHANCE
947 : BackgroundSyncEventLastChance::IS_NOT_LAST_CHANCE; 928 : BackgroundSyncEventLastChance::IS_NOT_LAST_CHANCE;
948 929
949 HasMainFrameProviderHost( 930 HasMainFrameProviderHost(
950 service_worker_registration->pattern().GetOrigin(), 931 service_worker_registration->pattern().GetOrigin(),
951 base::Bind(&BackgroundSyncMetrics::RecordEventStarted)); 932 base::Bind(&BackgroundSyncMetrics::RecordEventStarted));
952 933
953 DispatchSyncEvent( 934 DispatchSyncEvent(
954 registration->options()->tag, 935 registration->options()->tag,
955 service_worker_registration->active_version(), last_chance, 936 service_worker_registration->active_version(), last_chance,
956 base::Bind(&BackgroundSyncManager::EventComplete, 937 base::Bind(&BackgroundSyncManager::EventComplete,
957 weak_ptr_factory_.GetWeakPtr(), service_worker_registration, 938 weak_ptr_factory_.GetWeakPtr(), service_worker_registration,
958 service_worker_registration->id(), registration_key, 939 service_worker_registration->id(), tag,
959 event_completed_callback)); 940 event_completed_callback));
960 941
961 base::ThreadTaskRunnerHandle::Get()->PostTask( 942 base::ThreadTaskRunnerHandle::Get()->PostTask(
962 FROM_HERE, base::Bind(event_fired_callback)); 943 FROM_HERE, base::Bind(event_fired_callback));
963 } 944 }
964 945
965 void BackgroundSyncManager::FireReadyEventsAllEventsFiring( 946 void BackgroundSyncManager::FireReadyEventsAllEventsFiring(
966 const base::Closure& callback) { 947 const base::Closure& callback) {
967 DCHECK_CURRENTLY_ON(BrowserThread::IO); 948 DCHECK_CURRENTLY_ON(BrowserThread::IO);
968 949
969 RunInBackgroundIfNecessary(); 950 RunInBackgroundIfNecessary();
970 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 951 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
971 base::Bind(callback)); 952 base::Bind(callback));
972 } 953 }
973 954
974 // |service_worker_registration| is just to keep the registration alive 955 // |service_worker_registration| is just to keep the registration alive
975 // while the event is firing. 956 // while the event is firing.
976 void BackgroundSyncManager::EventComplete( 957 void BackgroundSyncManager::EventComplete(
977 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration, 958 const scoped_refptr<ServiceWorkerRegistration>& service_worker_registration,
978 int64_t service_worker_id, 959 int64_t service_worker_id,
979 const RegistrationKey& registration_key, 960 const std::string& tag,
980 const base::Closure& callback, 961 const base::Closure& callback,
981 ServiceWorkerStatusCode status_code) { 962 ServiceWorkerStatusCode status_code) {
982 DCHECK_CURRENTLY_ON(BrowserThread::IO); 963 DCHECK_CURRENTLY_ON(BrowserThread::IO);
983 964
984 if (disabled_) { 965 if (disabled_) {
985 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 966 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
986 base::Bind(callback)); 967 base::Bind(callback));
987 return; 968 return;
988 } 969 }
989 970
990 op_scheduler_.ScheduleOperation(base::Bind( 971 op_scheduler_.ScheduleOperation(base::Bind(
991 &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(), 972 &BackgroundSyncManager::EventCompleteImpl, weak_ptr_factory_.GetWeakPtr(),
992 service_worker_id, registration_key, status_code, 973 service_worker_id, tag, status_code, MakeClosureCompletion(callback)));
993 MakeClosureCompletion(callback)));
994 } 974 }
995 975
996 void BackgroundSyncManager::EventCompleteImpl( 976 void BackgroundSyncManager::EventCompleteImpl(
997 int64_t service_worker_id, 977 int64_t service_worker_id,
998 const RegistrationKey& registration_key, 978 const std::string& tag,
999 ServiceWorkerStatusCode status_code, 979 ServiceWorkerStatusCode status_code,
1000 const base::Closure& callback) { 980 const base::Closure& callback) {
1001 DCHECK_CURRENTLY_ON(BrowserThread::IO); 981 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1002 982
1003 if (disabled_) { 983 if (disabled_) {
1004 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 984 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
1005 base::Bind(callback)); 985 base::Bind(callback));
1006 return; 986 return;
1007 } 987 }
1008 988
1009 num_firing_registrations_ -= 1; 989 num_firing_registrations_ -= 1;
1010 990
1011 BackgroundSyncRegistration* registration = 991 BackgroundSyncRegistration* registration =
1012 LookupActiveRegistration(service_worker_id, registration_key); 992 LookupActiveRegistration(service_worker_id, tag);
1013 if (!registration) { 993 if (!registration) {
1014 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 994 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
1015 base::Bind(callback)); 995 base::Bind(callback));
1016 return; 996 return;
1017 } 997 }
1018 998
1019 DCHECK_NE(BackgroundSyncState::PENDING, registration->sync_state()); 999 DCHECK_NE(BackgroundSyncState::PENDING, registration->sync_state());
1020 1000
1021 registration->set_num_attempts(registration->num_attempts() + 1); 1001 registration->set_num_attempts(registration->num_attempts() + 1);
1022 1002
(...skipping 21 matching lines...) Expand all
1044 can_retry) { // Sync failed but can retry 1024 can_retry) { // Sync failed but can retry
1045 registration->set_sync_state(BackgroundSyncState::PENDING); 1025 registration->set_sync_state(BackgroundSyncState::PENDING);
1046 registration->set_delay_until(clock_->Now() + 1026 registration->set_delay_until(clock_->Now() +
1047 parameters_->initial_retry_delay * 1027 parameters_->initial_retry_delay *
1048 pow(parameters_->retry_delay_factor, 1028 pow(parameters_->retry_delay_factor,
1049 registration->num_attempts() - 1)); 1029 registration->num_attempts() - 1));
1050 registration_completed = false; 1030 registration_completed = false;
1051 } 1031 }
1052 1032
1053 if (registration_completed) { 1033 if (registration_completed) {
1054 RegistrationKey key(*registration); 1034 const std::string& tag = registration->options()->tag;
1055 BackgroundSyncRegistration* active_registration = 1035 BackgroundSyncRegistration* active_registration =
1056 LookupActiveRegistration(service_worker_id, key); 1036 LookupActiveRegistration(service_worker_id, tag);
1057 if (active_registration && 1037 if (active_registration &&
1058 active_registration->id() == registration->id()) { 1038 active_registration->id() == registration->id()) {
1059 RemoveActiveRegistration(service_worker_id, key); 1039 RemoveActiveRegistration(service_worker_id, tag);
1060 } 1040 }
1061 } 1041 }
1062 1042
1063 StoreRegistrations( 1043 StoreRegistrations(
1064 service_worker_id, 1044 service_worker_id,
1065 base::Bind(&BackgroundSyncManager::EventCompleteDidStore, 1045 base::Bind(&BackgroundSyncManager::EventCompleteDidStore,
1066 weak_ptr_factory_.GetWeakPtr(), service_worker_id, callback)); 1046 weak_ptr_factory_.GetWeakPtr(), service_worker_id, callback));
1067 } 1047 }
1068 1048
1069 void BackgroundSyncManager::EventCompleteDidStore( 1049 void BackgroundSyncManager::EventCompleteDidStore(
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) { 1187 BackgroundSyncManager::MakeStatusCompletion(const StatusCallback& callback) {
1208 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1188 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1209 1189
1210 return base::Bind( 1190 return base::Bind(
1211 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback, 1191 &BackgroundSyncManager::CompleteOperationCallback<StatusCallback,
1212 BackgroundSyncStatus>, 1192 BackgroundSyncStatus>,
1213 weak_ptr_factory_.GetWeakPtr(), callback); 1193 weak_ptr_factory_.GetWeakPtr(), callback);
1214 } 1194 }
1215 1195
1216 } // namespace content 1196 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/background_sync/background_sync_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698