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

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: Address all code reviews. Created 6 years, 9 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 <deque>
jianli 2014/03/21 18:25:27 nit: not needed since it is included in gcm_stats_
juyik 2014/03/26 04:06:03 Done.
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
13 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "base/strings/stringprintf.h"
14 #include "base/time/default_clock.h" 17 #include "base/time/default_clock.h"
15 #include "google_apis/gcm/base/mcs_message.h" 18 #include "google_apis/gcm/base/mcs_message.h"
16 #include "google_apis/gcm/base/mcs_util.h" 19 #include "google_apis/gcm/base/mcs_util.h"
17 #include "google_apis/gcm/engine/checkin_request.h" 20 #include "google_apis/gcm/engine/checkin_request.h"
18 #include "google_apis/gcm/engine/connection_factory_impl.h" 21 #include "google_apis/gcm/engine/connection_factory_impl.h"
19 #include "google_apis/gcm/engine/gcm_store_impl.h" 22 #include "google_apis/gcm/engine/gcm_store_impl.h"
20 #include "google_apis/gcm/engine/mcs_client.h" 23 #include "google_apis/gcm/engine/mcs_client.h"
21 #include "google_apis/gcm/engine/registration_request.h" 24 #include "google_apis/gcm/engine/registration_request.h"
22 #include "google_apis/gcm/engine/unregistration_request.h" 25 #include "google_apis/gcm/engine/unregistration_request.h"
26 #include "google_apis/gcm/gcm_stats_recorder.h"
23 #include "google_apis/gcm/protocol/mcs.pb.h" 27 #include "google_apis/gcm/protocol/mcs.pb.h"
24 #include "net/http/http_network_session.h" 28 #include "net/http/http_network_session.h"
25 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
26 #include "url/gurl.h" 30 #include "url/gurl.h"
27 31
28 namespace gcm { 32 namespace gcm {
29 33
30 namespace { 34 namespace {
31 35
32 // Backoff policy. Shared across reconnection logic and checkin/(un)registration 36 // Backoff policy. Shared across reconnection logic and checkin/(un)registration
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 DCHECK(network_session_params); 193 DCHECK(network_session_params);
190 network_session_ = new net::HttpNetworkSession(*network_session_params); 194 network_session_ = new net::HttpNetworkSession(*network_session_params);
191 connection_factory_.reset(new ConnectionFactoryImpl( 195 connection_factory_.reset(new ConnectionFactoryImpl(
192 GURL(kMCSEndpoint), 196 GURL(kMCSEndpoint),
193 kDefaultBackoffPolicy, 197 kDefaultBackoffPolicy,
194 network_session_, 198 network_session_,
195 net_log_.net_log())); 199 net_log_.net_log()));
196 mcs_client_.reset(new MCSClient(chrome_build_proto_.chrome_version(), 200 mcs_client_.reset(new MCSClient(chrome_build_proto_.chrome_version(),
197 clock_.get(), 201 clock_.get(),
198 connection_factory_.get(), 202 connection_factory_.get(),
199 gcm_store_.get())); 203 gcm_store_.get(),
204 &recorder_));
200 } 205 }
201 206
202 mcs_client_->Initialize( 207 mcs_client_->Initialize(
203 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), 208 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()),
204 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, 209 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS,
205 weak_ptr_factory_.GetWeakPtr()), 210 weak_ptr_factory_.GetWeakPtr()),
206 base::Bind(&GCMClientImpl::OnMessageSentToMCS, 211 base::Bind(&GCMClientImpl::OnMessageSentToMCS,
207 weak_ptr_factory_.GetWeakPtr()), 212 weak_ptr_factory_.GetWeakPtr()),
208 result.Pass()); 213 result.Pass());
209 } 214 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 for (MessageData::const_iterator iter = message.data.begin(); 411 for (MessageData::const_iterator iter = message.data.begin();
407 iter != message.data.end(); 412 iter != message.data.end();
408 ++iter) { 413 ++iter) {
409 mcs_proto::AppData* app_data = stanza.add_app_data(); 414 mcs_proto::AppData* app_data = stanza.add_app_data();
410 app_data->set_key(iter->first); 415 app_data->set_key(iter->first);
411 app_data->set_value(iter->second); 416 app_data->set_value(iter->second);
412 } 417 }
413 418
414 MCSMessage mcs_message(stanza); 419 MCSMessage mcs_message(stanza);
415 DVLOG(1) << "MCS message size: " << mcs_message.size(); 420 DVLOG(1) << "MCS message size: " << mcs_message.size();
421 recorder_.RecordSendingWithUMACounts(
422 app_id,
423 receiver_id,
424 message.id,
425 "SEND is called",
426 base::StringPrintf("Msg size: %d bytes, TTL: %d", stanza.ByteSize(),
427 message.time_to_live),
428 "GCM.SendAPICalled",
429 1);
416 mcs_client_->SendMessage(mcs_message); 430 mcs_client_->SendMessage(mcs_message);
417 } 431 }
418 432
419 std::string GCMClientImpl::GetStateString() const { 433 std::string GCMClientImpl::GetStateString() const {
420 switch(state_) { 434 switch(state_) {
421 case GCMClientImpl::INITIALIZED: 435 case GCMClientImpl::INITIALIZED:
422 return "INITIALIZED"; 436 return "INITIALIZED";
423 case GCMClientImpl::UNINITIALIZED: 437 case GCMClientImpl::UNINITIALIZED:
424 return "UNINITIALIZED"; 438 return "UNINITIALIZED";
425 case GCMClientImpl::LOADING: 439 case GCMClientImpl::LOADING:
426 return "LOADING"; 440 return "LOADING";
427 case GCMClientImpl::INITIAL_DEVICE_CHECKIN: 441 case GCMClientImpl::INITIAL_DEVICE_CHECKIN:
428 return "INITIAL_DEVICE_CHECKIN"; 442 return "INITIAL_DEVICE_CHECKIN";
429 case GCMClientImpl::READY: 443 case GCMClientImpl::READY:
430 return "READY"; 444 return "READY";
431 default: 445 default:
432 NOTREACHED(); 446 NOTREACHED();
433 return std::string(); 447 return std::string();
434 } 448 }
435 } 449 }
436 450
451 void GCMClientImpl::SetRecording(bool recording) {
452 recorder_.SetRecording(recording);
453 }
454
455 void GCMClientImpl::ClearActivityLogs() {
456 recorder_.Clear();
457 }
458
437 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { 459 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const {
438 GCMClient::GCMStatistics stats; 460 GCMClient::GCMStatistics stats;
439 stats.gcm_client_state = GCMClientImpl::GetStateString(); 461 stats.is_recording = recorder_.is_recording();
462 stats.gcm_client_state = GetStateString();
440 stats.connection_client_created = mcs_client_.get() != NULL; 463 stats.connection_client_created = mcs_client_.get() != NULL;
441 if (mcs_client_.get()) { 464 if (mcs_client_.get()) {
442 stats.connection_state = mcs_client_->GetStateString(); 465 stats.connection_state = mcs_client_->GetStateString();
443 // TODO(juyik): add more statistics such as message metadata list, etc. 466 stats.send_queue_size = mcs_client_->GetSendQueueSize();
467 stats.unacked_queue_size = mcs_client_->GetUnackedQueueSize();
444 } 468 }
445 if (device_checkin_info_.android_id > 0) 469 if (device_checkin_info_.android_id > 0)
446 stats.android_id = device_checkin_info_.android_id; 470 stats.android_id = device_checkin_info_.android_id;
471
472 for (std::deque<GCMStatsRecorder::SendingActivity>::const_iterator it =
473 recorder_.sending_activities().begin();
474 it != recorder_.sending_activities().end();
475 ++it) {
476 stats.sending.push_back(*it);
477 }
447 return stats; 478 return stats;
448 } 479 }
449 480
450 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { 481 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) {
451 switch (message.tag()) { 482 switch (message.tag()) {
452 case kLoginResponseTag: 483 case kLoginResponseTag:
453 DVLOG(1) << "Login response received by GCM Client. Ignoring."; 484 DVLOG(1) << "Login response received by GCM Client. Ignoring.";
454 return; 485 return;
455 case kDataMessageStanzaTag: 486 case kDataMessageStanzaTag:
456 DVLOG(1) << "A downstream message received. Processing..."; 487 DVLOG(1) << "A downstream message received. Processing...";
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 send_error_details.additional_data = message_data; 585 send_error_details.additional_data = message_data;
555 send_error_details.result = SERVER_ERROR; 586 send_error_details.result = SERVER_ERROR;
556 587
557 MessageData::iterator iter = 588 MessageData::iterator iter =
558 send_error_details.additional_data.find(kSendErrorMessageIdKey); 589 send_error_details.additional_data.find(kSendErrorMessageIdKey);
559 if (iter != send_error_details.additional_data.end()) { 590 if (iter != send_error_details.additional_data.end()) {
560 send_error_details.message_id = iter->second; 591 send_error_details.message_id = iter->second;
561 send_error_details.additional_data.erase(iter); 592 send_error_details.additional_data.erase(iter);
562 } 593 }
563 594
595 recorder_.RecordSendingWithUMACounts(
596 data_message_stanza.category(),
597 data_message_stanza.to(),
598 data_message_stanza.id(),
599 "SEND ERROR is received",
600 base::StringPrintf("Msg size: %d bytes, TTL: %d",
601 data_message_stanza.ByteSize(),
602 data_message_stanza.ttl()),
603 "GCM.SendMessageErrors",
604 1);
564 delegate_->OnMessageSendError(data_message_stanza.category(), 605 delegate_->OnMessageSendError(data_message_stanza.category(),
565 send_error_details); 606 send_error_details);
566 } 607 }
567 608
568 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) { 609 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) {
569 mcs_client_ = mcs_client.Pass(); 610 mcs_client_ = mcs_client.Pass();
570 } 611 }
571 612
572 } // namespace gcm 613 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698