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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); | 73 const scoped_refptr<base::SequencedTaskRunner> blocking_task_runner); |
74 void Start(GCMClient::StartMode start_mode, | 74 void Start(GCMClient::StartMode start_mode, |
75 const base::WeakPtr<GCMDriverDesktop>& service); | 75 const base::WeakPtr<GCMDriverDesktop>& service); |
76 void Stop(); | 76 void Stop(); |
77 void Register(const std::string& app_id, | 77 void Register(const std::string& app_id, |
78 const std::vector<std::string>& sender_ids); | 78 const std::vector<std::string>& sender_ids); |
79 void Unregister(const std::string& app_id); | 79 void Unregister(const std::string& app_id); |
80 void Send(const std::string& app_id, | 80 void Send(const std::string& app_id, |
81 const std::string& receiver_id, | 81 const std::string& receiver_id, |
82 const OutgoingMessage& message); | 82 const OutgoingMessage& message); |
83 void GetGCMStatistics(bool clear_logs); | 83 void GetGCMStatistics(GCMDriver::ClearActivityLogs clear_logs); |
84 void SetGCMRecording(bool recording); | 84 void SetGCMRecording(bool recording); |
85 | 85 |
86 void SetAccountTokens( | 86 void SetAccountTokens( |
87 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); | 87 const std::vector<GCMClient::AccountTokenInfo>& account_tokens); |
88 void UpdateAccountMapping(const AccountMapping& account_mapping); | 88 void UpdateAccountMapping(const AccountMapping& account_mapping); |
89 void RemoveAccountMapping(const std::string& account_id); | 89 void RemoveAccountMapping(const std::string& account_id); |
90 void SetLastTokenFetchTime(const base::Time& time); | 90 void SetLastTokenFetchTime(const base::Time& time); |
91 void WakeFromSuspendForHeartbeat(bool wake); | 91 void WakeFromSuspendForHeartbeat(bool wake); |
92 void AddHeartbeatInterval(const std::string& scope, int interval_ms); | 92 void AddHeartbeatInterval(const std::string& scope, int interval_ms); |
93 void RemoveHeartbeatInterval(const std::string& scope); | 93 void RemoveHeartbeatInterval(const std::string& scope); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 base::Bind(&GCMDriverDesktop::GCMClientReady, | 277 base::Bind(&GCMDriverDesktop::GCMClientReady, |
278 service_, | 278 service_, |
279 account_mappings, | 279 account_mappings, |
280 last_token_fetch_time)); | 280 last_token_fetch_time)); |
281 } | 281 } |
282 | 282 |
283 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { | 283 void GCMDriverDesktop::IOWorker::OnActivityRecorded() { |
284 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 284 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
285 // When an activity is recorded, get all the stats and refresh the UI of | 285 // When an activity is recorded, get all the stats and refresh the UI of |
286 // gcm-internals page. | 286 // gcm-internals page. |
287 GetGCMStatistics(false); | 287 GetGCMStatistics(GCMDriver::KEEP_LOGS); |
288 } | 288 } |
289 | 289 |
290 void GCMDriverDesktop::IOWorker::OnConnected( | 290 void GCMDriverDesktop::IOWorker::OnConnected( |
291 const net::IPEndPoint& ip_endpoint) { | 291 const net::IPEndPoint& ip_endpoint) { |
292 ui_thread_->PostTask(FROM_HERE, | 292 ui_thread_->PostTask(FROM_HERE, |
293 base::Bind(&GCMDriverDesktop::OnConnected, | 293 base::Bind(&GCMDriverDesktop::OnConnected, |
294 service_, | 294 service_, |
295 ip_endpoint)); | 295 ip_endpoint)); |
296 } | 296 } |
297 | 297 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 336 } |
337 | 337 |
338 void GCMDriverDesktop::IOWorker::Send(const std::string& app_id, | 338 void GCMDriverDesktop::IOWorker::Send(const std::string& app_id, |
339 const std::string& receiver_id, | 339 const std::string& receiver_id, |
340 const OutgoingMessage& message) { | 340 const OutgoingMessage& message) { |
341 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 341 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
342 | 342 |
343 gcm_client_->Send(app_id, receiver_id, message); | 343 gcm_client_->Send(app_id, receiver_id, message); |
344 } | 344 } |
345 | 345 |
346 void GCMDriverDesktop::IOWorker::GetGCMStatistics(bool clear_logs) { | 346 void GCMDriverDesktop::IOWorker::GetGCMStatistics( |
| 347 ClearActivityLogs clear_logs) { |
347 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 348 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
348 gcm::GCMClient::GCMStatistics stats; | 349 gcm::GCMClient::GCMStatistics stats; |
349 | 350 |
350 if (gcm_client_.get()) { | 351 if (gcm_client_.get()) { |
351 if (clear_logs) | 352 if (clear_logs == GCMDriver::CLEAR_LOGS) |
352 gcm_client_->ClearActivityLogs(); | 353 gcm_client_->ClearActivityLogs(); |
353 stats = gcm_client_->GetStatistics(); | 354 stats = gcm_client_->GetStatistics(); |
354 } | 355 } |
355 | 356 |
356 ui_thread_->PostTask( | 357 ui_thread_->PostTask( |
357 FROM_HERE, | 358 FROM_HERE, |
358 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); | 359 base::Bind(&GCMDriverDesktop::GetGCMStatisticsFinished, service_, stats)); |
359 } | 360 } |
360 | 361 |
361 void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) { | 362 void GCMDriverDesktop::IOWorker::SetGCMRecording(bool recording) { |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 729 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
729 return gcm_started_; | 730 return gcm_started_; |
730 } | 731 } |
731 | 732 |
732 bool GCMDriverDesktop::IsConnected() const { | 733 bool GCMDriverDesktop::IsConnected() const { |
733 return connected_; | 734 return connected_; |
734 } | 735 } |
735 | 736 |
736 void GCMDriverDesktop::GetGCMStatistics( | 737 void GCMDriverDesktop::GetGCMStatistics( |
737 const GetGCMStatisticsCallback& callback, | 738 const GetGCMStatisticsCallback& callback, |
738 bool clear_logs) { | 739 ClearActivityLogs clear_logs) { |
739 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 740 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
740 DCHECK(!callback.is_null()); | 741 DCHECK(!callback.is_null()); |
741 | 742 |
742 request_gcm_statistics_callback_ = callback; | 743 request_gcm_statistics_callback_ = callback; |
743 io_thread_->PostTask( | 744 io_thread_->PostTask( |
744 FROM_HERE, | 745 FROM_HERE, |
745 base::Bind(&GCMDriverDesktop::IOWorker::GetGCMStatistics, | 746 base::Bind(&GCMDriverDesktop::IOWorker::GetGCMStatistics, |
746 base::Unretained(io_worker_.get()), | 747 base::Unretained(io_worker_.get()), |
747 clear_logs)); | 748 clear_logs)); |
748 } | 749 } |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 | 1299 |
1299 if (base::get<1>(a) < base::get<1>(b)) | 1300 if (base::get<1>(a) < base::get<1>(b)) |
1300 return true; | 1301 return true; |
1301 if (base::get<1>(a) > base::get<1>(b)) | 1302 if (base::get<1>(a) > base::get<1>(b)) |
1302 return false; | 1303 return false; |
1303 | 1304 |
1304 return base::get<2>(a) < base::get<2>(b); | 1305 return base::get<2>(a) < base::get<2>(b); |
1305 } | 1306 } |
1306 | 1307 |
1307 } // namespace gcm | 1308 } // namespace gcm |
OLD | NEW |