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