OLD | NEW |
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 Loading... |
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 Loading... |
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 ui_thread_->PostTask(FROM_HERE, |
163 base::Bind(&GCMDriverDesktop::UnregisterFinished, | 195 base::Bind(&GCMDriverDesktop::UnregisterFinished, |
164 service_, | 196 service_, |
165 app_id, | 197 registration_info->app_id, |
166 result)); | 198 result)); |
167 } | 199 } |
168 | 200 |
169 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, | 201 void GCMDriverDesktop::IOWorker::OnSendFinished(const std::string& app_id, |
170 const std::string& message_id, | 202 const std::string& message_id, |
171 GCMClient::Result result) { | 203 GCMClient::Result result) { |
172 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 204 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
173 | 205 |
174 ui_thread_->PostTask( | 206 ui_thread_->PostTask( |
175 FROM_HERE, | 207 FROM_HERE, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 295 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
264 | 296 |
265 gcm_client_->Stop(); | 297 gcm_client_->Stop(); |
266 } | 298 } |
267 | 299 |
268 void GCMDriverDesktop::IOWorker::Register( | 300 void GCMDriverDesktop::IOWorker::Register( |
269 const std::string& app_id, | 301 const std::string& app_id, |
270 const std::vector<std::string>& sender_ids) { | 302 const std::vector<std::string>& sender_ids) { |
271 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 303 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
272 | 304 |
273 gcm_client_->Register(app_id, sender_ids); | 305 scoped_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo); |
| 306 gcm_info->app_id = app_id; |
| 307 gcm_info->sender_ids = sender_ids; |
| 308 gcm_client_->Register(make_linked_ptr<RegistrationInfo>(gcm_info.release())); |
274 } | 309 } |
275 | 310 |
276 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { | 311 void GCMDriverDesktop::IOWorker::Unregister(const std::string& app_id) { |
277 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 312 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
278 | 313 |
279 gcm_client_->Unregister(app_id); | 314 scoped_ptr<GCMRegistrationInfo> gcm_info(new GCMRegistrationInfo); |
| 315 gcm_info->app_id = app_id; |
| 316 gcm_client_->Unregister( |
| 317 make_linked_ptr<RegistrationInfo>(gcm_info.release())); |
280 } | 318 } |
281 | 319 |
282 void GCMDriverDesktop::IOWorker::Send( | 320 void GCMDriverDesktop::IOWorker::Send( |
283 const std::string& app_id, | 321 const std::string& app_id, |
284 const std::string& receiver_id, | 322 const std::string& receiver_id, |
285 const GCMClient::OutgoingMessage& message) { | 323 const GCMClient::OutgoingMessage& message) { |
286 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 324 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
287 | 325 |
288 gcm_client_->Send(app_id, receiver_id, message); | 326 gcm_client_->Send(app_id, receiver_id, message); |
289 } | 327 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 382 |
345 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { | 383 void GCMDriverDesktop::IOWorker::SetLastTokenFetchTime(const base::Time& time) { |
346 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 384 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
347 | 385 |
348 if (gcm_client_.get()) | 386 if (gcm_client_.get()) |
349 gcm_client_->SetLastTokenFetchTime(time); | 387 gcm_client_->SetLastTokenFetchTime(time); |
350 } | 388 } |
351 | 389 |
352 void GCMDriverDesktop::IOWorker::AddInstanceIDData( | 390 void GCMDriverDesktop::IOWorker::AddInstanceIDData( |
353 const std::string& app_id, | 391 const std::string& app_id, |
354 const std::string& instance_id_data) { | 392 const std::string& instance_id, |
| 393 const std::string& extra_data) { |
355 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 394 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
356 | 395 |
357 if (gcm_client_.get()) | 396 if (gcm_client_.get()) |
358 gcm_client_->AddInstanceIDData(app_id, instance_id_data); | 397 gcm_client_->AddInstanceIDData(app_id, instance_id, extra_data); |
359 } | 398 } |
360 | 399 |
361 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData( | 400 void GCMDriverDesktop::IOWorker::RemoveInstanceIDData( |
362 const std::string& app_id) { | 401 const std::string& app_id) { |
363 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 402 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
364 | 403 |
365 if (gcm_client_.get()) | 404 if (gcm_client_.get()) |
366 gcm_client_->RemoveInstanceIDData(app_id); | 405 gcm_client_->RemoveInstanceIDData(app_id); |
367 } | 406 } |
368 | 407 |
369 void GCMDriverDesktop::IOWorker::GetInstanceIDData( | 408 void GCMDriverDesktop::IOWorker::GetInstanceIDData( |
370 const std::string& app_id) { | 409 const std::string& app_id) { |
371 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 410 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
372 | 411 |
373 std::string instance_id_data; | 412 std::string instance_id; |
| 413 std::string extra_data; |
374 if (gcm_client_.get()) | 414 if (gcm_client_.get()) |
375 instance_id_data = gcm_client_->GetInstanceIDData(app_id); | 415 gcm_client_->GetInstanceIDData(app_id, &instance_id, &extra_data); |
376 | 416 |
377 ui_thread_->PostTask( | 417 ui_thread_->PostTask( |
378 FROM_HERE, | 418 FROM_HERE, |
379 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, | 419 base::Bind(&GCMDriverDesktop::GetInstanceIDDataFinished, |
380 service_, app_id, instance_id_data)); | 420 service_, app_id, instance_id, extra_data)); |
| 421 } |
| 422 |
| 423 void GCMDriverDesktop::IOWorker::GetToken( |
| 424 const std::string& app_id, |
| 425 const std::string& authorized_entity, |
| 426 const std::string& scope, |
| 427 const std::map<std::string, std::string>& options) { |
| 428 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 429 |
| 430 scoped_ptr<InstanceIDTokenInfo> instance_id_token_info( |
| 431 new InstanceIDTokenInfo); |
| 432 instance_id_token_info->app_id = app_id; |
| 433 instance_id_token_info->authorized_entity = authorized_entity; |
| 434 instance_id_token_info->scope = scope; |
| 435 instance_id_token_info->options = options; |
| 436 gcm_client_->Register( |
| 437 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); |
| 438 } |
| 439 |
| 440 void GCMDriverDesktop::IOWorker::DeleteToken( |
| 441 const std::string& app_id, |
| 442 const std::string& authorized_entity, |
| 443 const std::string& scope) { |
| 444 scoped_ptr<InstanceIDTokenInfo> instance_id_token_info( |
| 445 new InstanceIDTokenInfo); |
| 446 instance_id_token_info->app_id = app_id; |
| 447 instance_id_token_info->authorized_entity = authorized_entity; |
| 448 instance_id_token_info->scope = scope; |
| 449 gcm_client_->Unregister( |
| 450 make_linked_ptr<RegistrationInfo>(instance_id_token_info.release())); |
381 } | 451 } |
382 | 452 |
383 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { | 453 void GCMDriverDesktop::IOWorker::WakeFromSuspendForHeartbeat(bool wake) { |
384 #if defined(OS_CHROMEOS) | 454 #if defined(OS_CHROMEOS) |
385 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 455 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
386 | 456 |
387 scoped_ptr<base::Timer> timer; | 457 scoped_ptr<base::Timer> timer; |
388 if (wake) | 458 if (wake) |
389 timer.reset(new timers::SimpleAlarmTimer()); | 459 timer.reset(new timers::SimpleAlarmTimer()); |
390 else | 460 else |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 771 |
702 last_token_fetch_time_ = time; | 772 last_token_fetch_time_ = time; |
703 | 773 |
704 io_thread_->PostTask( | 774 io_thread_->PostTask( |
705 FROM_HERE, | 775 FROM_HERE, |
706 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, | 776 base::Bind(&GCMDriverDesktop::IOWorker::SetLastTokenFetchTime, |
707 base::Unretained(io_worker_.get()), | 777 base::Unretained(io_worker_.get()), |
708 time)); | 778 time)); |
709 } | 779 } |
710 | 780 |
711 InstanceIDStore* GCMDriverDesktop::GetInstanceIDStore() { | 781 InstanceIDHandler* GCMDriverDesktop::GetInstanceIDHandler() { |
712 return this; | 782 return this; |
713 } | 783 } |
714 | 784 |
| 785 void GCMDriverDesktop::GetToken( |
| 786 const std::string& app_id, |
| 787 const std::string& authorized_entity, |
| 788 const std::string& scope, |
| 789 const std::map<std::string, std::string>& options, |
| 790 const GetTokenCallback& callback) { |
| 791 DCHECK(!app_id.empty()); |
| 792 DCHECK(!authorized_entity.empty()); |
| 793 DCHECK(!scope.empty()); |
| 794 DCHECK(!callback.is_null()); |
| 795 |
| 796 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
| 797 if (result != GCMClient::SUCCESS) { |
| 798 callback.Run(std::string(), result); |
| 799 return; |
| 800 } |
| 801 |
| 802 // If previous GetToken operation is still in progress, bail out. |
| 803 TokenTuple tuple_key(app_id, authorized_entity, scope); |
| 804 if (get_token_callbacks_.find(tuple_key) != get_token_callbacks_.end()) { |
| 805 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING); |
| 806 return; |
| 807 } |
| 808 |
| 809 get_token_callbacks_[tuple_key] = callback; |
| 810 |
| 811 io_thread_->PostTask( |
| 812 FROM_HERE, |
| 813 base::Bind(&GCMDriverDesktop::IOWorker::GetToken, |
| 814 base::Unretained(io_worker_.get()), |
| 815 app_id, |
| 816 authorized_entity, |
| 817 scope, |
| 818 options)); |
| 819 } |
| 820 |
| 821 void GCMDriverDesktop::DeleteToken(const std::string& app_id, |
| 822 const std::string& authorized_entity, |
| 823 const std::string& scope, |
| 824 const DeleteTokenCallback& callback) { |
| 825 DCHECK(!app_id.empty()); |
| 826 DCHECK(!authorized_entity.empty()); |
| 827 DCHECK(!scope.empty()); |
| 828 DCHECK(!callback.is_null()); |
| 829 |
| 830 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
| 831 if (result != GCMClient::SUCCESS) { |
| 832 callback.Run(result); |
| 833 return; |
| 834 } |
| 835 |
| 836 // If previous GetToken operation is still in progress, bail out. |
| 837 TokenTuple tuple_key(app_id, authorized_entity, scope); |
| 838 if (delete_token_callbacks_.find(tuple_key) != |
| 839 delete_token_callbacks_.end()) { |
| 840 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); |
| 841 return; |
| 842 } |
| 843 |
| 844 delete_token_callbacks_[tuple_key] = callback; |
| 845 |
| 846 io_thread_->PostTask( |
| 847 FROM_HERE, |
| 848 base::Bind(&GCMDriverDesktop::IOWorker::DeleteToken, |
| 849 base::Unretained(io_worker_.get()), |
| 850 app_id, |
| 851 authorized_entity, |
| 852 scope)); |
| 853 } |
| 854 |
715 void GCMDriverDesktop::AddInstanceIDData( | 855 void GCMDriverDesktop::AddInstanceIDData( |
716 const std::string& app_id, | 856 const std::string& app_id, |
717 const std::string& instance_id_data) { | 857 const std::string& instance_id, |
| 858 const std::string& extra_data) { |
718 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 859 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
719 | 860 |
720 io_thread_->PostTask( | 861 io_thread_->PostTask( |
721 FROM_HERE, | 862 FROM_HERE, |
722 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData, | 863 base::Bind(&GCMDriverDesktop::IOWorker::AddInstanceIDData, |
723 base::Unretained(io_worker_.get()), | 864 base::Unretained(io_worker_.get()), |
724 app_id, | 865 app_id, |
725 instance_id_data)); | 866 instance_id, |
| 867 extra_data)); |
726 } | 868 } |
727 | 869 |
728 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { | 870 void GCMDriverDesktop::RemoveInstanceIDData(const std::string& app_id) { |
729 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 871 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
730 | 872 |
731 io_thread_->PostTask( | 873 io_thread_->PostTask( |
732 FROM_HERE, | 874 FROM_HERE, |
733 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData, | 875 base::Bind(&GCMDriverDesktop::IOWorker::RemoveInstanceIDData, |
734 base::Unretained(io_worker_.get()), | 876 base::Unretained(io_worker_.get()), |
735 app_id)); | 877 app_id)); |
736 } | 878 } |
737 | 879 |
738 void GCMDriverDesktop::GetInstanceIDData( | 880 void GCMDriverDesktop::GetInstanceIDData( |
739 const std::string& app_id, | 881 const std::string& app_id, |
740 const GetInstanceIDDataCallback& callback) { | 882 const GetInstanceIDDataCallback& callback) { |
741 DCHECK(!get_instance_id_data_callbacks_.count(app_id)); | 883 DCHECK(!get_instance_id_data_callbacks_.count(app_id)); |
742 get_instance_id_data_callbacks_[app_id] = callback; | 884 get_instance_id_data_callbacks_[app_id] = callback; |
743 io_thread_->PostTask( | 885 io_thread_->PostTask( |
744 FROM_HERE, | 886 FROM_HERE, |
745 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData, | 887 base::Bind(&GCMDriverDesktop::IOWorker::GetInstanceIDData, |
746 base::Unretained(io_worker_.get()), | 888 base::Unretained(io_worker_.get()), |
747 app_id)); | 889 app_id)); |
748 } | 890 } |
749 | 891 |
750 void GCMDriverDesktop::GetInstanceIDDataFinished( | 892 void GCMDriverDesktop::GetInstanceIDDataFinished( |
751 const std::string& app_id, | 893 const std::string& app_id, |
752 const std::string& instance_id_data) { | 894 const std::string& instance_id, |
| 895 const std::string& extra_data) { |
753 DCHECK(get_instance_id_data_callbacks_.count(app_id)); | 896 DCHECK(get_instance_id_data_callbacks_.count(app_id)); |
754 get_instance_id_data_callbacks_[app_id].Run(instance_id_data); | 897 get_instance_id_data_callbacks_[app_id].Run(instance_id, extra_data); |
755 get_instance_id_data_callbacks_.erase(app_id); | 898 get_instance_id_data_callbacks_.erase(app_id); |
756 } | 899 } |
757 | 900 |
| 901 void GCMDriverDesktop::GetTokenFinished(const std::string& app_id, |
| 902 const std::string& authorized_entity, |
| 903 const std::string& scope, |
| 904 const std::string& token, |
| 905 GCMClient::Result result) { |
| 906 TokenTuple tuple_key(app_id, authorized_entity, scope); |
| 907 auto callback_iter = get_token_callbacks_.find(tuple_key); |
| 908 if (callback_iter == get_token_callbacks_.end()) { |
| 909 // The callback could have been removed when the app is uninstalled. |
| 910 return; |
| 911 } |
| 912 |
| 913 GetTokenCallback callback = callback_iter->second; |
| 914 get_token_callbacks_.erase(callback_iter); |
| 915 callback.Run(token, result); |
| 916 } |
| 917 |
| 918 void GCMDriverDesktop::DeleteTokenFinished(const std::string& app_id, |
| 919 const std::string& authorized_entity, |
| 920 const std::string& scope, |
| 921 GCMClient::Result result) { |
| 922 TokenTuple tuple_key(app_id, authorized_entity, scope); |
| 923 auto callback_iter = delete_token_callbacks_.find(tuple_key); |
| 924 if (callback_iter == delete_token_callbacks_.end()) { |
| 925 // The callback could have been removed when the app is uninstalled. |
| 926 return; |
| 927 } |
| 928 |
| 929 DeleteTokenCallback callback = callback_iter->second; |
| 930 delete_token_callbacks_.erase(callback_iter); |
| 931 callback.Run(result); |
| 932 } |
| 933 |
758 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { | 934 void GCMDriverDesktop::WakeFromSuspendForHeartbeat(bool wake) { |
759 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 935 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
760 | 936 |
761 wake_from_suspend_enabled_ = wake; | 937 wake_from_suspend_enabled_ = wake; |
762 | 938 |
763 // The GCM service has not been initialized. | 939 // The GCM service has not been initialized. |
764 if (!delayed_task_controller_) | 940 if (!delayed_task_controller_) |
765 return; | 941 return; |
766 | 942 |
767 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { | 943 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 const GCMClient::GCMStatistics& stats) { | 1155 const GCMClient::GCMStatistics& stats) { |
980 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1156 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
981 | 1157 |
982 // Normally request_gcm_statistics_callback_ would not be null. | 1158 // Normally request_gcm_statistics_callback_ would not be null. |
983 if (!request_gcm_statistics_callback_.is_null()) | 1159 if (!request_gcm_statistics_callback_.is_null()) |
984 request_gcm_statistics_callback_.Run(stats); | 1160 request_gcm_statistics_callback_.Run(stats); |
985 else | 1161 else |
986 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 1162 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
987 } | 1163 } |
988 | 1164 |
| 1165 bool GCMDriverDesktop::TokenTupleComparer::operator()( |
| 1166 const TokenTuple& a, const TokenTuple& b) const { |
| 1167 if (get<0>(a) < get<0>(b)) |
| 1168 return true; |
| 1169 if (get<0>(a) > get<0>(b)) |
| 1170 return false; |
| 1171 |
| 1172 if (get<1>(a) < get<1>(b)) |
| 1173 return true; |
| 1174 if (get<1>(a) > get<1>(b)) |
| 1175 return false; |
| 1176 |
| 1177 return get<2>(a) < get<2>(b); |
| 1178 } |
| 1179 |
989 } // namespace gcm | 1180 } // namespace gcm |
OLD | NEW |