Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: google_apis/gcm/gcm_client_impl.cc

Issue 248213004: Record connection, registration, and receiving activities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « google_apis/gcm/gcm_client_impl.h ('k') | google_apis/gcm/gcm_client_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "google_apis/gcm/gcm_client_impl.h" 5 #include "google_apis/gcm/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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 clock, 139 clock,
140 connection_factory, 140 connection_factory,
141 gcm_store, 141 gcm_store,
142 recorder)); 142 recorder));
143 } 143 }
144 144
145 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( 145 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory(
146 const std::vector<GURL>& endpoints, 146 const std::vector<GURL>& endpoints,
147 const net::BackoffEntry::Policy& backoff_policy, 147 const net::BackoffEntry::Policy& backoff_policy,
148 scoped_refptr<net::HttpNetworkSession> network_session, 148 scoped_refptr<net::HttpNetworkSession> network_session,
149 net::NetLog* net_log) { 149 net::NetLog* net_log,
150 GCMStatsRecorder* recorder) {
150 return make_scoped_ptr<ConnectionFactory>( 151 return make_scoped_ptr<ConnectionFactory>(
151 new ConnectionFactoryImpl(endpoints, 152 new ConnectionFactoryImpl(endpoints,
152 backoff_policy, 153 backoff_policy,
153 network_session, 154 network_session,
154 net_log)); 155 net_log,
156 recorder));
155 } 157 }
156 158
157 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder) 159 GCMClientImpl::GCMClientImpl(scoped_ptr<GCMInternalsBuilder> internals_builder)
158 : internals_builder_(internals_builder.Pass()), 160 : internals_builder_(internals_builder.Pass()),
159 state_(UNINITIALIZED), 161 state_(UNINITIALIZED),
160 clock_(internals_builder_->BuildClock()), 162 clock_(internals_builder_->BuildClock()),
161 url_request_context_getter_(NULL), 163 url_request_context_getter_(NULL),
162 pending_registration_requests_deleter_(&pending_registration_requests_), 164 pending_registration_requests_deleter_(&pending_registration_requests_),
163 pending_unregistration_requests_deleter_( 165 pending_unregistration_requests_deleter_(
164 &pending_unregistration_requests_), 166 &pending_unregistration_requests_),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 235
234 void GCMClientImpl::InitializeMCSClient( 236 void GCMClientImpl::InitializeMCSClient(
235 scoped_ptr<GCMStore::LoadResult> result) { 237 scoped_ptr<GCMStore::LoadResult> result) {
236 std::vector<GURL> endpoints; 238 std::vector<GURL> endpoints;
237 endpoints.push_back(GURL(kMCSEndpointMain)); 239 endpoints.push_back(GURL(kMCSEndpointMain));
238 endpoints.push_back(GURL(kMCSEndpointFallback)); 240 endpoints.push_back(GURL(kMCSEndpointFallback));
239 connection_factory_ = internals_builder_->BuildConnectionFactory( 241 connection_factory_ = internals_builder_->BuildConnectionFactory(
240 endpoints, 242 endpoints,
241 kDefaultBackoffPolicy, 243 kDefaultBackoffPolicy,
242 network_session_, 244 network_session_,
243 net_log_.net_log()); 245 net_log_.net_log(),
246 &recorder_);
244 mcs_client_ = internals_builder_->BuildMCSClient( 247 mcs_client_ = internals_builder_->BuildMCSClient(
245 chrome_build_proto_.chrome_version(), 248 chrome_build_proto_.chrome_version(),
246 clock_.get(), 249 clock_.get(),
247 connection_factory_.get(), 250 connection_factory_.get(),
248 gcm_store_.get(), 251 gcm_store_.get(),
249 &recorder_).Pass(); 252 &recorder_).Pass();
250 253
251 mcs_client_->Initialize( 254 mcs_client_->Initialize(
252 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), 255 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()),
253 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, 256 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 DCHECK_EQ(0u, pending_registration_requests_.count(app_id)); 413 DCHECK_EQ(0u, pending_registration_requests_.count(app_id));
411 414
412 RegistrationRequest* registration_request = 415 RegistrationRequest* registration_request =
413 new RegistrationRequest(request_info, 416 new RegistrationRequest(request_info,
414 kDefaultBackoffPolicy, 417 kDefaultBackoffPolicy,
415 base::Bind(&GCMClientImpl::OnRegisterCompleted, 418 base::Bind(&GCMClientImpl::OnRegisterCompleted,
416 weak_ptr_factory_.GetWeakPtr(), 419 weak_ptr_factory_.GetWeakPtr(),
417 app_id, 420 app_id,
418 sender_ids), 421 sender_ids),
419 kMaxRegistrationRetries, 422 kMaxRegistrationRetries,
420 url_request_context_getter_); 423 url_request_context_getter_,
424 &recorder_);
421 pending_registration_requests_[app_id] = registration_request; 425 pending_registration_requests_[app_id] = registration_request;
422 registration_request->Start(); 426 registration_request->Start();
423 } 427 }
424 428
425 void GCMClientImpl::OnRegisterCompleted( 429 void GCMClientImpl::OnRegisterCompleted(
426 const std::string& app_id, 430 const std::string& app_id,
427 const std::vector<std::string>& sender_ids, 431 const std::vector<std::string>& sender_ids,
428 RegistrationRequest::Status status, 432 RegistrationRequest::Status status,
429 const std::string& registration_id) { 433 const std::string& registration_id) {
430 DCHECK(delegate_); 434 DCHECK(delegate_);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 device_checkin_info_.secret, 486 device_checkin_info_.secret,
483 app_id); 487 app_id);
484 488
485 UnregistrationRequest* unregistration_request = 489 UnregistrationRequest* unregistration_request =
486 new UnregistrationRequest( 490 new UnregistrationRequest(
487 request_info, 491 request_info,
488 kDefaultBackoffPolicy, 492 kDefaultBackoffPolicy,
489 base::Bind(&GCMClientImpl::OnUnregisterCompleted, 493 base::Bind(&GCMClientImpl::OnUnregisterCompleted,
490 weak_ptr_factory_.GetWeakPtr(), 494 weak_ptr_factory_.GetWeakPtr(),
491 app_id), 495 app_id),
492 url_request_context_getter_); 496 url_request_context_getter_,
497 &recorder_);
493 pending_unregistration_requests_[app_id] = unregistration_request; 498 pending_unregistration_requests_[app_id] = unregistration_request;
494 unregistration_request->Start(); 499 unregistration_request->Start();
495 } 500 }
496 501
497 void GCMClientImpl::OnUnregisterCompleted( 502 void GCMClientImpl::OnUnregisterCompleted(
498 const std::string& app_id, 503 const std::string& app_id,
499 UnregistrationRequest::Status status) { 504 UnregistrationRequest::Status status) {
500 DVLOG(1) << "Unregister completed for app: " << app_id 505 DVLOG(1) << "Unregister completed for app: " << app_id
501 << " with " << (status ? "success." : "failure."); 506 << " with " << (status ? "success." : "failure.");
502 delegate_->OnUnregisterFinished( 507 delegate_->OnUnregisterFinished(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 stats.is_recording = recorder_.is_recording(); 581 stats.is_recording = recorder_.is_recording();
577 stats.gcm_client_state = GetStateString(); 582 stats.gcm_client_state = GetStateString();
578 stats.connection_client_created = mcs_client_.get() != NULL; 583 stats.connection_client_created = mcs_client_.get() != NULL;
579 if (mcs_client_.get()) { 584 if (mcs_client_.get()) {
580 stats.connection_state = mcs_client_->GetStateString(); 585 stats.connection_state = mcs_client_->GetStateString();
581 stats.send_queue_size = mcs_client_->GetSendQueueSize(); 586 stats.send_queue_size = mcs_client_->GetSendQueueSize();
582 stats.resend_queue_size = mcs_client_->GetResendQueueSize(); 587 stats.resend_queue_size = mcs_client_->GetResendQueueSize();
583 } 588 }
584 if (device_checkin_info_.android_id > 0) 589 if (device_checkin_info_.android_id > 0)
585 stats.android_id = device_checkin_info_.android_id; 590 stats.android_id = device_checkin_info_.android_id;
586 recorder_.CollectSendingActivities(&stats.sending_activities); 591 recorder_.CollectActivities(&stats.recorded_activities);
587 592
588 for (RegistrationInfoMap::const_iterator it = registrations_.begin(); 593 for (RegistrationInfoMap::const_iterator it = registrations_.begin();
589 it != registrations_.end(); ++it) { 594 it != registrations_.end(); ++it) {
590 stats.registered_app_ids.push_back(it->first); 595 stats.registered_app_ids.push_back(it->first);
591 } 596 }
592 return stats; 597 return stats;
593 } 598 }
594 599
595 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { 600 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) {
596 switch (message.tag()) { 601 switch (message.tag()) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 if (iter != message_data.end()) { 665 if (iter != message_data.end()) {
661 message_type = DecodeMessageType(iter->second); 666 message_type = DecodeMessageType(iter->second);
662 message_data.erase(iter); 667 message_data.erase(iter);
663 } 668 }
664 669
665 switch (message_type) { 670 switch (message_type) {
666 case DATA_MESSAGE: 671 case DATA_MESSAGE:
667 HandleIncomingDataMessage(data_message_stanza, message_data); 672 HandleIncomingDataMessage(data_message_stanza, message_data);
668 break; 673 break;
669 case DELETED_MESSAGES: 674 case DELETED_MESSAGES:
675 recorder_.RecordDataMessageRecieved(data_message_stanza.category(),
676 data_message_stanza.from(),
677 data_message_stanza.ByteSize(),
678 true,
679 GCMStatsRecorder::DELETED_MESSAGES);
670 delegate_->OnMessagesDeleted(data_message_stanza.category()); 680 delegate_->OnMessagesDeleted(data_message_stanza.category());
671 break; 681 break;
672 case SEND_ERROR: 682 case SEND_ERROR:
673 HandleIncomingSendError(data_message_stanza, message_data); 683 HandleIncomingSendError(data_message_stanza, message_data);
674 break; 684 break;
675 case UNKNOWN: 685 case UNKNOWN:
676 default: // Treat default the same as UNKNOWN. 686 default: // Treat default the same as UNKNOWN.
677 DVLOG(1) << "Unknown message_type received. Message ignored. " 687 DVLOG(1) << "Unknown message_type received. Message ignored. "
678 << "App ID: " << data_message_stanza.category() << "."; 688 << "App ID: " << data_message_stanza.category() << ".";
679 break; 689 break;
680 } 690 }
681 } 691 }
682 692
683 void GCMClientImpl::HandleIncomingDataMessage( 693 void GCMClientImpl::HandleIncomingDataMessage(
684 const mcs_proto::DataMessageStanza& data_message_stanza, 694 const mcs_proto::DataMessageStanza& data_message_stanza,
685 MessageData& message_data) { 695 MessageData& message_data) {
686 std::string app_id = data_message_stanza.category(); 696 std::string app_id = data_message_stanza.category();
687 697
688 // Drop the message when the app is not registered for the sender of the 698 // Drop the message when the app is not registered for the sender of the
689 // message. 699 // message.
690 RegistrationInfoMap::iterator iter = registrations_.find(app_id); 700 RegistrationInfoMap::iterator iter = registrations_.find(app_id);
691 if (iter == registrations_.end() || 701 bool not_registered =
702 iter == registrations_.end() ||
692 std::find(iter->second->sender_ids.begin(), 703 std::find(iter->second->sender_ids.begin(),
693 iter->second->sender_ids.end(), 704 iter->second->sender_ids.end(),
694 data_message_stanza.from()) == iter->second->sender_ids.end()) { 705 data_message_stanza.from()) == iter->second->sender_ids.end();
706 recorder_.RecordDataMessageRecieved(app_id, data_message_stanza.from(),
707 data_message_stanza.ByteSize(), !not_registered,
708 GCMStatsRecorder::DATA_MESSAGE);
709 if (not_registered) {
695 return; 710 return;
696 } 711 }
697 712
698 IncomingMessage incoming_message; 713 IncomingMessage incoming_message;
699 incoming_message.sender_id = data_message_stanza.from(); 714 incoming_message.sender_id = data_message_stanza.from();
700 if (data_message_stanza.has_token()) 715 if (data_message_stanza.has_token())
701 incoming_message.collapse_key = data_message_stanza.token(); 716 incoming_message.collapse_key = data_message_stanza.token();
702 incoming_message.data = message_data; 717 incoming_message.data = message_data;
703 delegate_->OnMessageReceived(app_id, incoming_message); 718 delegate_->OnMessageReceived(app_id, incoming_message);
704 } 719 }
(...skipping 14 matching lines...) Expand all
719 734
720 recorder_.RecordIncomingSendError( 735 recorder_.RecordIncomingSendError(
721 data_message_stanza.category(), 736 data_message_stanza.category(),
722 data_message_stanza.to(), 737 data_message_stanza.to(),
723 data_message_stanza.id()); 738 data_message_stanza.id());
724 delegate_->OnMessageSendError(data_message_stanza.category(), 739 delegate_->OnMessageSendError(data_message_stanza.category(),
725 send_error_details); 740 send_error_details);
726 } 741 }
727 742
728 } // namespace gcm 743 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/gcm_client_impl.h ('k') | google_apis/gcm/gcm_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698