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

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

Issue 293053014: Retrieve chrome build info in GCMProfileService, instead of GCMDriver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync 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 | Annotate | Revision Log
« 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"
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" 15 #include "base/strings/stringprintf.h"
16 #include "base/time/default_clock.h" 16 #include "base/time/default_clock.h"
17 #include "google_apis/gcm/base/encryptor.h" 17 #include "google_apis/gcm/base/encryptor.h"
18 #include "google_apis/gcm/base/mcs_message.h" 18 #include "google_apis/gcm/base/mcs_message.h"
19 #include "google_apis/gcm/base/mcs_util.h" 19 #include "google_apis/gcm/base/mcs_util.h"
20 #include "google_apis/gcm/engine/checkin_request.h" 20 #include "google_apis/gcm/engine/checkin_request.h"
21 #include "google_apis/gcm/engine/connection_factory_impl.h" 21 #include "google_apis/gcm/engine/connection_factory_impl.h"
22 #include "google_apis/gcm/engine/gcm_store_impl.h" 22 #include "google_apis/gcm/engine/gcm_store_impl.h"
23 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" 23 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h"
24 #include "google_apis/gcm/protocol/checkin.pb.h"
24 #include "google_apis/gcm/protocol/mcs.pb.h" 25 #include "google_apis/gcm/protocol/mcs.pb.h"
25 #include "net/http/http_network_session.h" 26 #include "net/http/http_network_session.h"
26 #include "net/url_request/url_request_context.h" 27 #include "net/url_request/url_request_context.h"
27 #include "url/gurl.h" 28 #include "url/gurl.h"
28 29
29 namespace gcm { 30 namespace gcm {
30 31
31 namespace { 32 namespace {
32 33
33 // Backoff policy. Shared across reconnection logic and checkin/(un)registration 34 // Backoff policy. Shared across reconnection logic and checkin/(un)registration
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 case MCSClient::TTL_EXCEEDED: 109 case MCSClient::TTL_EXCEEDED:
109 return GCMClient::NETWORK_ERROR; 110 return GCMClient::NETWORK_ERROR;
110 case MCSClient::SENT: 111 case MCSClient::SENT:
111 default: 112 default:
112 NOTREACHED(); 113 NOTREACHED();
113 break; 114 break;
114 } 115 }
115 return GCMClientImpl::UNKNOWN_ERROR; 116 return GCMClientImpl::UNKNOWN_ERROR;
116 } 117 }
117 118
119 void ToCheckinProtoVersion(
120 const GCMClient::ChromeBuildInfo& chrome_build_info,
121 checkin_proto::ChromeBuildProto* android_build_info) {
122 checkin_proto::ChromeBuildProto_Platform platform;
123 switch (chrome_build_info.platform) {
124 case GCMClient::PLATFORM_WIN:
125 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_WIN;
126 break;
127 case GCMClient::PLATFORM_MAC:
128 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_MAC;
129 break;
130 case GCMClient::PLATFORM_LINUX:
131 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
132 break;
133 case GCMClient::PLATFORM_IOS:
134 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_IOS;
135 break;
136 case GCMClient::PLATFORM_ANDROID:
137 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_ANDROID;
138 break;
139 case GCMClient::PLATFORM_CROS:
140 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_CROS;
141 break;
142 case GCMClient::PLATFORM_UNKNOWN:
143 // For unknown platform, return as LINUX.
144 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
145 break;
146 default:
147 NOTREACHED();
148 platform = checkin_proto::ChromeBuildProto_Platform_PLATFORM_LINUX;
149 break;
150 }
151 android_build_info->set_platform(platform);
152
153 checkin_proto::ChromeBuildProto_Channel channel;
154 switch (chrome_build_info.channel) {
155 case GCMClient::CHANNEL_STABLE:
156 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_STABLE;
157 break;
158 case GCMClient::CHANNEL_BETA:
159 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_BETA;
160 break;
161 case GCMClient::CHANNEL_DEV:
162 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_DEV;
163 break;
164 case GCMClient::CHANNEL_CANARY:
165 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_CANARY;
166 break;
167 case GCMClient::CHANNEL_UNKNOWN:
168 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
169 break;
170 default:
171 NOTREACHED();
172 channel = checkin_proto::ChromeBuildProto_Channel_CHANNEL_UNKNOWN;
173 break;
174 }
175 android_build_info->set_channel(channel);
176
177 android_build_info->set_chrome_version(chrome_build_info.version);
178 }
179
118 MessageType DecodeMessageType(const std::string& value) { 180 MessageType DecodeMessageType(const std::string& value) {
119 if (kMessageTypeDeletedMessagesKey == value) 181 if (kMessageTypeDeletedMessagesKey == value)
120 return DELETED_MESSAGES; 182 return DELETED_MESSAGES;
121 if (kMessageTypeSendErrorKey == value) 183 if (kMessageTypeSendErrorKey == value)
122 return SEND_ERROR; 184 return SEND_ERROR;
123 if (kMessageTypeDataMessage == value) 185 if (kMessageTypeDataMessage == value)
124 return DATA_MESSAGE; 186 return DATA_MESSAGE;
125 return UNKNOWN; 187 return UNKNOWN;
126 } 188 }
127 189
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 pending_unregistration_requests_deleter_( 256 pending_unregistration_requests_deleter_(
195 &pending_unregistration_requests_), 257 &pending_unregistration_requests_),
196 periodic_checkin_ptr_factory_(this), 258 periodic_checkin_ptr_factory_(this),
197 weak_ptr_factory_(this) { 259 weak_ptr_factory_(this) {
198 } 260 }
199 261
200 GCMClientImpl::~GCMClientImpl() { 262 GCMClientImpl::~GCMClientImpl() {
201 } 263 }
202 264
203 void GCMClientImpl::Initialize( 265 void GCMClientImpl::Initialize(
204 const checkin_proto::ChromeBuildProto& chrome_build_proto, 266 const ChromeBuildInfo& chrome_build_info,
205 const base::FilePath& path, 267 const base::FilePath& path,
206 const std::vector<std::string>& account_ids, 268 const std::vector<std::string>& account_ids,
207 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, 269 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner,
208 const scoped_refptr<net::URLRequestContextGetter>& 270 const scoped_refptr<net::URLRequestContextGetter>&
209 url_request_context_getter, 271 url_request_context_getter,
210 scoped_ptr<Encryptor> encryptor, 272 scoped_ptr<Encryptor> encryptor,
211 GCMClient::Delegate* delegate) { 273 GCMClient::Delegate* delegate) {
212 DCHECK_EQ(UNINITIALIZED, state_); 274 DCHECK_EQ(UNINITIALIZED, state_);
213 DCHECK(url_request_context_getter); 275 DCHECK(url_request_context_getter);
214 DCHECK(delegate); 276 DCHECK(delegate);
215 277
216 url_request_context_getter_ = url_request_context_getter; 278 url_request_context_getter_ = url_request_context_getter;
217 const net::HttpNetworkSession::Params* network_session_params = 279 const net::HttpNetworkSession::Params* network_session_params =
218 url_request_context_getter_->GetURLRequestContext()-> 280 url_request_context_getter_->GetURLRequestContext()->
219 GetNetworkSessionParams(); 281 GetNetworkSessionParams();
220 DCHECK(network_session_params); 282 DCHECK(network_session_params);
221 network_session_ = new net::HttpNetworkSession(*network_session_params); 283 network_session_ = new net::HttpNetworkSession(*network_session_params);
222 284
223 chrome_build_proto_.CopyFrom(chrome_build_proto); 285 chrome_build_info_ = chrome_build_info;
224 account_ids_ = account_ids; 286 account_ids_ = account_ids;
225 287
226 gcm_store_.reset( 288 gcm_store_.reset(
227 new GCMStoreImpl(path, blocking_task_runner, encryptor.Pass())); 289 new GCMStoreImpl(path, blocking_task_runner, encryptor.Pass()));
228 290
229 delegate_ = delegate; 291 delegate_ = delegate;
230 292
231 recorder_.SetDelegate(this); 293 recorder_.SetDelegate(this);
232 294
233 state_ = INITIALIZED; 295 state_ = INITIALIZED;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 std::vector<GURL> endpoints; 335 std::vector<GURL> endpoints;
274 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint()); 336 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint());
275 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint()); 337 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint());
276 connection_factory_ = internals_builder_->BuildConnectionFactory( 338 connection_factory_ = internals_builder_->BuildConnectionFactory(
277 endpoints, 339 endpoints,
278 kDefaultBackoffPolicy, 340 kDefaultBackoffPolicy,
279 network_session_, 341 network_session_,
280 net_log_.net_log(), 342 net_log_.net_log(),
281 &recorder_); 343 &recorder_);
282 mcs_client_ = internals_builder_->BuildMCSClient( 344 mcs_client_ = internals_builder_->BuildMCSClient(
283 chrome_build_proto_.chrome_version(), 345 chrome_build_info_.version,
284 clock_.get(), 346 clock_.get(),
285 connection_factory_.get(), 347 connection_factory_.get(),
286 gcm_store_.get(), 348 gcm_store_.get(),
287 &recorder_).Pass(); 349 &recorder_).Pass();
288 350
289 mcs_client_->Initialize( 351 mcs_client_->Initialize(
290 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), 352 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()),
291 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, 353 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS,
292 weak_ptr_factory_.GetWeakPtr()), 354 weak_ptr_factory_.GetWeakPtr()),
293 base::Bind(&GCMClientImpl::OnMessageSentToMCS, 355 base::Bind(&GCMClientImpl::OnMessageSentToMCS,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 void GCMClientImpl::ResetState() { 388 void GCMClientImpl::ResetState() {
327 state_ = UNINITIALIZED; 389 state_ = UNINITIALIZED;
328 // TODO(fgorski): reset all of the necessart objects and start over. 390 // TODO(fgorski): reset all of the necessart objects and start over.
329 } 391 }
330 392
331 void GCMClientImpl::StartCheckin() { 393 void GCMClientImpl::StartCheckin() {
332 // Make sure no checkin is in progress. 394 // Make sure no checkin is in progress.
333 if (checkin_request_.get()) 395 if (checkin_request_.get())
334 return; 396 return;
335 397
398 checkin_proto::ChromeBuildProto chrome_build_proto;
399 ToCheckinProtoVersion(chrome_build_info_, &chrome_build_proto);
336 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, 400 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id,
337 device_checkin_info_.secret, 401 device_checkin_info_.secret,
338 gservices_settings_.digest(), 402 gservices_settings_.digest(),
339 account_ids_, 403 account_ids_,
340 chrome_build_proto_); 404 chrome_build_proto);
341 checkin_request_.reset( 405 checkin_request_.reset(
342 new CheckinRequest(gservices_settings_.GetCheckinURL(), 406 new CheckinRequest(gservices_settings_.GetCheckinURL(),
343 request_info, 407 request_info,
344 kDefaultBackoffPolicy, 408 kDefaultBackoffPolicy,
345 base::Bind(&GCMClientImpl::OnCheckinCompleted, 409 base::Bind(&GCMClientImpl::OnCheckinCompleted,
346 weak_ptr_factory_.GetWeakPtr()), 410 weak_ptr_factory_.GetWeakPtr()),
347 url_request_context_getter_, 411 url_request_context_getter_,
348 &recorder_)); 412 &recorder_));
349 checkin_request_->Start(); 413 checkin_request_->Start();
350 } 414 }
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 868
805 recorder_.RecordIncomingSendError( 869 recorder_.RecordIncomingSendError(
806 data_message_stanza.category(), 870 data_message_stanza.category(),
807 data_message_stanza.to(), 871 data_message_stanza.to(),
808 data_message_stanza.id()); 872 data_message_stanza.id());
809 delegate_->OnMessageSendError(data_message_stanza.category(), 873 delegate_->OnMessageSendError(data_message_stanza.category(),
810 send_error_details); 874 send_error_details);
811 } 875 }
812 876
813 } // namespace gcm 877 } // 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