Chromium Code Reviews| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 void OnMessageSendError( | 59 void OnMessageSendError( |
| 60 const std::string& app_id, | 60 const std::string& app_id, |
| 61 const GCMClient::SendErrorDetails& send_error_details) override; | 61 const GCMClient::SendErrorDetails& send_error_details) override; |
| 62 void OnSendAcknowledged(const std::string& app_id, | 62 void OnSendAcknowledged(const std::string& app_id, |
| 63 const std::string& message_id) override; | 63 const std::string& message_id) override; |
| 64 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, | 64 void OnGCMReady(const std::vector<AccountMapping>& account_mappings, |
| 65 const base::Time& last_token_fetch_time) override; | 65 const base::Time& last_token_fetch_time) override; |
| 66 void OnActivityRecorded() override; | 66 void OnActivityRecorded() override; |
| 67 void OnConnected(const net::IPEndPoint& ip_endpoint) override; | 67 void OnConnected(const net::IPEndPoint& ip_endpoint) override; |
| 68 void OnDisconnected() override; | 68 void OnDisconnected() override; |
| 69 void OnStoreReset() override; | |
| 69 | 70 |
| 70 // Called on IO thread. | 71 // Called on IO thread. |
| 71 void Initialize( | 72 void Initialize( |
| 72 std::unique_ptr<GCMClientFactory> gcm_client_factory, | 73 std::unique_ptr<GCMClientFactory> gcm_client_factory, |
| 73 const GCMClient::ChromeBuildInfo& chrome_build_info, | 74 const GCMClient::ChromeBuildInfo& chrome_build_info, |
| 74 const base::FilePath& store_path, | 75 const base::FilePath& store_path, |
| 75 const scoped_refptr<net::URLRequestContextGetter>& request_context, | 76 const scoped_refptr<net::URLRequestContextGetter>& request_context, |
| 76 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | 77 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
| 77 void Start(GCMClient::StartMode start_mode, | 78 void Start(GCMClient::StartMode start_mode, |
| 78 const base::WeakPtr<GCMDriverDesktop>& service); | 79 const base::WeakPtr<GCMDriverDesktop>& service); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 base::Bind(&GCMDriverDesktop::OnConnected, | 297 base::Bind(&GCMDriverDesktop::OnConnected, |
| 297 service_, | 298 service_, |
| 298 ip_endpoint)); | 299 ip_endpoint)); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void GCMDriverDesktop::IOWorker::OnDisconnected() { | 302 void GCMDriverDesktop::IOWorker::OnDisconnected() { |
| 302 ui_thread_->PostTask(FROM_HERE, | 303 ui_thread_->PostTask(FROM_HERE, |
| 303 base::Bind(&GCMDriverDesktop::OnDisconnected, service_)); | 304 base::Bind(&GCMDriverDesktop::OnDisconnected, service_)); |
| 304 } | 305 } |
| 305 | 306 |
| 307 void GCMDriverDesktop::IOWorker::OnStoreReset() { | |
| 308 ui_thread_->PostTask(FROM_HERE, | |
| 309 base::Bind(&GCMDriverDesktop::OnStoreReset, service_)); | |
| 310 } | |
| 311 | |
| 306 void GCMDriverDesktop::IOWorker::Start( | 312 void GCMDriverDesktop::IOWorker::Start( |
| 307 GCMClient::StartMode start_mode, | 313 GCMClient::StartMode start_mode, |
| 308 const base::WeakPtr<GCMDriverDesktop>& service) { | 314 const base::WeakPtr<GCMDriverDesktop>& service) { |
| 309 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 315 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 310 | 316 |
| 311 service_ = service; | 317 service_ = service; |
| 312 gcm_client_->Start(start_mode); | 318 gcm_client_->Start(start_mode); |
| 313 } | 319 } |
| 314 | 320 |
| 315 void GCMDriverDesktop::IOWorker::Stop() { | 321 void GCMDriverDesktop::IOWorker::Stop() { |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1293 connected_ = false; | 1299 connected_ = false; |
| 1294 | 1300 |
| 1295 // Drop the event if the service has been stopped. | 1301 // Drop the event if the service has been stopped. |
| 1296 if (!gcm_started_) | 1302 if (!gcm_started_) |
| 1297 return; | 1303 return; |
| 1298 | 1304 |
| 1299 for (GCMConnectionObserver& observer : connection_observer_list_) | 1305 for (GCMConnectionObserver& observer : connection_observer_list_) |
| 1300 observer.OnDisconnected(); | 1306 observer.OnDisconnected(); |
| 1301 } | 1307 } |
| 1302 | 1308 |
| 1309 void GCMDriverDesktop::OnStoreReset() { | |
| 1310 for (const auto& key_value : app_handlers()) | |
| 1311 key_value.second->OnStoreReset(); | |
|
jianli
2016/11/09 21:53:51
There is a risk here when the called app_handler a
johnme
2016/11/10 19:56:54
Good spot! I now iterate over a copy of app_handle
| |
| 1312 } | |
| 1313 | |
| 1303 void GCMDriverDesktop::GetGCMStatisticsFinished( | 1314 void GCMDriverDesktop::GetGCMStatisticsFinished( |
| 1304 const GCMClient::GCMStatistics& stats) { | 1315 const GCMClient::GCMStatistics& stats) { |
| 1305 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 1316 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 1306 | 1317 |
| 1307 // request_gcm_statistics_callback_ could be null when an activity, i.e. | 1318 // request_gcm_statistics_callback_ could be null when an activity, i.e. |
| 1308 // network activity, is triggered while gcm-intenals page is not open. | 1319 // network activity, is triggered while gcm-intenals page is not open. |
| 1309 if (!request_gcm_statistics_callback_.is_null()) | 1320 if (!request_gcm_statistics_callback_.is_null()) |
| 1310 request_gcm_statistics_callback_.Run(stats); | 1321 request_gcm_statistics_callback_.Run(stats); |
| 1311 } | 1322 } |
| 1312 | 1323 |
| 1313 bool GCMDriverDesktop::TokenTupleComparer::operator()( | 1324 bool GCMDriverDesktop::TokenTupleComparer::operator()( |
| 1314 const TokenTuple& a, const TokenTuple& b) const { | 1325 const TokenTuple& a, const TokenTuple& b) const { |
| 1315 if (std::get<0>(a) < std::get<0>(b)) | 1326 if (std::get<0>(a) < std::get<0>(b)) |
| 1316 return true; | 1327 return true; |
| 1317 if (std::get<0>(a) > std::get<0>(b)) | 1328 if (std::get<0>(a) > std::get<0>(b)) |
| 1318 return false; | 1329 return false; |
| 1319 | 1330 |
| 1320 if (std::get<1>(a) < std::get<1>(b)) | 1331 if (std::get<1>(a) < std::get<1>(b)) |
| 1321 return true; | 1332 return true; |
| 1322 if (std::get<1>(a) > std::get<1>(b)) | 1333 if (std::get<1>(a) > std::get<1>(b)) |
| 1323 return false; | 1334 return false; |
| 1324 | 1335 |
| 1325 return std::get<2>(a) < std::get<2>(b); | 1336 return std::get<2>(a) < std::get<2>(b); |
| 1326 } | 1337 } |
| 1327 | 1338 |
| 1328 } // namespace gcm | 1339 } // namespace gcm |
| OLD | NEW |