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" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 new ConnectionFactoryImpl(endpoints, | 243 new ConnectionFactoryImpl(endpoints, |
244 backoff_policy, | 244 backoff_policy, |
245 network_session, | 245 network_session, |
246 net_log, | 246 net_log, |
247 recorder)); | 247 recorder)); |
248 } | 248 } |
249 | 249 |
250 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder) | 250 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder) |
251 : internals_builder_(internals_builder.Pass()), | 251 : internals_builder_(internals_builder.Pass()), |
252 state_(UNINITIALIZED), | 252 state_(UNINITIALIZED), |
| 253 delegate_(NULL), |
253 clock_(internals_builder_->BuildClock()), | 254 clock_(internals_builder_->BuildClock()), |
254 url_request_context_getter_(NULL), | 255 url_request_context_getter_(NULL), |
255 pending_registration_requests_deleter_(&pending_registration_requests_), | 256 pending_registration_requests_deleter_(&pending_registration_requests_), |
256 pending_unregistration_requests_deleter_( | 257 pending_unregistration_requests_deleter_( |
257 &pending_unregistration_requests_), | 258 &pending_unregistration_requests_), |
258 periodic_checkin_ptr_factory_(this), | 259 periodic_checkin_ptr_factory_(this), |
259 weak_ptr_factory_(this) { | 260 weak_ptr_factory_(this) { |
260 } | 261 } |
261 | 262 |
262 GCMClientImpl::~GCMClientImpl() { | 263 GCMClientImpl::~GCMClientImpl() { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 499 } |
499 | 500 |
500 void GCMClientImpl::UpdateRegistrationCallback(bool success) { | 501 void GCMClientImpl::UpdateRegistrationCallback(bool success) { |
501 // TODO(fgorski): This is one of the signals that store needs a rebuild. | 502 // TODO(fgorski): This is one of the signals that store needs a rebuild. |
502 DCHECK(success); | 503 DCHECK(success); |
503 } | 504 } |
504 | 505 |
505 void GCMClientImpl::Stop() { | 506 void GCMClientImpl::Stop() { |
506 device_checkin_info_.Reset(); | 507 device_checkin_info_.Reset(); |
507 connection_factory_.reset(); | 508 connection_factory_.reset(); |
| 509 delegate_->OnDisconnected(); |
508 mcs_client_.reset(); | 510 mcs_client_.reset(); |
509 checkin_request_.reset(); | 511 checkin_request_.reset(); |
510 pending_registration_requests_.clear(); | 512 pending_registration_requests_.clear(); |
511 state_ = INITIALIZED; | 513 state_ = INITIALIZED; |
512 gcm_store_->Close(); | 514 gcm_store_->Close(); |
513 } | 515 } |
514 | 516 |
515 void GCMClientImpl::CheckOut() { | 517 void GCMClientImpl::CheckOut() { |
516 Stop(); | 518 Stop(); |
517 gcm_store_->Destroy(base::Bind(&GCMClientImpl::OnGCMStoreDestroyed, | 519 gcm_store_->Destroy(base::Bind(&GCMClientImpl::OnGCMStoreDestroyed, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 } | 730 } |
729 return stats; | 731 return stats; |
730 } | 732 } |
731 | 733 |
732 void GCMClientImpl::OnActivityRecorded() { | 734 void GCMClientImpl::OnActivityRecorded() { |
733 delegate_->OnActivityRecorded(); | 735 delegate_->OnActivityRecorded(); |
734 } | 736 } |
735 | 737 |
736 void GCMClientImpl::OnConnected(const GURL& current_server, | 738 void GCMClientImpl::OnConnected(const GURL& current_server, |
737 const net::IPEndPoint& ip_endpoint) { | 739 const net::IPEndPoint& ip_endpoint) { |
738 // TODO(zea): inform GCMClient::Delegate and app handlers as well. | 740 // TODO(gcm): expose current server in debug page. |
739 delegate_->OnActivityRecorded(); | 741 delegate_->OnActivityRecorded(); |
| 742 delegate_->OnConnected(ip_endpoint); |
740 } | 743 } |
741 | 744 |
742 void GCMClientImpl::OnDisconnected() { | 745 void GCMClientImpl::OnDisconnected() { |
743 // TODO(zea): inform GCMClient::Delegate and app handlers as well. | |
744 delegate_->OnActivityRecorded(); | 746 delegate_->OnActivityRecorded(); |
| 747 delegate_->OnDisconnected(); |
745 } | 748 } |
746 | 749 |
747 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { | 750 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { |
748 switch (message.tag()) { | 751 switch (message.tag()) { |
749 case kLoginResponseTag: | 752 case kLoginResponseTag: |
750 DVLOG(1) << "Login response received by GCM Client. Ignoring."; | 753 DVLOG(1) << "Login response received by GCM Client. Ignoring."; |
751 return; | 754 return; |
752 case kDataMessageStanzaTag: | 755 case kDataMessageStanzaTag: |
753 DVLOG(1) << "A downstream message received. Processing..."; | 756 DVLOG(1) << "A downstream message received. Processing..."; |
754 HandleIncomingMessage(message); | 757 HandleIncomingMessage(message); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 | 884 |
882 recorder_.RecordIncomingSendError( | 885 recorder_.RecordIncomingSendError( |
883 data_message_stanza.category(), | 886 data_message_stanza.category(), |
884 data_message_stanza.to(), | 887 data_message_stanza.to(), |
885 data_message_stanza.id()); | 888 data_message_stanza.id()); |
886 delegate_->OnMessageSendError(data_message_stanza.category(), | 889 delegate_->OnMessageSendError(data_message_stanza.category(), |
887 send_error_details); | 890 send_error_details); |
888 } | 891 } |
889 | 892 |
890 } // namespace gcm | 893 } // namespace gcm |
OLD | NEW |