| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 weak_ptr_factory_.InvalidateWeakPtrs(); | 507 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 507 device_checkin_info_.Reset(); | 508 device_checkin_info_.Reset(); |
| 508 connection_factory_.reset(); | 509 connection_factory_.reset(); |
| 510 delegate_->OnDisconnected(); |
| 509 mcs_client_.reset(); | 511 mcs_client_.reset(); |
| 510 checkin_request_.reset(); | 512 checkin_request_.reset(); |
| 511 pending_registration_requests_.clear(); | 513 pending_registration_requests_.clear(); |
| 512 state_ = INITIALIZED; | 514 state_ = INITIALIZED; |
| 513 gcm_store_->Close(); | 515 gcm_store_->Close(); |
| 514 } | 516 } |
| 515 | 517 |
| 516 void GCMClientImpl::CheckOut() { | 518 void GCMClientImpl::CheckOut() { |
| 517 Stop(); | 519 Stop(); |
| 518 gcm_store_->Destroy(base::Bind(&GCMClientImpl::OnGCMStoreDestroyed, | 520 gcm_store_->Destroy(base::Bind(&GCMClientImpl::OnGCMStoreDestroyed, |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 } | 731 } |
| 730 return stats; | 732 return stats; |
| 731 } | 733 } |
| 732 | 734 |
| 733 void GCMClientImpl::OnActivityRecorded() { | 735 void GCMClientImpl::OnActivityRecorded() { |
| 734 delegate_->OnActivityRecorded(); | 736 delegate_->OnActivityRecorded(); |
| 735 } | 737 } |
| 736 | 738 |
| 737 void GCMClientImpl::OnConnected(const GURL& current_server, | 739 void GCMClientImpl::OnConnected(const GURL& current_server, |
| 738 const net::IPEndPoint& ip_endpoint) { | 740 const net::IPEndPoint& ip_endpoint) { |
| 739 // TODO(zea): inform GCMClient::Delegate and app handlers as well. | 741 // TODO(gcm): expose current server in debug page. |
| 740 delegate_->OnActivityRecorded(); | 742 delegate_->OnActivityRecorded(); |
| 743 delegate_->OnConnected(ip_endpoint); |
| 741 } | 744 } |
| 742 | 745 |
| 743 void GCMClientImpl::OnDisconnected() { | 746 void GCMClientImpl::OnDisconnected() { |
| 744 // TODO(zea): inform GCMClient::Delegate and app handlers as well. | |
| 745 delegate_->OnActivityRecorded(); | 747 delegate_->OnActivityRecorded(); |
| 748 delegate_->OnDisconnected(); |
| 746 } | 749 } |
| 747 | 750 |
| 748 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { | 751 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { |
| 749 switch (message.tag()) { | 752 switch (message.tag()) { |
| 750 case kLoginResponseTag: | 753 case kLoginResponseTag: |
| 751 DVLOG(1) << "Login response received by GCM Client. Ignoring."; | 754 DVLOG(1) << "Login response received by GCM Client. Ignoring."; |
| 752 return; | 755 return; |
| 753 case kDataMessageStanzaTag: | 756 case kDataMessageStanzaTag: |
| 754 DVLOG(1) << "A downstream message received. Processing..."; | 757 DVLOG(1) << "A downstream message received. Processing..."; |
| 755 HandleIncomingMessage(message); | 758 HandleIncomingMessage(message); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 885 |
| 883 recorder_.RecordIncomingSendError( | 886 recorder_.RecordIncomingSendError( |
| 884 data_message_stanza.category(), | 887 data_message_stanza.category(), |
| 885 data_message_stanza.to(), | 888 data_message_stanza.to(), |
| 886 data_message_stanza.id()); | 889 data_message_stanza.id()); |
| 887 delegate_->OnMessageSendError(data_message_stanza.category(), | 890 delegate_->OnMessageSendError(data_message_stanza.category(), |
| 888 send_error_details); | 891 send_error_details); |
| 889 } | 892 } |
| 890 | 893 |
| 891 } // namespace gcm | 894 } // namespace gcm |
| OLD | NEW |