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

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

Issue 240583002: Revert 264313 "Add activity recording capability to gcm internal..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
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/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h"
16 #include "base/time/default_clock.h" 15 #include "base/time/default_clock.h"
17 #include "google_apis/gcm/base/mcs_message.h" 16 #include "google_apis/gcm/base/mcs_message.h"
18 #include "google_apis/gcm/base/mcs_util.h" 17 #include "google_apis/gcm/base/mcs_util.h"
19 #include "google_apis/gcm/engine/checkin_request.h" 18 #include "google_apis/gcm/engine/checkin_request.h"
20 #include "google_apis/gcm/engine/connection_factory_impl.h" 19 #include "google_apis/gcm/engine/connection_factory_impl.h"
21 #include "google_apis/gcm/engine/gcm_store_impl.h" 20 #include "google_apis/gcm/engine/gcm_store_impl.h"
22 #include "google_apis/gcm/engine/mcs_client.h" 21 #include "google_apis/gcm/engine/mcs_client.h"
23 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
24 #include "google_apis/gcm/protocol/mcs.pb.h" 22 #include "google_apis/gcm/protocol/mcs.pb.h"
25 #include "net/http/http_network_session.h" 23 #include "net/http/http_network_session.h"
26 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
27 #include "url/gurl.h" 25 #include "url/gurl.h"
28 26
29 namespace gcm { 27 namespace gcm {
30 28
31 namespace { 29 namespace {
32 30
33 // Backoff policy. Shared across reconnection logic and checkin/(un)registration 31 // Backoff policy. Shared across reconnection logic and checkin/(un)registration
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 GCMInternalsBuilder::~GCMInternalsBuilder() {} 123 GCMInternalsBuilder::~GCMInternalsBuilder() {}
126 124
127 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() { 125 scoped_ptr<base::Clock> GCMInternalsBuilder::BuildClock() {
128 return make_scoped_ptr<base::Clock>(new base::DefaultClock()); 126 return make_scoped_ptr<base::Clock>(new base::DefaultClock());
129 } 127 }
130 128
131 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient( 129 scoped_ptr<MCSClient> GCMInternalsBuilder::BuildMCSClient(
132 const std::string& version, 130 const std::string& version,
133 base::Clock* clock, 131 base::Clock* clock,
134 ConnectionFactory* connection_factory, 132 ConnectionFactory* connection_factory,
135 GCMStore* gcm_store, 133 GCMStore* gcm_store) {
136 GCMStatsRecorder* recorder) {
137 return make_scoped_ptr<MCSClient>( 134 return make_scoped_ptr<MCSClient>(
138 new MCSClient(version, 135 new MCSClient(version,
139 clock, 136 clock,
140 connection_factory, 137 connection_factory,
141 gcm_store, 138 gcm_store));
142 recorder));
143 } 139 }
144 140
145 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory( 141 scoped_ptr<ConnectionFactory> GCMInternalsBuilder::BuildConnectionFactory(
146 const std::vector<GURL>& endpoints, 142 const std::vector<GURL>& endpoints,
147 const net::BackoffEntry::Policy& backoff_policy, 143 const net::BackoffEntry::Policy& backoff_policy,
148 scoped_refptr<net::HttpNetworkSession> network_session, 144 scoped_refptr<net::HttpNetworkSession> network_session,
149 net::NetLog* net_log) { 145 net::NetLog* net_log) {
150 return make_scoped_ptr<ConnectionFactory>( 146 return make_scoped_ptr<ConnectionFactory>(
151 new ConnectionFactoryImpl(endpoints, 147 new ConnectionFactoryImpl(endpoints,
152 backoff_policy, 148 backoff_policy,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 endpoints.push_back(GURL(kMCSEndpointFallback)); 234 endpoints.push_back(GURL(kMCSEndpointFallback));
239 connection_factory_ = internals_builder_->BuildConnectionFactory( 235 connection_factory_ = internals_builder_->BuildConnectionFactory(
240 endpoints, 236 endpoints,
241 kDefaultBackoffPolicy, 237 kDefaultBackoffPolicy,
242 network_session_, 238 network_session_,
243 net_log_.net_log()); 239 net_log_.net_log());
244 mcs_client_ = internals_builder_->BuildMCSClient( 240 mcs_client_ = internals_builder_->BuildMCSClient(
245 chrome_build_proto_.chrome_version(), 241 chrome_build_proto_.chrome_version(),
246 clock_.get(), 242 clock_.get(),
247 connection_factory_.get(), 243 connection_factory_.get(),
248 gcm_store_.get(), 244 gcm_store_.get()).Pass();
249 &recorder_).Pass();
250 245
251 mcs_client_->Initialize( 246 mcs_client_->Initialize(
252 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), 247 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()),
253 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, 248 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS,
254 weak_ptr_factory_.GetWeakPtr()), 249 weak_ptr_factory_.GetWeakPtr()),
255 base::Bind(&GCMClientImpl::OnMessageSentToMCS, 250 base::Bind(&GCMClientImpl::OnMessageSentToMCS,
256 weak_ptr_factory_.GetWeakPtr()), 251 weak_ptr_factory_.GetWeakPtr()),
257 result.Pass()); 252 result.Pass());
258 } 253 }
259 254
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 case GCMClientImpl::INITIAL_DEVICE_CHECKIN: 550 case GCMClientImpl::INITIAL_DEVICE_CHECKIN:
556 return "INITIAL_DEVICE_CHECKIN"; 551 return "INITIAL_DEVICE_CHECKIN";
557 case GCMClientImpl::READY: 552 case GCMClientImpl::READY:
558 return "READY"; 553 return "READY";
559 default: 554 default:
560 NOTREACHED(); 555 NOTREACHED();
561 return std::string(); 556 return std::string();
562 } 557 }
563 } 558 }
564 559
565 void GCMClientImpl::SetRecording(bool recording) {
566 recorder_.SetRecording(recording);
567 }
568
569 void GCMClientImpl::ClearActivityLogs() {
570 recorder_.Clear();
571 }
572
573 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { 560 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const {
574 GCMClient::GCMStatistics stats; 561 GCMClient::GCMStatistics stats;
575 stats.gcm_client_created = true; 562 stats.gcm_client_state = GCMClientImpl::GetStateString();
576 stats.is_recording = recorder_.is_recording();
577 stats.gcm_client_state = GetStateString();
578 stats.connection_client_created = mcs_client_.get() != NULL; 563 stats.connection_client_created = mcs_client_.get() != NULL;
579 if (mcs_client_.get()) { 564 if (mcs_client_.get()) {
580 stats.connection_state = mcs_client_->GetStateString(); 565 stats.connection_state = mcs_client_->GetStateString();
581 stats.send_queue_size = mcs_client_->GetSendQueueSize(); 566 // TODO(juyik): add more statistics such as message metadata list, etc.
582 stats.resend_queue_size = mcs_client_->GetResendQueueSize();
583 } 567 }
584 if (device_checkin_info_.android_id > 0) 568 if (device_checkin_info_.android_id > 0)
585 stats.android_id = device_checkin_info_.android_id; 569 stats.android_id = device_checkin_info_.android_id;
586 recorder_.CollectSendingActivities(&stats.sending_activities);
587
588 for (RegistrationInfoMap::const_iterator it = registrations_.begin();
589 it != registrations_.end(); ++it) {
590 stats.registered_app_ids.push_back(it->first);
591 }
592 return stats; 570 return stats;
593 } 571 }
594 572
595 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { 573 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) {
596 switch (message.tag()) { 574 switch (message.tag()) {
597 case kLoginResponseTag: 575 case kLoginResponseTag:
598 DVLOG(1) << "Login response received by GCM Client. Ignoring."; 576 DVLOG(1) << "Login response received by GCM Client. Ignoring.";
599 return; 577 return;
600 case kDataMessageStanzaTag: 578 case kDataMessageStanzaTag:
601 DVLOG(1) << "A downstream message received. Processing..."; 579 DVLOG(1) << "A downstream message received. Processing...";
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 send_error_details.additional_data = message_data; 688 send_error_details.additional_data = message_data;
711 send_error_details.result = SERVER_ERROR; 689 send_error_details.result = SERVER_ERROR;
712 690
713 MessageData::iterator iter = 691 MessageData::iterator iter =
714 send_error_details.additional_data.find(kSendErrorMessageIdKey); 692 send_error_details.additional_data.find(kSendErrorMessageIdKey);
715 if (iter != send_error_details.additional_data.end()) { 693 if (iter != send_error_details.additional_data.end()) {
716 send_error_details.message_id = iter->second; 694 send_error_details.message_id = iter->second;
717 send_error_details.additional_data.erase(iter); 695 send_error_details.additional_data.erase(iter);
718 } 696 }
719 697
720 recorder_.RecordIncomingSendError(
721 data_message_stanza.category(),
722 data_message_stanza.to(),
723 data_message_stanza.id());
724 delegate_->OnMessageSendError(data_message_stanza.category(), 698 delegate_->OnMessageSendError(data_message_stanza.category(),
725 send_error_details); 699 send_error_details);
726 } 700 }
727 701
728 } // namespace gcm 702 } // namespace gcm
OLDNEW
« no previous file with comments | « trunk/src/google_apis/gcm/gcm_client_impl.h ('k') | trunk/src/google_apis/gcm/gcm_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698