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_client_impl.h" | 5 #include "components/gcm_driver/gcm_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/time/default_clock.h" | 17 #include "base/time/default_clock.h" |
| 18 #include "base/timer/timer.h" |
18 #include "components/gcm_driver/gcm_backoff_policy.h" | 19 #include "components/gcm_driver/gcm_backoff_policy.h" |
19 #include "components/timers/alarm_timer.h" | |
20 #include "google_apis/gcm/base/encryptor.h" | 20 #include "google_apis/gcm/base/encryptor.h" |
21 #include "google_apis/gcm/base/mcs_message.h" | 21 #include "google_apis/gcm/base/mcs_message.h" |
22 #include "google_apis/gcm/base/mcs_util.h" | 22 #include "google_apis/gcm/base/mcs_util.h" |
23 #include "google_apis/gcm/engine/checkin_request.h" | 23 #include "google_apis/gcm/engine/checkin_request.h" |
24 #include "google_apis/gcm/engine/connection_factory_impl.h" | 24 #include "google_apis/gcm/engine/connection_factory_impl.h" |
25 #include "google_apis/gcm/engine/gcm_store_impl.h" | 25 #include "google_apis/gcm/engine/gcm_store_impl.h" |
26 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 26 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
27 #include "google_apis/gcm/protocol/checkin.pb.h" | 27 #include "google_apis/gcm/protocol/checkin.pb.h" |
28 #include "google_apis/gcm/protocol/mcs.pb.h" | 28 #include "google_apis/gcm/protocol/mcs.pb.h" |
29 #include "net/http/http_network_session.h" | 29 #include "net/http/http_network_session.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { | 186 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { |
187 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); | 187 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); |
188 } | 188 } |
189 | 189 |
190 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( | 190 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( |
191 const std::string& version, | 191 const std::string& version, |
192 base::Clock* clock, | 192 base::Clock* clock, |
193 ConnectionFactory* connection_factory, | 193 ConnectionFactory* connection_factory, |
194 GCMStore* gcm_store, | 194 GCMStore* gcm_store, |
195 GCMStatsRecorder* recorder) { | 195 GCMStatsRecorder* recorder) { |
196 #if defined(OS_CHROMEOS) | |
197 return scoped_ptr<MCSClient>(new MCSClient( | 196 return scoped_ptr<MCSClient>(new MCSClient( |
198 version, clock, connection_factory, gcm_store, recorder, | 197 version, clock, connection_factory, gcm_store, recorder)); |
199 make_scoped_ptr(new timers::AlarmTimer(true, /* retain user task */ | |
200 false /* non-repeating */)))); | |
201 #else | |
202 return scoped_ptr<MCSClient>(new MCSClient( | |
203 version, clock, connection_factory, gcm_store, recorder, | |
204 make_scoped_ptr(new base::Timer(true, /* retain user task */ | |
205 false /* non-repeating */)))); | |
206 #endif // defined(OS_CHROMEOS) | |
207 } | 198 } |
208 | 199 |
209 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( | 200 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( |
210 const std::vector<GURL>& endpoints, | 201 const std::vector<GURL>& endpoints, |
211 const net::BackoffEntry::Policy& backoff_policy, | 202 const net::BackoffEntry::Policy& backoff_policy, |
212 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, | 203 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, |
213 const scoped_refptr<net::HttpNetworkSession>& http_network_session, | 204 const scoped_refptr<net::HttpNetworkSession>& http_network_session, |
214 net::NetLog* net_log, | 205 net::NetLog* net_log, |
215 GCMStatsRecorder* recorder) { | 206 GCMStatsRecorder* recorder) { |
216 return make_scoped_ptr<ConnectionFactory>( | 207 return make_scoped_ptr<ConnectionFactory>( |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 weak_ptr_factory_.GetWeakPtr())); | 462 weak_ptr_factory_.GetWeakPtr())); |
472 } | 463 } |
473 | 464 |
474 void GCMClientImpl::SetLastTokenFetchTime(const base::Time& time) { | 465 void GCMClientImpl::SetLastTokenFetchTime(const base::Time& time) { |
475 gcm_store_->SetLastTokenFetchTime( | 466 gcm_store_->SetLastTokenFetchTime( |
476 time, | 467 time, |
477 base::Bind(&GCMClientImpl::IgnoreWriteResultCallback, | 468 base::Bind(&GCMClientImpl::IgnoreWriteResultCallback, |
478 weak_ptr_factory_.GetWeakPtr())); | 469 weak_ptr_factory_.GetWeakPtr())); |
479 } | 470 } |
480 | 471 |
| 472 void GCMClientImpl::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) { |
| 473 DCHECK(mcs_client_); |
| 474 mcs_client_->UpdateHeartbeatTimer(timer.Pass()); |
| 475 } |
| 476 |
481 void GCMClientImpl::StartCheckin() { | 477 void GCMClientImpl::StartCheckin() { |
482 // Make sure no checkin is in progress. | 478 // Make sure no checkin is in progress. |
483 if (checkin_request_.get()) | 479 if (checkin_request_.get()) |
484 return; | 480 return; |
485 | 481 |
486 checkin_proto::ChromeBuildProto chrome_build_proto; | 482 checkin_proto::ChromeBuildProto chrome_build_proto; |
487 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); | 483 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto); |
488 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, | 484 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, |
489 device_checkin_info_.secret, | 485 device_checkin_info_.secret, |
490 device_checkin_info_.account_tokens, | 486 device_checkin_info_.account_tokens, |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 | 986 |
991 recorder_.RecordIncomingSendError( | 987 recorder_.RecordIncomingSendError( |
992 data_message_stanza.category(), | 988 data_message_stanza.category(), |
993 data_message_stanza.to(), | 989 data_message_stanza.to(), |
994 data_message_stanza.id()); | 990 data_message_stanza.id()); |
995 delegate_->OnMessageSendError(data_message_stanza.category(), | 991 delegate_->OnMessageSendError(data_message_stanza.category(), |
996 send_error_details); | 992 send_error_details); |
997 } | 993 } |
998 | 994 |
999 } // namespace gcm | 995 } // namespace gcm |
OLD | NEW |