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

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

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolving another merge conflict. Created 6 years, 8 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
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"
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/strings/stringprintf.h"
14 #include "base/time/default_clock.h" 15 #include "base/time/default_clock.h"
15 #include "google_apis/gcm/base/mcs_message.h" 16 #include "google_apis/gcm/base/mcs_message.h"
16 #include "google_apis/gcm/base/mcs_util.h" 17 #include "google_apis/gcm/base/mcs_util.h"
17 #include "google_apis/gcm/engine/checkin_request.h" 18 #include "google_apis/gcm/engine/checkin_request.h"
18 #include "google_apis/gcm/engine/connection_factory_impl.h" 19 #include "google_apis/gcm/engine/connection_factory_impl.h"
19 #include "google_apis/gcm/engine/gcm_store_impl.h" 20 #include "google_apis/gcm/engine/gcm_store_impl.h"
20 #include "google_apis/gcm/engine/mcs_client.h" 21 #include "google_apis/gcm/engine/mcs_client.h"
22 #include "google_apis/gcm/gcm_stats_recorder.h"
21 #include "google_apis/gcm/protocol/mcs.pb.h" 23 #include "google_apis/gcm/protocol/mcs.pb.h"
22 #include "net/http/http_network_session.h" 24 #include "net/http/http_network_session.h"
23 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
24 #include "url/gurl.h" 26 #include "url/gurl.h"
25 27
26 namespace gcm { 28 namespace gcm {
27 29
28 namespace { 30 namespace {
29 31
30 // Backoff policy. Shared across reconnection logic and checkin/(un)registration 32 // Backoff policy. Shared across reconnection logic and checkin/(un)registration
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 GCMInternalsBuilder::~GCMInternalsBuilder() {} 123 GCMInternalsBuilder::~GCMInternalsBuilder() {}
122 124
123 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { 125 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() {
124 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); 126 return make_scoped_ptr<base::Clock>(new base::DefaultClock());
125 } 127 }
126 128
127 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( 129 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient(
128 const std::string& version, 130 const std::string& version,
129 base::Clock* clock, 131 base::Clock* clock,
130 ConnectionFactory* connection_factory, 132 ConnectionFactory* connection_factory,
131 GCMStore* gcm_store) { 133 GCMStore* gcm_store,
134 GCMStatsRecorder* recorder) {
132 return make_scoped_ptr<MCSClient>( 135 return make_scoped_ptr<MCSClient>(
133 new MCSClient(version, 136 new MCSClient(version,
134 clock, 137 clock,
135 connection_factory, 138 connection_factory,
136 gcm_store)); 139 gcm_store,
140 recorder));
137 } 141 }
138 142
139 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( 143 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory(
140 const std::vector<GURL>& endpoints, 144 const std::vector<GURL>& endpoints,
141 const net::BackoffEntry::Policy& backoff_policy, 145 const net::BackoffEntry::Policy& backoff_policy,
142 scoped_refptr<net::HttpNetworkSession> network_session, 146 scoped_refptr<net::HttpNetworkSession> network_session,
143 net::NetLog* net_log) { 147 net::NetLog* net_log) {
144 return make_scoped_ptr<ConnectionFactory>( 148 return make_scoped_ptr<ConnectionFactory>(
145 new ConnectionFactoryImpl(endpoints, 149 new ConnectionFactoryImpl(endpoints,
146 backoff_policy, 150 backoff_policy,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 endpoints.push_back(GURL(kMCSEndpointFallback)); 234 endpoints.push_back(GURL(kMCSEndpointFallback));
231 connection_factory_ = internals_builder_->BuildConnectionFactory( 235 connection_factory_ = internals_builder_->BuildConnectionFactory(
232 endpoints, 236 endpoints,
233 kDefaultBackoffPolicy, 237 kDefaultBackoffPolicy,
234 network_session_, 238 network_session_,
235 net_log_.net_log()); 239 net_log_.net_log());
236 mcs_client_ = internals_builder_->BuildMCSClient( 240 mcs_client_ = internals_builder_->BuildMCSClient(
237 chrome_build_proto_.chrome_version(), 241 chrome_build_proto_.chrome_version(),
238 clock_.get(), 242 clock_.get(),
239 connection_factory_.get(), 243 connection_factory_.get(),
240 gcm_store_.get()).Pass(); 244 gcm_store_.get(),
245 &recorder_).Pass();
241 246
242 mcs_client_->Initialize( 247 mcs_client_->Initialize(
243 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), 248 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()),
244 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, 249 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS,
245 weak_ptr_factory_.GetWeakPtr()), 250 weak_ptr_factory_.GetWeakPtr()),
246 base::Bind(&GCMClientImpl::OnMessageSentToMCS, 251 base::Bind(&GCMClientImpl::OnMessageSentToMCS,
247 weak_ptr_factory_.GetWeakPtr()), 252 weak_ptr_factory_.GetWeakPtr()),
248 result.Pass()); 253 result.Pass());
249 } 254 }
250 255
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 for (MessageData::const_iterator iter = message.data.begin(); 499 for (MessageData::const_iterator iter = message.data.begin();
495 iter != message.data.end(); 500 iter != message.data.end();
496 ++iter) { 501 ++iter) {
497 mcs_proto::AppData* app_data = stanza.add_app_data(); 502 mcs_proto::AppData* app_data = stanza.add_app_data();
498 app_data->set_key(iter->first); 503 app_data->set_key(iter->first);
499 app_data->set_value(iter->second); 504 app_data->set_value(iter->second);
500 } 505 }
501 506
502 MCSMessage mcs_message(stanza); 507 MCSMessage mcs_message(stanza);
503 DVLOG(1) << "MCS message size: " << mcs_message.size(); 508 DVLOG(1) << "MCS message size: " << mcs_message.size();
509 recorder_.RecordSendCalled(
jianli 2014/03/26 20:17:18 "SendCalled" in the method name sounds a bit stran
juyik 2014/03/26 20:57:32 OK, in that case this recording seems pretty redun
510 app_id,
511 receiver_id,
512 message.id,
513 stanza.ByteSize(),
514 message.time_to_live);
504 mcs_client_->SendMessage(mcs_message); 515 mcs_client_->SendMessage(mcs_message);
505 } 516 }
506 517
507 std::string GCMClientImpl::GetStateString() const { 518 std::string GCMClientImpl::GetStateString() const {
508 switch(state_) { 519 switch(state_) {
509 case GCMClientImpl::INITIALIZED: 520 case GCMClientImpl::INITIALIZED:
510 return "INITIALIZED"; 521 return "INITIALIZED";
511 case GCMClientImpl::UNINITIALIZED: 522 case GCMClientImpl::UNINITIALIZED:
512 return "UNINITIALIZED"; 523 return "UNINITIALIZED";
513 case GCMClientImpl::LOADING: 524 case GCMClientImpl::LOADING:
514 return "LOADING"; 525 return "LOADING";
515 case GCMClientImpl::INITIAL_DEVICE_CHECKIN: 526 case GCMClientImpl::INITIAL_DEVICE_CHECKIN:
516 return "INITIAL_DEVICE_CHECKIN"; 527 return "INITIAL_DEVICE_CHECKIN";
517 case GCMClientImpl::READY: 528 case GCMClientImpl::READY:
518 return "READY"; 529 return "READY";
519 default: 530 default:
520 NOTREACHED(); 531 NOTREACHED();
521 return std::string(); 532 return std::string();
522 } 533 }
523 } 534 }
524 535
536 void GCMClientImpl::SetRecording(bool recording) {
537 recorder_.SetRecording(recording);
538 }
539
540 void GCMClientImpl::ClearActivityLogs() {
541 recorder_.Clear();
542 }
543
525 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { 544 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const {
526 GCMClient::GCMStatistics stats; 545 GCMClient::GCMStatistics stats;
527 stats.gcm_client_state = GCMClientImpl::GetStateString(); 546 stats.is_recording = recorder_.is_recording();
547 stats.gcm_client_state = GetStateString();
528 stats.connection_client_created = mcs_client_.get() != NULL; 548 stats.connection_client_created = mcs_client_.get() != NULL;
529 if (mcs_client_.get()) { 549 if (mcs_client_.get()) {
530 stats.connection_state = mcs_client_->GetStateString(); 550 stats.connection_state = mcs_client_->GetStateString();
531 // TODO(juyik): add more statistics such as message metadata list, etc. 551 stats.send_queue_size = mcs_client_->GetSendQueueSize();
552 stats.unacked_queue_size = mcs_client_->GetUnackedQueueSize();
532 } 553 }
533 if (device_checkin_info_.android_id > 0) 554 if (device_checkin_info_.android_id > 0)
534 stats.android_id = device_checkin_info_.android_id; 555 stats.android_id = device_checkin_info_.android_id;
556
557 for (std::deque<GCMStatsRecorder::SendingActivity>::const_iterator it =
558 recorder_.sending_activities().begin();
559 it != recorder_.sending_activities().end();
560 ++it) {
561 stats.sending.push_back(*it);
562 }
563 for (RegistrationInfoMap::const_iterator it = registrations_.begin();
564 it != registrations_.end(); ++it) {
565 stats.registered_app_ids.push_back(it->first);
566 }
535 return stats; 567 return stats;
536 } 568 }
537 569
538 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { 570 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) {
539 switch (message.tag()) { 571 switch (message.tag()) {
540 case kLoginResponseTag: 572 case kLoginResponseTag:
541 DVLOG(1) << "Login response received by GCM Client. Ignoring."; 573 DVLOG(1) << "Login response received by GCM Client. Ignoring.";
542 return; 574 return;
543 case kDataMessageStanzaTag: 575 case kDataMessageStanzaTag:
544 DVLOG(1) << "A downstream message received. Processing..."; 576 DVLOG(1) << "A downstream message received. Processing...";
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 send_error_details.additional_data = message_data; 685 send_error_details.additional_data = message_data;
654 send_error_details.result = SERVER_ERROR; 686 send_error_details.result = SERVER_ERROR;
655 687
656 MessageData::iterator iter = 688 MessageData::iterator iter =
657 send_error_details.additional_data.find(kSendErrorMessageIdKey); 689 send_error_details.additional_data.find(kSendErrorMessageIdKey);
658 if (iter != send_error_details.additional_data.end()) { 690 if (iter != send_error_details.additional_data.end()) {
659 send_error_details.message_id = iter->second; 691 send_error_details.message_id = iter->second;
660 send_error_details.additional_data.erase(iter); 692 send_error_details.additional_data.erase(iter);
661 } 693 }
662 694
695 recorder_.RecordIncomingSendError(
696 data_message_stanza.category(),
697 data_message_stanza.to(),
698 data_message_stanza.id(),
699 data_message_stanza.ByteSize(),
700 data_message_stanza.ttl());
663 delegate_->OnMessageSendError(data_message_stanza.category(), 701 delegate_->OnMessageSendError(data_message_stanza.category(),
664 send_error_details); 702 send_error_details);
665 } 703 }
666 704
667 } // namespace gcm 705 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698