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" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 void CheckOut(); | 125 void CheckOut(); |
126 void Register(const std::string& app_id, | 126 void Register(const std::string& app_id, |
127 const std::vector<std::string>& sender_ids); | 127 const std::vector<std::string>& sender_ids); |
128 void Unregister(const std::string& app_id); | 128 void Unregister(const std::string& app_id); |
129 void Send(const std::string& app_id, | 129 void Send(const std::string& app_id, |
130 const std::string& receiver_id, | 130 const std::string& receiver_id, |
131 const GCMClient::OutgoingMessage& message); | 131 const GCMClient::OutgoingMessage& message); |
132 void GetGCMStatistics(bool clear_logs); | 132 void GetGCMStatistics(bool clear_logs); |
133 void SetGCMRecording(bool recording); | 133 void SetGCMRecording(bool recording); |
134 | 134 |
| 135 void SetAccountsForCheckin( |
| 136 const std::map<std::string, std::string>& account_tokens); |
| 137 |
135 // For testing purpose. Can be called from UI thread. Use with care. | 138 // For testing purpose. Can be called from UI thread. Use with care. |
136 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 139 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
137 | 140 |
138 private: | 141 private: |
139 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 142 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
140 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 143 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
141 | 144 |
142 base::WeakPtr<GCMDriverDesktop> service_; | 145 base::WeakPtr<GCMDriverDesktop> service_; |
143 | 146 |
144 scoped_ptr<GCMClient> gcm_client_; | 147 scoped_ptr<GCMClient> gcm_client_; |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 gcm_client_->SetRecording(recording); | 341 gcm_client_->SetRecording(recording); |
339 stats = gcm_client_->GetStatistics(); | 342 stats = gcm_client_->GetStatistics(); |
340 stats.gcm_client_created = true; | 343 stats.gcm_client_created = true; |
341 } | 344 } |
342 | 345 |
343 ui_thread_->PostTask( | 346 ui_thread_->PostTask( |
344 FROM_HERE, | 347 FROM_HERE, |
345 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); | 348 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); |
346 } | 349 } |
347 | 350 |
| 351 void GCMDriverDesktop::IOWorker::SetAccountsForCheckin( |
| 352 const std::map<std::string, std::string>& account_tokens) { |
| 353 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 354 |
| 355 if (gcm_client_.get()) |
| 356 gcm_client_->SetAccountsForCheckin(account_tokens); |
| 357 } |
| 358 |
348 GCMDriverDesktop::GCMDriverDesktop( | 359 GCMDriverDesktop::GCMDriverDesktop( |
349 scoped_ptr<GCMClientFactory> gcm_client_factory, | 360 scoped_ptr<GCMClientFactory> gcm_client_factory, |
350 const GCMClient::ChromeBuildInfo& chrome_build_info, | 361 const GCMClient::ChromeBuildInfo& chrome_build_info, |
351 const base::FilePath& store_path, | 362 const base::FilePath& store_path, |
352 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 363 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
353 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 364 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
354 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 365 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
355 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) | 366 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) |
356 : signed_in_(false), | 367 : signed_in_(false), |
357 gcm_started_(false), | 368 gcm_started_(false), |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 585 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
575 | 586 |
576 request_gcm_statistics_callback_ = callback; | 587 request_gcm_statistics_callback_ = callback; |
577 io_thread_->PostTask( | 588 io_thread_->PostTask( |
578 FROM_HERE, | 589 FROM_HERE, |
579 base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording, | 590 base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording, |
580 base::Unretained(io_worker_.get()), | 591 base::Unretained(io_worker_.get()), |
581 recording)); | 592 recording)); |
582 } | 593 } |
583 | 594 |
| 595 void GCMDriverDesktop::SetAccountsForCheckin( |
| 596 const std::map<std::string, std::string>& account_tokens) { |
| 597 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 598 |
| 599 io_thread_->PostTask( |
| 600 FROM_HERE, |
| 601 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountsForCheckin, |
| 602 base::Unretained(io_worker_.get()), |
| 603 account_tokens)); |
| 604 } |
| 605 |
584 GCMClient::Result GCMDriverDesktop::EnsureStarted() { | 606 GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
585 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 607 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
586 | 608 |
587 if (gcm_started_) | 609 if (gcm_started_) |
588 return GCMClient::SUCCESS; | 610 return GCMClient::SUCCESS; |
589 | 611 |
590 if (!gcm_enabled_) | 612 if (!gcm_enabled_) |
591 return GCMClient::GCM_DISABLED; | 613 return GCMClient::GCM_DISABLED; |
592 | 614 |
593 // Have any app requested the service? | 615 // Have any app requested the service? |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 728 |
707 // Normally request_gcm_statistics_callback_ would not be null. | 729 // Normally request_gcm_statistics_callback_ would not be null. |
708 if (!request_gcm_statistics_callback_.is_null()) | 730 if (!request_gcm_statistics_callback_.is_null()) |
709 request_gcm_statistics_callback_.Run(stats); | 731 request_gcm_statistics_callback_.Run(stats); |
710 else | 732 else |
711 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 733 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
712 } | 734 } |
713 | 735 |
714 } // namespace gcm | 736 } // namespace gcm |
715 | 737 |
OLD | NEW |