| OLD | NEW |
| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 pending_unregistrations_deleter_(&pending_unregistrations_), | 119 pending_unregistrations_deleter_(&pending_unregistrations_), |
| 120 weak_ptr_factory_(this) { | 120 weak_ptr_factory_(this) { |
| 121 } | 121 } |
| 122 | 122 |
| 123 GCMClientImpl::~GCMClientImpl() { | 123 GCMClientImpl::~GCMClientImpl() { |
| 124 } | 124 } |
| 125 | 125 |
| 126 void GCMClientImpl::Initialize( | 126 void GCMClientImpl::Initialize( |
| 127 const checkin_proto::ChromeBuildProto& chrome_build_proto, | 127 const checkin_proto::ChromeBuildProto& chrome_build_proto, |
| 128 const base::FilePath& path, | 128 const base::FilePath& path, |
| 129 const std::vector<std::string>& account_ids, |
| 129 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, | 130 const scoped_refptr<base::SequencedTaskRunner>& blocking_task_runner, |
| 130 const scoped_refptr<net::URLRequestContextGetter>& | 131 const scoped_refptr<net::URLRequestContextGetter>& |
| 131 url_request_context_getter, | 132 url_request_context_getter, |
| 132 Delegate* delegate) { | 133 Delegate* delegate) { |
| 133 DCHECK_EQ(UNINITIALIZED, state_); | 134 DCHECK_EQ(UNINITIALIZED, state_); |
| 134 DCHECK(url_request_context_getter); | 135 DCHECK(url_request_context_getter); |
| 135 DCHECK(delegate); | 136 DCHECK(delegate); |
| 136 | 137 |
| 137 chrome_build_proto_.CopyFrom(chrome_build_proto); | 138 chrome_build_proto_.CopyFrom(chrome_build_proto); |
| 138 url_request_context_getter_ = url_request_context_getter; | 139 url_request_context_getter_ = url_request_context_getter; |
| 140 account_ids_ = account_ids; |
| 139 | 141 |
| 140 gcm_store_.reset(new GCMStoreImpl(false, path, blocking_task_runner)); | 142 gcm_store_.reset(new GCMStoreImpl(false, path, blocking_task_runner)); |
| 141 gcm_store_->Load(base::Bind(&GCMClientImpl::OnLoadCompleted, | 143 gcm_store_->Load(base::Bind(&GCMClientImpl::OnLoadCompleted, |
| 142 weak_ptr_factory_.GetWeakPtr())); | 144 weak_ptr_factory_.GetWeakPtr())); |
| 143 | 145 |
| 144 delegate_ = delegate; | 146 delegate_ = delegate; |
| 145 | 147 |
| 146 // |mcs_client_| might already be set for testing at this point. No need to | 148 // |mcs_client_| might already be set for testing at this point. No need to |
| 147 // create a |connection_factory_|. | 149 // create a |connection_factory_|. |
| 148 if (!mcs_client_.get()) { | 150 if (!mcs_client_.get()) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 device_checkin_info_.secret); | 227 device_checkin_info_.secret); |
| 226 } | 228 } |
| 227 | 229 |
| 228 void GCMClientImpl::ResetState() { | 230 void GCMClientImpl::ResetState() { |
| 229 state_ = UNINITIALIZED; | 231 state_ = UNINITIALIZED; |
| 230 // TODO(fgorski): reset all of the necessart objects and start over. | 232 // TODO(fgorski): reset all of the necessart objects and start over. |
| 231 } | 233 } |
| 232 | 234 |
| 233 void GCMClientImpl::StartCheckin(const CheckinInfo& checkin_info) { | 235 void GCMClientImpl::StartCheckin(const CheckinInfo& checkin_info) { |
| 234 checkin_request_.reset( | 236 checkin_request_.reset( |
| 235 new CheckinRequest( | 237 new CheckinRequest(base::Bind(&GCMClientImpl::OnCheckinCompleted, |
| 236 base::Bind(&GCMClientImpl::OnCheckinCompleted, | 238 weak_ptr_factory_.GetWeakPtr()), |
| 237 weak_ptr_factory_.GetWeakPtr()), | 239 kDefaultBackoffPolicy, |
| 238 kDefaultBackoffPolicy, | 240 chrome_build_proto_, |
| 239 chrome_build_proto_, | 241 checkin_info.android_id, |
| 240 checkin_info.android_id, | 242 checkin_info.secret, |
| 241 checkin_info.secret, | 243 account_ids_, |
| 242 url_request_context_getter_)); | 244 url_request_context_getter_)); |
| 243 checkin_request_->Start(); | 245 checkin_request_->Start(); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void GCMClientImpl::OnCheckinCompleted(uint64 android_id, | 248 void GCMClientImpl::OnCheckinCompleted(uint64 android_id, |
| 247 uint64 security_token) { | 249 uint64 security_token) { |
| 248 checkin_request_.reset(); | 250 checkin_request_.reset(); |
| 249 | 251 |
| 250 CheckinInfo checkin_info; | 252 CheckinInfo checkin_info; |
| 251 checkin_info.android_id = android_id; | 253 checkin_info.android_id = android_id; |
| 252 checkin_info.secret = security_token; | 254 checkin_info.secret = security_token; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (iter != incoming_message.data.end()) | 490 if (iter != incoming_message.data.end()) |
| 489 message_id = iter->second; | 491 message_id = iter->second; |
| 490 delegate->OnMessageSendError(app_id, message_id, SERVER_ERROR); | 492 delegate->OnMessageSendError(app_id, message_id, SERVER_ERROR); |
| 491 } | 493 } |
| 492 | 494 |
| 493 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) { | 495 void GCMClientImpl::SetMCSClientForTesting(scoped_ptr<MCSClient> mcs_client) { |
| 494 mcs_client_ = mcs_client.Pass(); | 496 mcs_client_ = mcs_client.Pass(); |
| 495 } | 497 } |
| 496 | 498 |
| 497 } // namespace gcm | 499 } // namespace gcm |
| OLD | NEW |