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_app_handler.h" | 16 #include "components/gcm_driver/gcm_app_handler.h" |
17 #include "components/gcm_driver/gcm_client_factory.h" | 17 #include "components/gcm_driver/gcm_client_factory.h" |
18 #include "components/gcm_driver/system_encryptor.h" | 18 #include "components/gcm_driver/system_encryptor.h" |
19 #include "google_apis/gcm/engine/account_mapping.h" | |
19 #include "net/base/ip_endpoint.h" | 20 #include "net/base/ip_endpoint.h" |
20 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
21 | 22 |
22 namespace gcm { | 23 namespace gcm { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 // Empty string is reserved for the default app handler. | 27 // Empty string is reserved for the default app handler. |
27 const char kDefaultAppHandler[] = ""; | 28 const char kDefaultAppHandler[] = ""; |
28 | 29 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 const std::vector<std::string>& sender_ids); | 130 const std::vector<std::string>& sender_ids); |
130 void Unregister(const std::string& app_id); | 131 void Unregister(const std::string& app_id); |
131 void Send(const std::string& app_id, | 132 void Send(const std::string& app_id, |
132 const std::string& receiver_id, | 133 const std::string& receiver_id, |
133 const GCMClient::OutgoingMessage& message); | 134 const GCMClient::OutgoingMessage& message); |
134 void GetGCMStatistics(bool clear_logs); | 135 void GetGCMStatistics(bool clear_logs); |
135 void SetGCMRecording(bool recording); | 136 void SetGCMRecording(bool recording); |
136 | 137 |
137 void SetAccountsForCheckin( | 138 void SetAccountsForCheckin( |
138 const std::map<std::string, std::string>& account_tokens); | 139 const std::map<std::string, std::string>& account_tokens); |
140 void UpdateAccountMapping(const AccountMapping& account_mapping); | |
141 void RemoveAccountMapping(const std::string& account_id); | |
139 | 142 |
140 // For testing purpose. Can be called from UI thread. Use with care. | 143 // For testing purpose. Can be called from UI thread. Use with care. |
141 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } | 144 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } |
142 | 145 |
143 private: | 146 private: |
144 scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 147 scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
145 scoped_refptr<base::SequencedTaskRunner> io_thread_; | 148 scoped_refptr<base::SequencedTaskRunner> io_thread_; |
146 | 149 |
147 base::WeakPtr<GCMDriverDesktop> service_; | 150 base::WeakPtr<GCMDriverDesktop> service_; |
148 | 151 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 } | 365 } |
363 | 366 |
364 void GCMDriverDesktop::IOWorker::SetAccountsForCheckin( | 367 void GCMDriverDesktop::IOWorker::SetAccountsForCheckin( |
365 const std::map<std::string, std::string>& account_tokens) { | 368 const std::map<std::string, std::string>& account_tokens) { |
366 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 369 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
367 | 370 |
368 if (gcm_client_.get()) | 371 if (gcm_client_.get()) |
369 gcm_client_->SetAccountsForCheckin(account_tokens); | 372 gcm_client_->SetAccountsForCheckin(account_tokens); |
370 } | 373 } |
371 | 374 |
375 void GCMDriverDesktop::IOWorker::UpdateAccountMapping( | |
376 const AccountMapping& account_mapping) { | |
377 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | |
378 | |
379 if (gcm_client_.get()) | |
Nicolas Zea
2014/08/11 18:21:05
Shouldn't we always have a gcm_client_ at this poi
fgorski
2014/08/20 18:29:06
It shouldn't be after Initialize was called. I am
| |
380 gcm_client_->UpdateAccountMapping(account_mapping); | |
381 } | |
382 | |
383 void GCMDriverDesktop::IOWorker::RemoveAccountMapping( | |
384 const std::string& account_id) { | |
385 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | |
386 | |
387 if (gcm_client_.get()) | |
388 gcm_client_->RemoveAccountMapping(account_id); | |
389 } | |
390 | |
372 GCMDriverDesktop::GCMDriverDesktop( | 391 GCMDriverDesktop::GCMDriverDesktop( |
373 scoped_ptr<GCMClientFactory> gcm_client_factory, | 392 scoped_ptr<GCMClientFactory> gcm_client_factory, |
374 const GCMClient::ChromeBuildInfo& chrome_build_info, | 393 const GCMClient::ChromeBuildInfo& chrome_build_info, |
375 const base::FilePath& store_path, | 394 const base::FilePath& store_path, |
376 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 395 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
377 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 396 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
378 const scoped_refptr<base::SequencedTaskRunner>& io_thread, | 397 const scoped_refptr<base::SequencedTaskRunner>& io_thread, |
379 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) | 398 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner) |
380 : signed_in_(false), | 399 : signed_in_(false), |
381 gcm_started_(false), | 400 gcm_started_(false), |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 617 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
599 | 618 |
600 request_gcm_statistics_callback_ = callback; | 619 request_gcm_statistics_callback_ = callback; |
601 io_thread_->PostTask( | 620 io_thread_->PostTask( |
602 FROM_HERE, | 621 FROM_HERE, |
603 base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording, | 622 base::Bind(&GCMDriverDesktop::IOWorker::SetGCMRecording, |
604 base::Unretained(io_worker_.get()), | 623 base::Unretained(io_worker_.get()), |
605 recording)); | 624 recording)); |
606 } | 625 } |
607 | 626 |
627 void GCMDriverDesktop::UpdateAccountMapping( | |
628 const AccountMapping& account_mapping) { | |
629 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | |
630 | |
631 io_thread_->PostTask( | |
632 FROM_HERE, | |
633 base::Bind(&GCMDriverDesktop::IOWorker::UpdateAccountMapping, | |
634 base::Unretained(io_worker_.get()), | |
635 account_mapping)); | |
636 } | |
637 | |
638 void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) { | |
639 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | |
640 | |
641 io_thread_->PostTask( | |
642 FROM_HERE, | |
643 base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping, | |
644 base::Unretained(io_worker_.get()), | |
645 account_id)); | |
646 } | |
647 | |
608 void GCMDriverDesktop::SetAccountsForCheckin( | 648 void GCMDriverDesktop::SetAccountsForCheckin( |
609 const std::map<std::string, std::string>& account_tokens) { | 649 const std::map<std::string, std::string>& account_tokens) { |
610 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 650 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
611 | 651 |
612 io_thread_->PostTask( | 652 io_thread_->PostTask( |
613 FROM_HERE, | 653 FROM_HERE, |
614 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountsForCheckin, | 654 base::Bind(&GCMDriverDesktop::IOWorker::SetAccountsForCheckin, |
615 base::Unretained(io_worker_.get()), | 655 base::Unretained(io_worker_.get()), |
616 account_tokens)); | 656 account_tokens)); |
617 } | 657 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 | 792 |
753 // Normally request_gcm_statistics_callback_ would not be null. | 793 // Normally request_gcm_statistics_callback_ would not be null. |
754 if (!request_gcm_statistics_callback_.is_null()) | 794 if (!request_gcm_statistics_callback_.is_null()) |
755 request_gcm_statistics_callback_.Run(stats); | 795 request_gcm_statistics_callback_.Run(stats); |
756 else | 796 else |
757 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; | 797 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
758 } | 798 } |
759 | 799 |
760 } // namespace gcm | 800 } // namespace gcm |
761 | 801 |
OLD | NEW |