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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.cc

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass InstanceID to requests Created 5 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/gcm_driver/gcm_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/profiler/scoped_tracker.h" 15 #include "base/profiler/scoped_tracker.h"
16 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "components/gcm_driver/gcm_account_mapper.h" 18 #include "components/gcm_driver/gcm_account_mapper.h"
19 #include "components/gcm_driver/gcm_app_handler.h" 19 #include "components/gcm_driver/gcm_app_handler.h"
20 #include "components/gcm_driver/gcm_channel_status_syncer.h" 20 #include "components/gcm_driver/gcm_channel_status_syncer.h"
21 #include "components/gcm_driver/gcm_client_factory.h" 21 #include "components/gcm_driver/gcm_client_factory.h"
22 #include "components/gcm_driver/gcm_delayed_task_controller.h" 22 #include "components/gcm_driver/gcm_delayed_task_controller.h"
23 #include "components/gcm_driver/instance_id/instance_id_impl.h"
23 #include "components/gcm_driver/system_encryptor.h" 24 #include "components/gcm_driver/system_encryptor.h"
24 #include "google_apis/gcm/engine/account_mapping.h" 25 #include "google_apis/gcm/engine/account_mapping.h"
25 #include "net/base/ip_endpoint.h" 26 #include "net/base/ip_endpoint.h"
26 #include "net/url_request/url_request_context_getter.h" 27 #include "net/url_request/url_request_context_getter.h"
27 28
28 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
29 #include "components/timers/alarm_timer_chromeos.h" 30 #include "components/timers/alarm_timer_chromeos.h"
30 #endif 31 #endif
31 32
32 namespace gcm { 33 namespace gcm {
33 34
34 class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { 35 class GCMDriverDesktop::IOWorker : public GCMClient::Delegate {
35 public: 36 public:
36 // Called on UI thread. 37 // Called on UI thread.
37 IOWorker(const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 38 IOWorker(const scoped_refptr<base::SequencedTaskRunner>& ui_thread,
38 const scoped_refptr<base::SequencedTaskRunner>& io_thread); 39 const scoped_refptr<base::SequencedTaskRunner>& io_thread);
39 virtual ~IOWorker(); 40 virtual ~IOWorker();
40 41
41 // Overridden from GCMClient::Delegate: 42 // Overridden from GCMClient::Delegate:
42 // Called on IO thread. 43 // Called on IO thread.
43 void OnRegisterFinished(const std::string& app_id, 44 void OnRegisterFinished(const linked_ptr<RegistrationInfo>& registration_info,
44 const std::string& registration_id, 45 const std::string& registration_id,
45 GCMClient::Result result) override; 46 GCMClient::Result result) override;
46 void OnUnregisterFinished(const std::string& app_id, 47 void OnUnregisterFinished(
47 GCMClient::Result result) override; 48 const linked_ptr<RegistrationInfo>& registration_info,
49 GCMClient::Result result) override;
48 void OnSendFinished(const std::string& app_id, 50 void OnSendFinished(const std::string& app_id,
49 const std::string& message_id, 51 const std::string& message_id,
50 GCMClient::Result result) override; 52 GCMClient::Result result) override;
51 void OnMessageReceived(const std::string& app_id, 53 void OnMessageReceived(const std::string& app_id,
52 const GCMClient::IncomingMessage& message) override; 54 const GCMClient::IncomingMessage& message) override;
53 void OnMessagesDeleted(const std::string& app_id) override; 55 void OnMessagesDeleted(const std::string& app_id) override;
54 void OnMessageSendError( 56 void OnMessageSendError(
55 const std::string& app_id, 57 const std::string& app_id,
56 const GCMClient::SendErrorDetails& send_error_details) override; 58 const GCMClient::SendErrorDetails& send_error_details) override;
57 void OnSendAcknowledged(const std::string& app_id, 59 void OnSendAcknowledged(const std::string& app_id,
(...skipping 23 matching lines...) Expand all
81 void GetGCMStatistics(bool clear_logs); 83 void GetGCMStatistics(bool clear_logs);
82 void SetGCMRecording(bool recording); 84 void SetGCMRecording(bool recording);
83 85
84 void SetAccountTokens( 86 void SetAccountTokens(
85 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); 87 const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
86 void UpdateAccountMapping(const AccountMapping& account_mapping); 88 void UpdateAccountMapping(const AccountMapping& account_mapping);
87 void RemoveAccountMapping(const std::string& account_id); 89 void RemoveAccountMapping(const std::string& account_id);
88 void SetLastTokenFetchTime(const base::Time& time); 90 void SetLastTokenFetchTime(const base::Time& time);
89 void WakeFromSuspendForHeartbeat(bool wake); 91 void WakeFromSuspendForHeartbeat(bool wake);
90 void AddInstanceIDData(const std::string& app_id, 92 void AddInstanceIDData(const std::string& app_id,
91 const std::string& instance_id_data); 93 const std::string& instance_id,
94 const std::string& extra_data);
92 void RemoveInstanceIDData(const std::string& app_id); 95 void RemoveInstanceIDData(const std::string& app_id);
93 void GetInstanceIDData(const std::string& app_id); 96 void GetInstanceIDData(const std::string& app_id);
97 void GetToken(const std::string& app_id,
98 const std::string& authorized_entity,
99 const std::string& scope,
100 const std::map<std::string, std::string>& options);
101 void DeleteToken(const std::string& app_id,
102 const std::string& authorized_entity,
103 const std::string& scope);
94 104
95 // For testing purpose. Can be called from UI thread. Use with care. 105 // For testing purpose. Can be called from UI thread. Use with care.
96 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 106 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
97 107
98 private: 108 private:
99 scoped_refptr<base::SequencedTaskRunner> ui_thread_; 109 scoped_refptr<base::SequencedTaskRunner> ui_thread_;
100 scoped_refptr<base::SequencedTaskRunner> io_thread_; 110 scoped_refptr<base::SequencedTaskRunner> io_thread_;
101 111
102 base::WeakPtr<GCMDriverDesktop> service_; 112 base::WeakPtr<GCMDriverDesktop> service_;
103 113
(...skipping 30 matching lines...) Expand all
134 144
135 gcm_client_->Initialize(chrome_build_info, 145 gcm_client_->Initialize(chrome_build_info,
136 store_path, 146 store_path,
137 blocking_task_runner, 147 blocking_task_runner,
138 request_context, 148 request_context,
139 make_scoped_ptr<Encryptor>(new SystemEncryptor), 149 make_scoped_ptr<Encryptor>(new SystemEncryptor),
140 this); 150 this);
141 } 151 }
142 152
143 void GCMDriverDesktop::IOWorker::OnRegisterFinished( 153 void GCMDriverDesktop::IOWorker::OnRegisterFinished(
144 const std::string& app_id, 154 const linked_ptr<RegistrationInfo>& registration_info,
145 const std::string& registration_id, 155 const std::string& registration_id,
146 GCMClient::Result result) { 156 GCMClient::Result result) {
147 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 157 DCHECK(io_thread_->RunsTasksOnCurrentThread());
148 158
149 ui_thread_->PostTask( 159 const GCMRegistrationInfo* gcm_registration_info =
160 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
161 if (gcm_registration_info) {
162 ui_thread_->PostTask(
163 FROM_HERE,
164 base::Bind(&GCMDriverDesktop::RegisterFinished,
165 service_,
166 gcm_registration_info->app_id,
167 registration_id,
168 result));
169 }
170
171 const InstanceIDTokenInfo* instance_id_token_info =
172 InstanceIDTokenInfo::FromRegistrationInfo(registration_info.get());
173 if (instance_id_token_info) {
174 ui_thread_->PostTask(
150 FROM_HERE, 175 FROM_HERE,
151 base::Bind(&GCMDriverDesktop::RegisterFinished, service_, app_id, 176 base::Bind(&GCMDriverDesktop::GetTokenFinished,
152 registration_id, result)); 177 service_,
178 instance_id_token_info->app_id,
179 instance_id_token_info->authorized_entity,
180 instance_id_token_info->scope,
181 registration_id,
182 result));
183 }
153 } 184 }
154 185
155 void GCMDriverDesktop::IOWorker::OnUnregisterFinished( 186 void GCMDriverDesktop::IOWorker::OnUnregisterFinished(
156 const std::string& app_id, 187 const linked_ptr<RegistrationInfo>& registration_info,
157 GCMClient::Result result) { 188 GCMClient::Result result) {
158 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 189 DCHECK(io_thread_->RunsTasksOnCurrentThread());
159 190
160 ui_thread_->PostTask(FROM_HERE, 191 ui_thread_->PostTask(FROM_HERE,
161 base::Bind(&GCMDriverDesktop::UnregisterFinished, 192 base::Bind(&GCMDriverDesktop::UnregisterFinished,
162 service_, 193 service_,
163 app_id, 194 registration_info->app_id,
164 result)); 195 result));
165 } 196 }
166 197
167 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, 198 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id,
168 const std::string& message_id, 199 const std::string& message_id,
169 GCMClient::Result result) { 200 GCMClient::Result result) {
170 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 201 DCHECK(io_thread_->RunsTasksOnCurrentThread());
171 202
172 ui_thread_->PostTask( 203 ui_thread_->PostTask(
173 FROM_HERE, 204 FROM_HERE,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 292 DCHECK(io_thread_->RunsTasksOnCurrentThread());
262 293
263 gcm_client_->Stop(); 294 gcm_client_->Stop();
264 } 295 }
265 296
266 void GCMDriverDesktop::IOWorker::Register( 297 void GCMDriverDesktop::IOWorker::Register(
267 const std::string& app_id, 298 const std::string& app_id,
268 const std::vector<std::string>& sender_ids) { 299 const std::vector<std::string>& sender_ids) {
269 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 300 DCHECK(io_thread_->RunsTasksOnCurrentThread());
270 301
271 gcm_client_->Register(app_id, sender_ids); 302 scoped_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
303 gcm_info->app_id = app_id;
304 gcm_info->sender_ids = sender_ids;
305 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release()));
272 } 306 }
273 307
274 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { 308 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) {
275 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 309 DCHECK(io_thread_->RunsTasksOnCurrentThread());
276 310
277 gcm_client_->Unregister(app_id); 311 scoped_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
312 gcm_info->app_id = app_id;
313 gcm_client_->Unregister(
314 make_linked_ptr<RegistrationInfo>(gcm_info.release()));
278 } 315 }
279 316
280 void GCMDriverDesktop::IOWorker::Send( 317 void GCMDriverDesktop::IOWorker::Send(
281 const std::string& app_id, 318 const std::string& app_id,
282 const std::string& receiver_id, 319 const std::string& receiver_id,
283 const GCMClient::OutgoingMessage& message) { 320 const GCMClient::OutgoingMessage& message) {
284 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 321 DCHECK(io_thread_->RunsTasksOnCurrentThread());
285 322
286 gcm_client_->Send(app_id, receiver_id, message); 323 gcm_client_->Send(app_id, receiver_id, message);
287 } 324 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 379
343 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { 380 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) {
344 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 381 DCHECK(io_thread_->RunsTasksOnCurrentThread());
345 382
346 if (gcm_client_.get()) 383 if (gcm_client_.get())
347 gcm_client_->SetLastTokenFetchTime(time); 384 gcm_client_->SetLastTokenFetchTime(time);
348 } 385 }
349 386
350 void GCMDriverDesktop::IOWorker::AddInstanceIDData( 387 void GCMDriverDesktop::IOWorker::AddInstanceIDData(
351 const std::string& app_id, 388 const std::string& app_id,
352 const std::string& instance_id_data) { 389 const std::string& instance_id,
390 const std::string& extra_data) {
353 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 391 DCHECK(io_thread_->RunsTasksOnCurrentThread());
354 392
355 if (gcm_client_.get()) 393 if (gcm_client_.get())
356 gcm_client_->AddInstanceIDData(app_id, instance_id_data); 394 gcm_client_->AddInstanceIDData(app_id, instance_id, extra_data);
357 } 395 }
358 396
359 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData( 397 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData(
360 const std::string& app_id) { 398 const std::string& app_id) {
361 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 399 DCHECK(io_thread_->RunsTasksOnCurrentThread());
362 400
363 if (gcm_client_.get()) 401 if (gcm_client_.get())
364 gcm_client_->RemoveInstanceIDData(app_id); 402 gcm_client_->RemoveInstanceIDData(app_id);
365 } 403 }
366 404
367 void GCMDriverDesktop::IOWorker::GetInstanceIDData( 405 void GCMDriverDesktop::IOWorker::GetInstanceIDData(
368 const std::string& app_id) { 406 const std::string& app_id) {
369 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 407 DCHECK(io_thread_->RunsTasksOnCurrentThread());
370 408
371 std::string instance_id_data; 409 std::string instance_id;
410 std::string extra_data;
372 if (gcm_client_.get()) 411 if (gcm_client_.get())
373 instance_id_data = gcm_client_->GetInstanceIDData(app_id); 412 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data);
374 413
375 ui_thread_->PostTask( 414 ui_thread_->PostTask(
376 FROM_HERE, 415 FROM_HERE,
377 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, 416 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished,
378 service_, app_id, instance_id_data)); 417 service_, app_id, instance_id, extra_data));
418 }
419
420 void GCMDriverDesktop::IOWorker::GetToken(
421 const std::string& app_id,
422 const std::string& authorized_entity,
423 const std::string& scope,
424 const std::map<std::string, std::string>& options) {
425 DCHECK(io_thread_->RunsTasksOnCurrentThread());
426
427 scoped_ptr<InstanceIDTokenInfo> instance_id_token_info(
428 new InstanceIDTokenInfo);
429 instance_id_token_info->app_id = app_id;
430 instance_id_token_info->authorized_entity = authorized_entity;
431 instance_id_token_info->scope = scope;
432 instance_id_token_info->options = options;
433 gcm_client_->Register(
434 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release()));
435 }
436
437 void GCMDriverDesktop::IOWorker::DeleteToken(
438 const std::string& app_id,
439 const std::string& authorized_entity,
440 const std::string& scope) {
441 scoped_ptr<InstanceIDTokenInfo> instance_id_token_info(
442 new InstanceIDTokenInfo);
443 instance_id_token_info->app_id = app_id;
444 instance_id_token_info->authorized_entity = authorized_entity;
445 instance_id_token_info->scope = scope;
446 gcm_client_->Unregister(
447 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release()));
379 } 448 }
380 449
381 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { 450 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) {
382 #if defined(OS_CHROMEOS) 451 #if defined(OS_CHROMEOS)
383 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 452 DCHECK(io_thread_->RunsTasksOnCurrentThread());
384 453
385 scoped_ptr<base::Timer> timer; 454 scoped_ptr<base::Timer> timer;
386 if (wake) 455 if (wake)
387 timer.reset(new timers::SimpleAlarmTimer()); 456 timer.reset(new timers::SimpleAlarmTimer());
388 else 457 else
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 756
688 last_token_fetch_time_ = time; 757 last_token_fetch_time_ = time;
689 758
690 io_thread_->PostTask( 759 io_thread_->PostTask(
691 FROM_HERE, 760 FROM_HERE,
692 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, 761 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime,
693 base::Unretained(io_worker_.get()), 762 base::Unretained(io_worker_.get()),
694 time)); 763 time));
695 } 764 }
696 765
697 InstanceIDStore* GCMDriverDesktop::GetInstanceIDStore() { 766 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandler() {
698 return this; 767 return this;
699 } 768 }
700 769
770 void GCMDriverDesktop::GetToken(
771 const std::string& app_id,
772 const std::string& authorized_entity,
773 const std::string& scope,
774 const std::map<std::string, std::string>& options,
775 const GetTokenCallback& callback) {
776 DCHECK(!app_id.empty());
777 DCHECK(!authorized_entity.empty());
778 DCHECK(!scope.empty());
779 DCHECK(!callback.is_null());
780
781 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
782 if (result != GCMClient::SUCCESS) {
783 callback.Run(std::string(), result);
784 return;
785 }
786
787 // If previous GetToken operation is still in progress, bail out.
788 TokenTuple tuple_key(app_id, authorized_entity, scope);
789 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) {
790 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING);
791 return;
792 }
793
794 get_token_callbacks_[tuple_key] = callback;
795
796 io_thread_->PostTask(
797 FROM_HERE,
798 base::Bind(&GCMDriverDesktop::IOWorker::GetToken,
799 base::Unretained(io_worker_.get()),
800 app_id,
801 authorized_entity,
802 scope,
803 options));
804 }
805
806 void GCMDriverDesktop::DeleteToken(const std::string& app_id,
807 const std::string& authorized_entity,
808 const std::string& scope,
809 const DeleteTokenCallback& callback) {
810 DCHECK(!app_id.empty());
811 DCHECK(!authorized_entity.empty());
812 DCHECK(!scope.empty());
813 DCHECK(!callback.is_null());
814
815 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
816 if (result != GCMClient::SUCCESS) {
817 callback.Run(result);
818 return;
819 }
820
821 // If previous GetToken operation is still in progress, bail out.
822 TokenTuple tuple_key(app_id, authorized_entity, scope);
823 if (delete_token_callbacks_.find(tuple_key) !=
824 delete_token_callbacks_.end()) {
825 callback.Run(GCMClient::ASYNC_OPERATION_PENDING);
826 return;
827 }
828
829 delete_token_callbacks_[tuple_key] = callback;
830
831 io_thread_->PostTask(
832 FROM_HERE,
833 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken,
834 base::Unretained(io_worker_.get()),
835 app_id,
836 authorized_entity,
837 scope));
838 }
839
701 void GCMDriverDesktop::AddInstanceIDData( 840 void GCMDriverDesktop::AddInstanceIDData(
702 const std::string& app_id, 841 const std::string& app_id,
703 const std::string& instance_id_data) { 842 const std::string& instance_id,
843 const std::string& extra_data) {
704 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 844 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
705 845
706 io_thread_->PostTask( 846 io_thread_->PostTask(
707 FROM_HERE, 847 FROM_HERE,
708 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData, 848 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData,
709 base::Unretained(io_worker_.get()), 849 base::Unretained(io_worker_.get()),
710 app_id, 850 app_id,
711 instance_id_data)); 851 instance_id,
852 extra_data));
712 } 853 }
713 854
714 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { 855 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) {
715 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 856 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
716 857
717 io_thread_->PostTask( 858 io_thread_->PostTask(
718 FROM_HERE, 859 FROM_HERE,
719 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData, 860 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData,
720 base::Unretained(io_worker_.get()), 861 base::Unretained(io_worker_.get()),
721 app_id)); 862 app_id));
722 } 863 }
723 864
724 void GCMDriverDesktop::GetInstanceIDData( 865 void GCMDriverDesktop::GetInstanceIDData(
725 const std::string& app_id, 866 const std::string& app_id,
726 const GetInstanceIDDataCallback& callback) { 867 const GetInstanceIDDataCallback& callback) {
727 DCHECK(!get_instance_id_data_callbacks_.count(app_id)); 868 DCHECK(!get_instance_id_data_callbacks_.count(app_id));
728 get_instance_id_data_callbacks_[app_id] = callback; 869 get_instance_id_data_callbacks_[app_id] = callback;
729 io_thread_->PostTask( 870 io_thread_->PostTask(
730 FROM_HERE, 871 FROM_HERE,
731 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData, 872 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData,
732 base::Unretained(io_worker_.get()), 873 base::Unretained(io_worker_.get()),
733 app_id)); 874 app_id));
734 } 875 }
735 876
736 void GCMDriverDesktop::GetInstanceIDDataFinished( 877 void GCMDriverDesktop::GetInstanceIDDataFinished(
737 const std::string& app_id, 878 const std::string& app_id,
738 const std::string& instance_id_data) { 879 const std::string& instance_id,
880 const std::string& extra_data) {
739 DCHECK(get_instance_id_data_callbacks_.count(app_id)); 881 DCHECK(get_instance_id_data_callbacks_.count(app_id));
740 get_instance_id_data_callbacks_[app_id].Run(instance_id_data); 882 get_instance_id_data_callbacks_[app_id].Run(instance_id, extra_data);
741 get_instance_id_data_callbacks_.erase(app_id); 883 get_instance_id_data_callbacks_.erase(app_id);
742 } 884 }
743 885
886 void GCMDriverDesktop::GetTokenFinished(const std::string& app_id,
887 const std::string& authorized_entity,
888 const std::string& scope,
889 const std::string& token,
890 GCMClient::Result result) {
891 TokenTuple tuple_key(app_id, authorized_entity, scope);
892 auto callback_iter = get_token_callbacks_.find(tuple_key);
893 if (callback_iter == get_token_callbacks_.end()) {
894 // The callback could have been removed when the app is uninstalled.
895 return;
896 }
897
898 GetTokenCallback callback = callback_iter->second;
899 get_token_callbacks_.erase(callback_iter);
900 callback.Run(token, result);
901 }
902
903 void GCMDriverDesktop::DeleteTokenFinished(const std::string& app_id,
904 const std::string& authorized_entity,
905 const std::string& scope,
906 GCMClient::Result result) {
907 TokenTuple tuple_key(app_id, authorized_entity, scope);
908 auto callback_iter = delete_token_callbacks_.find(tuple_key);
909 if (callback_iter == delete_token_callbacks_.end()) {
910 // The callback could have been removed when the app is uninstalled.
911 return;
912 }
913
914 DeleteTokenCallback callback = callback_iter->second;
915 delete_token_callbacks_.erase(callback_iter);
916 callback.Run(result);
917 }
918
744 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { 919 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) {
745 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 920 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
746 921
747 wake_from_suspend_enabled_ = wake; 922 wake_from_suspend_enabled_ = wake;
748 923
749 // The GCM service has not been initialized. 924 // The GCM service has not been initialized.
750 if (!delayed_task_controller_) 925 if (!delayed_task_controller_)
751 return; 926 return;
752 927
753 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 928 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 const GCMClient::GCMStatistics& stats) { 1097 const GCMClient::GCMStatistics& stats) {
923 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1098 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
924 1099
925 // Normally request_gcm_statistics_callback_ would not be null. 1100 // Normally request_gcm_statistics_callback_ would not be null.
926 if (!request_gcm_statistics_callback_.is_null()) 1101 if (!request_gcm_statistics_callback_.is_null())
927 request_gcm_statistics_callback_.Run(stats); 1102 request_gcm_statistics_callback_.Run(stats);
928 else 1103 else
929 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 1104 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
930 } 1105 }
931 1106
1107 bool GCMDriverDesktop::TokenTupleComparer::operator()(
1108 const TokenTuple& a, const TokenTuple& b) const {
1109 if (get<0>(a) < get<0>(b))
1110 return true;
1111 if (get<0>(a) > get<0>(b))
1112 return false;
1113
1114 if (get<1>(a) < get<1>(b))
1115 return true;
1116 if (get<1>(a) > get<1>(b))
1117 return false;
1118
1119 return get<2>(a) < get<2>(b);
1120 }
1121
932 } // namespace gcm 1122 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698