| 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/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "components/gcm_driver/gcm_account_mapper.h" |
| 16 #include "components/gcm_driver/gcm_app_handler.h" | 17 #include "components/gcm_driver/gcm_app_handler.h" |
| 17 #include "components/gcm_driver/gcm_channel_status_syncer.h" | 18 #include "components/gcm_driver/gcm_channel_status_syncer.h" |
| 18 #include "components/gcm_driver/gcm_client_factory.h" | 19 #include "components/gcm_driver/gcm_client_factory.h" |
| 19 #include "components/gcm_driver/gcm_delayed_task_controller.h" | 20 #include "components/gcm_driver/gcm_delayed_task_controller.h" |
| 20 #include "components/gcm_driver/system_encryptor.h" | 21 #include "components/gcm_driver/system_encryptor.h" |
| 21 #include "google_apis/gcm/engine/account_mapping.h" | 22 #include "google_apis/gcm/engine/account_mapping.h" |
| 22 #include "net/base/ip_endpoint.h" | 23 #include "net/base/ip_endpoint.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 | 25 |
| 25 namespace gcm { | 26 namespace gcm { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 void CheckOut(); | 69 void CheckOut(); |
| 69 void Register(const std::string& app_id, | 70 void Register(const std::string& app_id, |
| 70 const std::vector<std::string>& sender_ids); | 71 const std::vector<std::string>& sender_ids); |
| 71 void Unregister(const std::string& app_id); | 72 void Unregister(const std::string& app_id); |
| 72 void Send(const std::string& app_id, | 73 void Send(const std::string& app_id, |
| 73 const std::string& receiver_id, | 74 const std::string& receiver_id, |
| 74 const GCMClient::OutgoingMessage& message); | 75 const GCMClient::OutgoingMessage& message); |
| 75 void GetGCMStatistics(bool clear_logs); | 76 void GetGCMStatistics(bool clear_logs); |
| 76 void SetGCMRecording(bool recording); | 77 void SetGCMRecording(bool recording); |
| 77 | 78 |
| 78 void SetAccountsForCheckin( | 79 void SetAccountTokens( |
| 79 const std::map<std::string, std::string>& account_tokens); | 80 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); |
| 80 void UpdateAccountMapping(const AccountMapping& account_mapping); | 81 void UpdateAccountMapping(const AccountMapping& account_mapping); |
| 81 void RemoveAccountMapping(const std::string& account_id); | 82 void RemoveAccountMapping(const std::string& account_id); |
| 82 | 83 |
| 83 // For testing purpose. Can be called from UI thread. Use with care. | 84 // For testing purpose. Can be called from UI thread. Use with care. |
| 84 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 85 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
| 85 | 86 |
| 86 private: | 87 private: |
| 87 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 88 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
| 88 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 89 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
| 89 | 90 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 gcm_client_->SetRecording(recording); | 300 gcm_client_->SetRecording(recording); |
| 300 stats = gcm_client_->GetStatistics(); | 301 stats = gcm_client_->GetStatistics(); |
| 301 stats.gcm_client_created = true; | 302 stats.gcm_client_created = true; |
| 302 } | 303 } |
| 303 | 304 |
| 304 ui_thread_->PostTask( | 305 ui_thread_->PostTask( |
| 305 FROM_HERE, | 306 FROM_HERE, |
| 306 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); | 307 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); |
| 307 } | 308 } |
| 308 | 309 |
| 309 void GCMDriverDesktop::IOWorker::SetAccountsForCheckin( | 310 void GCMDriverDesktop::IOWorker::SetAccountTokens( |
| 310 const std::map<std::string, std::string>& account_tokens) { | 311 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { |
| 311 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 312 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 312 | 313 |
| 313 if (gcm_client_.get()) | 314 if (gcm_client_.get()) |
| 314 gcm_client_->SetAccountsForCheckin(account_tokens); | 315 gcm_client_->SetAccountTokens(account_tokens); |
| 315 } | 316 } |
| 316 | 317 |
| 317 void GCMDriverDesktop::IOWorker::UpdateAccountMapping( | 318 void GCMDriverDesktop::IOWorker::UpdateAccountMapping( |
| 318 const AccountMapping& account_mapping) { | 319 const AccountMapping& account_mapping) { |
| 319 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 320 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 320 | 321 |
| 321 if (gcm_client_.get()) | 322 if (gcm_client_.get()) |
| 322 gcm_client_->UpdateAccountMapping(account_mapping); | 323 gcm_client_->UpdateAccountMapping(account_mapping); |
| 323 } | 324 } |
| 324 | 325 |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { | 608 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { |
| 608 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 609 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 609 | 610 |
| 610 io_thread_->PostTask( | 611 io_thread_->PostTask( |
| 611 FROM_HERE, | 612 FROM_HERE, |
| 612 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, | 613 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, |
| 613 base::Unretained(io_worker_.get()), | 614 base::Unretained(io_worker_.get()), |
| 614 account_id)); | 615 account_id)); |
| 615 } | 616 } |
| 616 | 617 |
| 617 void GCMDriverDesktop::SetAccountsForCheckin( | 618 void GCMDriverDesktop::SetAccountTokens( |
| 618 const std::map<std::string, std::string>& account_tokens) { | 619 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) { |
| 619 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 620 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 620 | 621 |
| 621 io_thread_->PostTask( | 622 io_thread_->PostTask( |
| 622 FROM_HERE, | 623 FROM_HERE, |
| 623 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountsForCheckin, | 624 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountTokens, |
| 624 base::Unretained(io_worker_.get()), | 625 base::Unretained(io_worker_.get()), |
| 625 account_tokens)); | 626 account_tokens)); |
| 626 } | 627 } |
| 627 | 628 |
| 628 GCMClient::Result GCMDriverDesktop::EnsureStarted() { | 629 GCMClient::Result GCMDriverDesktop::EnsureStarted() { |
| 629 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 630 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 630 | 631 |
| 631 if (gcm_started_) | 632 if (gcm_started_) |
| 632 return GCMClient::SUCCESS; | 633 return GCMClient::SUCCESS; |
| 633 | 634 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 | 758 |
| 758 // Normally request_gcm_statistics_callback_ would not be null. | 759 // Normally request_gcm_statistics_callback_ would not be null. |
| 759 if (!request_gcm_statistics_callback_.is_null()) | 760 if (!request_gcm_statistics_callback_.is_null()) |
| 760 request_gcm_statistics_callback_.Run(stats); | 761 request_gcm_statistics_callback_.Run(stats); |
| 761 else | 762 else |
| 762 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 763 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
| 763 } | 764 } |
| 764 | 765 |
| 765 } // namespace gcm | 766 } // namespace gcm |
| 766 | 767 |
| OLD | NEW |