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

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: Patch to land Created 5 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 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 22 matching lines...) Expand all
80 const GCMClient::OutgoingMessage& message); 82 const GCMClient::OutgoingMessage& message);
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,
91 const std::string& instance_id_data);
92 void RemoveInstanceIDData(const std::string& app_id);
93 void GetInstanceIDData(const std::string& app_id);
94 void AddHeartbeatInterval(const std::string& scope, int interval_ms); 92 void AddHeartbeatInterval(const std::string& scope, int interval_ms);
95 void RemoveHeartbeatInterval(const std::string& scope); 93 void RemoveHeartbeatInterval(const std::string& scope);
96 94
95 void AddInstanceIDData(const std::string& app_id,
96 const std::string& instance_id,
97 const std::string& extra_data);
98 void RemoveInstanceIDData(const std::string& app_id);
99 void GetInstanceIDData(const std::string& app_id);
100 void GetToken(const std::string& app_id,
101 const std::string& authorized_entity,
102 const std::string& scope,
103 const std::map<std::string, std::string>& options);
104 void DeleteToken(const std::string& app_id,
105 const std::string& authorized_entity,
106 const std::string& scope);
107
97 // For testing purpose. Can be called from UI thread. Use with care. 108 // For testing purpose. Can be called from UI thread. Use with care.
98 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 109 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
99 110
100 private: 111 private:
101 scoped_refptr<base::SequencedTaskRunner> ui_thread_; 112 scoped_refptr<base::SequencedTaskRunner> ui_thread_;
102 scoped_refptr<base::SequencedTaskRunner> io_thread_; 113 scoped_refptr<base::SequencedTaskRunner> io_thread_;
103 114
104 base::WeakPtr<GCMDriverDesktop> service_; 115 base::WeakPtr<GCMDriverDesktop> service_;
105 116
106 scoped_ptr<GCMClient> gcm_client_; 117 scoped_ptr<GCMClient> gcm_client_;
(...skipping 29 matching lines...) Expand all
136 147
137 gcm_client_->Initialize(chrome_build_info, 148 gcm_client_->Initialize(chrome_build_info,
138 store_path, 149 store_path,
139 blocking_task_runner, 150 blocking_task_runner,
140 request_context, 151 request_context,
141 make_scoped_ptr<Encryptor>(new SystemEncryptor), 152 make_scoped_ptr<Encryptor>(new SystemEncryptor),
142 this); 153 this);
143 } 154 }
144 155
145 void GCMDriverDesktop::IOWorker::OnRegisterFinished( 156 void GCMDriverDesktop::IOWorker::OnRegisterFinished(
146 const std::string& app_id, 157 const linked_ptr<RegistrationInfo>& registration_info,
147 const std::string& registration_id, 158 const std::string& registration_id,
148 GCMClient::Result result) { 159 GCMClient::Result result) {
149 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 160 DCHECK(io_thread_->RunsTasksOnCurrentThread());
150 161
151 ui_thread_->PostTask( 162 const GCMRegistrationInfo* gcm_registration_info =
163 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
164 if (gcm_registration_info) {
165 ui_thread_->PostTask(
166 FROM_HERE,
167 base::Bind(&GCMDriverDesktop::RegisterFinished,
168 service_,
169 gcm_registration_info->app_id,
170 registration_id,
171 result));
172 }
173
174 const InstanceIDTokenInfo* instance_id_token_info =
175 InstanceIDTokenInfo::FromRegistrationInfo(registration_info.get());
176 if (instance_id_token_info) {
177 ui_thread_->PostTask(
152 FROM_HERE, 178 FROM_HERE,
153 base::Bind(&GCMDriverDesktop::RegisterFinished, service_, app_id, 179 base::Bind(&GCMDriverDesktop::GetTokenFinished,
154 registration_id, result)); 180 service_,
181 instance_id_token_info->app_id,
182 instance_id_token_info->authorized_entity,
183 instance_id_token_info->scope,
184 registration_id,
185 result));
186 }
155 } 187 }
156 188
157 void GCMDriverDesktop::IOWorker::OnUnregisterFinished( 189 void GCMDriverDesktop::IOWorker::OnUnregisterFinished(
158 const std::string& app_id, 190 const linked_ptr<RegistrationInfo>& registration_info,
159 GCMClient::Result result) { 191 GCMClient::Result result) {
160 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 192 DCHECK(io_thread_->RunsTasksOnCurrentThread());
161 193
162 ui_thread_->PostTask(FROM_HERE, 194 const GCMRegistrationInfo* gcm_registration_info =
163 base::Bind(&GCMDriverDesktop::UnregisterFinished, 195 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get());
164 service_, 196 if (gcm_registration_info) {
165 app_id, 197 ui_thread_->PostTask(
166 result)); 198 FROM_HERE,
199 base::Bind(&GCMDriverDesktop::UnregisterFinished,
200 service_,
201 gcm_registration_info->app_id,
202 result));
203 }
204
205 const InstanceIDTokenInfo* instance_id_token_info =
206 InstanceIDTokenInfo::FromRegistrationInfo(registration_info.get());
207 if (instance_id_token_info) {
208 ui_thread_->PostTask(
209 FROM_HERE,
210 base::Bind(&GCMDriverDesktop::DeleteTokenFinished,
211 service_,
212 instance_id_token_info->app_id,
213 instance_id_token_info->authorized_entity,
214 instance_id_token_info->scope,
215 result));
216 }
167 } 217 }
168 218
169 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, 219 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id,
170 const std::string& message_id, 220 const std::string& message_id,
171 GCMClient::Result result) { 221 GCMClient::Result result) {
172 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 222 DCHECK(io_thread_->RunsTasksOnCurrentThread());
173 223
174 ui_thread_->PostTask( 224 ui_thread_->PostTask(
175 FROM_HERE, 225 FROM_HERE,
176 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id, 226 base::Bind(&GCMDriverDesktop::SendFinished, service_, app_id, message_id,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 313 DCHECK(io_thread_->RunsTasksOnCurrentThread());
264 314
265 gcm_client_->Stop(); 315 gcm_client_->Stop();
266 } 316 }
267 317
268 void GCMDriverDesktop::IOWorker::Register( 318 void GCMDriverDesktop::IOWorker::Register(
269 const std::string& app_id, 319 const std::string& app_id,
270 const std::vector<std::string>& sender_ids) { 320 const std::vector<std::string>& sender_ids) {
271 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 321 DCHECK(io_thread_->RunsTasksOnCurrentThread());
272 322
273 gcm_client_->Register(app_id, sender_ids); 323 scoped_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
324 gcm_info->app_id = app_id;
325 gcm_info->sender_ids = sender_ids;
326 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release()));
274 } 327 }
275 328
276 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { 329 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) {
277 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 330 DCHECK(io_thread_->RunsTasksOnCurrentThread());
278 331
279 gcm_client_->Unregister(app_id); 332 scoped_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo);
333 gcm_info->app_id = app_id;
334 gcm_client_->Unregister(
335 make_linked_ptr<RegistrationInfo>(gcm_info.release()));
280 } 336 }
281 337
282 void GCMDriverDesktop::IOWorker::Send( 338 void GCMDriverDesktop::IOWorker::Send(
283 const std::string& app_id, 339 const std::string& app_id,
284 const std::string& receiver_id, 340 const std::string& receiver_id,
285 const GCMClient::OutgoingMessage& message) { 341 const GCMClient::OutgoingMessage& message) {
286 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 342 DCHECK(io_thread_->RunsTasksOnCurrentThread());
287 343
288 gcm_client_->Send(app_id, receiver_id, message); 344 gcm_client_->Send(app_id, receiver_id, message);
289 } 345 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 400
345 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { 401 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) {
346 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 402 DCHECK(io_thread_->RunsTasksOnCurrentThread());
347 403
348 if (gcm_client_.get()) 404 if (gcm_client_.get())
349 gcm_client_->SetLastTokenFetchTime(time); 405 gcm_client_->SetLastTokenFetchTime(time);
350 } 406 }
351 407
352 void GCMDriverDesktop::IOWorker::AddInstanceIDData( 408 void GCMDriverDesktop::IOWorker::AddInstanceIDData(
353 const std::string& app_id, 409 const std::string& app_id,
354 const std::string& instance_id_data) { 410 const std::string& instance_id,
411 const std::string& extra_data) {
355 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 412 DCHECK(io_thread_->RunsTasksOnCurrentThread());
356 413
357 if (gcm_client_.get()) 414 if (gcm_client_.get())
358 gcm_client_->AddInstanceIDData(app_id, instance_id_data); 415 gcm_client_->AddInstanceIDData(app_id, instance_id, extra_data);
359 } 416 }
360 417
361 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData( 418 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData(
362 const std::string& app_id) { 419 const std::string& app_id) {
363 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 420 DCHECK(io_thread_->RunsTasksOnCurrentThread());
364 421
365 if (gcm_client_.get()) 422 if (gcm_client_.get())
366 gcm_client_->RemoveInstanceIDData(app_id); 423 gcm_client_->RemoveInstanceIDData(app_id);
367 } 424 }
368 425
369 void GCMDriverDesktop::IOWorker::GetInstanceIDData( 426 void GCMDriverDesktop::IOWorker::GetInstanceIDData(
370 const std::string& app_id) { 427 const std::string& app_id) {
371 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 428 DCHECK(io_thread_->RunsTasksOnCurrentThread());
372 429
373 std::string instance_id_data; 430 std::string instance_id;
431 std::string extra_data;
374 if (gcm_client_.get()) 432 if (gcm_client_.get())
375 instance_id_data = gcm_client_->GetInstanceIDData(app_id); 433 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data);
376 434
377 ui_thread_->PostTask( 435 ui_thread_->PostTask(
378 FROM_HERE, 436 FROM_HERE,
379 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, 437 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished,
380 service_, app_id, instance_id_data)); 438 service_, app_id, instance_id, extra_data));
439 }
440
441 void GCMDriverDesktop::IOWorker::GetToken(
442 const std::string& app_id,
443 const std::string& authorized_entity,
444 const std::string& scope,
445 const std::map<std::string, std::string>& options) {
446 DCHECK(io_thread_->RunsTasksOnCurrentThread());
447
448 scoped_ptr<InstanceIDTokenInfo> instance_id_token_info(
449 new InstanceIDTokenInfo);
450 instance_id_token_info->app_id = app_id;
451 instance_id_token_info->authorized_entity = authorized_entity;
452 instance_id_token_info->scope = scope;
453 instance_id_token_info->options = options;
454 gcm_client_->Register(
455 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release()));
456 }
457
458 void GCMDriverDesktop::IOWorker::DeleteToken(
459 const std::string& app_id,
460 const std::string& authorized_entity,
461 const std::string& scope) {
462 scoped_ptr<InstanceIDTokenInfo> instance_id_token_info(
463 new InstanceIDTokenInfo);
464 instance_id_token_info->app_id = app_id;
465 instance_id_token_info->authorized_entity = authorized_entity;
466 instance_id_token_info->scope = scope;
467 gcm_client_->Unregister(
468 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release()));
381 } 469 }
382 470
383 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { 471 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) {
384 #if defined(OS_CHROMEOS) 472 #if defined(OS_CHROMEOS)
385 DCHECK(io_thread_->RunsTasksOnCurrentThread()); 473 DCHECK(io_thread_->RunsTasksOnCurrentThread());
386 474
387 scoped_ptr<base::Timer> timer; 475 scoped_ptr<base::Timer> timer;
388 if (wake) 476 if (wake)
389 timer.reset(new timers::SimpleAlarmTimer()); 477 timer.reset(new timers::SimpleAlarmTimer());
390 else 478 else
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 789
702 last_token_fetch_time_ = time; 790 last_token_fetch_time_ = time;
703 791
704 io_thread_->PostTask( 792 io_thread_->PostTask(
705 FROM_HERE, 793 FROM_HERE,
706 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, 794 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime,
707 base::Unretained(io_worker_.get()), 795 base::Unretained(io_worker_.get()),
708 time)); 796 time));
709 } 797 }
710 798
711 InstanceIDStore* GCMDriverDesktop::GetInstanceIDStore() { 799 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandler() {
712 return this; 800 return this;
713 } 801 }
714 802
803 void GCMDriverDesktop::GetToken(
804 const std::string& app_id,
805 const std::string& authorized_entity,
806 const std::string& scope,
807 const std::map<std::string, std::string>& options,
808 const GetTokenCallback& callback) {
809 DCHECK(!app_id.empty());
810 DCHECK(!authorized_entity.empty());
811 DCHECK(!scope.empty());
812 DCHECK(!callback.is_null());
813
814 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
815 if (result != GCMClient::SUCCESS) {
816 callback.Run(std::string(), result);
817 return;
818 }
819
820 // If previous GetToken operation is still in progress, bail out.
821 TokenTuple tuple_key(app_id, authorized_entity, scope);
822 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) {
823 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING);
824 return;
825 }
826
827 get_token_callbacks_[tuple_key] = callback;
828
829 io_thread_->PostTask(
830 FROM_HERE,
831 base::Bind(&GCMDriverDesktop::IOWorker::GetToken,
832 base::Unretained(io_worker_.get()),
833 app_id,
834 authorized_entity,
835 scope,
836 options));
837 }
838
839 void GCMDriverDesktop::DeleteToken(const std::string& app_id,
840 const std::string& authorized_entity,
841 const std::string& scope,
842 const DeleteTokenCallback& callback) {
843 DCHECK(!app_id.empty());
844 DCHECK(!authorized_entity.empty());
845 DCHECK(!scope.empty());
846 DCHECK(!callback.is_null());
847
848 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START);
849 if (result != GCMClient::SUCCESS) {
850 callback.Run(result);
851 return;
852 }
853
854 // If previous GetToken operation is still in progress, bail out.
855 TokenTuple tuple_key(app_id, authorized_entity, scope);
856 if (delete_token_callbacks_.find(tuple_key) !=
857 delete_token_callbacks_.end()) {
858 callback.Run(GCMClient::ASYNC_OPERATION_PENDING);
859 return;
860 }
861
862 delete_token_callbacks_[tuple_key] = callback;
863
864 io_thread_->PostTask(
865 FROM_HERE,
866 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken,
867 base::Unretained(io_worker_.get()),
868 app_id,
869 authorized_entity,
870 scope));
871 }
872
715 void GCMDriverDesktop::AddInstanceIDData( 873 void GCMDriverDesktop::AddInstanceIDData(
716 const std::string& app_id, 874 const std::string& app_id,
717 const std::string& instance_id_data) { 875 const std::string& instance_id,
876 const std::string& extra_data) {
718 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 877 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
719 878
720 io_thread_->PostTask( 879 io_thread_->PostTask(
721 FROM_HERE, 880 FROM_HERE,
722 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData, 881 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData,
723 base::Unretained(io_worker_.get()), 882 base::Unretained(io_worker_.get()),
724 app_id, 883 app_id,
725 instance_id_data)); 884 instance_id,
885 extra_data));
726 } 886 }
727 887
728 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { 888 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) {
729 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 889 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
730 890
731 io_thread_->PostTask( 891 io_thread_->PostTask(
732 FROM_HERE, 892 FROM_HERE,
733 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData, 893 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData,
734 base::Unretained(io_worker_.get()), 894 base::Unretained(io_worker_.get()),
735 app_id)); 895 app_id));
736 } 896 }
737 897
738 void GCMDriverDesktop::GetInstanceIDData( 898 void GCMDriverDesktop::GetInstanceIDData(
739 const std::string& app_id, 899 const std::string& app_id,
740 const GetInstanceIDDataCallback& callback) { 900 const GetInstanceIDDataCallback& callback) {
741 DCHECK(!get_instance_id_data_callbacks_.count(app_id)); 901 DCHECK(!get_instance_id_data_callbacks_.count(app_id));
742 get_instance_id_data_callbacks_[app_id] = callback; 902 get_instance_id_data_callbacks_[app_id] = callback;
743 io_thread_->PostTask( 903 io_thread_->PostTask(
744 FROM_HERE, 904 FROM_HERE,
745 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData, 905 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData,
746 base::Unretained(io_worker_.get()), 906 base::Unretained(io_worker_.get()),
747 app_id)); 907 app_id));
748 } 908 }
749 909
750 void GCMDriverDesktop::GetInstanceIDDataFinished( 910 void GCMDriverDesktop::GetInstanceIDDataFinished(
751 const std::string& app_id, 911 const std::string& app_id,
752 const std::string& instance_id_data) { 912 const std::string& instance_id,
913 const std::string& extra_data) {
753 DCHECK(get_instance_id_data_callbacks_.count(app_id)); 914 DCHECK(get_instance_id_data_callbacks_.count(app_id));
754 get_instance_id_data_callbacks_[app_id].Run(instance_id_data); 915 get_instance_id_data_callbacks_[app_id].Run(instance_id, extra_data);
755 get_instance_id_data_callbacks_.erase(app_id); 916 get_instance_id_data_callbacks_.erase(app_id);
756 } 917 }
757 918
919 void GCMDriverDesktop::GetTokenFinished(const std::string& app_id,
920 const std::string& authorized_entity,
921 const std::string& scope,
922 const std::string& token,
923 GCMClient::Result result) {
924 TokenTuple tuple_key(app_id, authorized_entity, scope);
925 auto callback_iter = get_token_callbacks_.find(tuple_key);
926 if (callback_iter == get_token_callbacks_.end()) {
927 // The callback could have been removed when the app is uninstalled.
928 return;
929 }
930
931 GetTokenCallback callback = callback_iter->second;
932 get_token_callbacks_.erase(callback_iter);
933 callback.Run(token, result);
934 }
935
936 void GCMDriverDesktop::DeleteTokenFinished(const std::string& app_id,
937 const std::string& authorized_entity,
938 const std::string& scope,
939 GCMClient::Result result) {
940 TokenTuple tuple_key(app_id, authorized_entity, scope);
941 auto callback_iter = delete_token_callbacks_.find(tuple_key);
942 if (callback_iter == delete_token_callbacks_.end()) {
943 // The callback could have been removed when the app is uninstalled.
944 return;
945 }
946
947 DeleteTokenCallback callback = callback_iter->second;
948 delete_token_callbacks_.erase(callback_iter);
949 callback.Run(result);
950 }
951
758 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { 952 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) {
759 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 953 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
760 954
761 wake_from_suspend_enabled_ = wake; 955 wake_from_suspend_enabled_ = wake;
762 956
763 // The GCM service has not been initialized. 957 // The GCM service has not been initialized.
764 if (!delayed_task_controller_) 958 if (!delayed_task_controller_)
765 return; 959 return;
766 960
767 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 961 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 const GCMClient::GCMStatistics& stats) { 1173 const GCMClient::GCMStatistics& stats) {
980 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 1174 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
981 1175
982 // Normally request_gcm_statistics_callback_ would not be null. 1176 // Normally request_gcm_statistics_callback_ would not be null.
983 if (!request_gcm_statistics_callback_.is_null()) 1177 if (!request_gcm_statistics_callback_.is_null())
984 request_gcm_statistics_callback_.Run(stats); 1178 request_gcm_statistics_callback_.Run(stats);
985 else 1179 else
986 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 1180 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
987 } 1181 }
988 1182
1183 bool GCMDriverDesktop::TokenTupleComparer::operator()(
1184 const TokenTuple& a, const TokenTuple& b) const {
1185 if (get<0>(a) < get<0>(b))
1186 return true;
1187 if (get<0>(a) > get<0>(b))
1188 return false;
1189
1190 if (get<1>(a) < get<1>(b))
1191 return true;
1192 if (get<1>(a) > get<1>(b))
1193 return false;
1194
1195 return get<2>(a) < get<2>(b);
1196 }
1197
989 } // namespace gcm 1198 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.h ('k') | components/gcm_driver/gcm_stats_recorder_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698