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

Side by Side Diff: chrome/browser/chromeos/policy/heartbeat_scheduler.cc

Issue 1258313002: Send GCM id to DMServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adopt upstream protobuf changes Created 5 years, 4 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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "chrome/browser/chromeos/policy/heartbeat_scheduler.h" 5 #include "chrome/browser/chromeos/policy/heartbeat_scheduler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/location.h" 12 #include "base/location.h"
11 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
12 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
15 #include "components/gcm_driver/gcm_driver.h" 17 #include "components/gcm_driver/gcm_driver.h"
16 18
17 namespace { 19 namespace {
18 const int kMinHeartbeatIntervalMs = 30 * 1000; // 30 seconds 20 const int kMinHeartbeatIntervalMs = 30 * 1000; // 30 seconds
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 case gcm::GCMClient::ASYNC_OPERATION_PENDING: 155 case gcm::GCMClient::ASYNC_OPERATION_PENDING:
154 case gcm::GCMClient::TTL_EXCEEDED: 156 case gcm::GCMClient::TTL_EXCEEDED:
155 default: 157 default:
156 NOTREACHED() << "Unexpected GCMDriver::Register() result: " << result; 158 NOTREACHED() << "Unexpected GCMDriver::Register() result: " << result;
157 break; 159 break;
158 } 160 }
159 } 161 }
160 162
161 HeartbeatScheduler::HeartbeatScheduler( 163 HeartbeatScheduler::HeartbeatScheduler(
162 gcm::GCMDriver* driver, 164 gcm::GCMDriver* driver,
165 policy::CloudPolicyClient* cloud_policy_client,
163 const std::string& enrollment_domain, 166 const std::string& enrollment_domain,
164 const std::string& device_id, 167 const std::string& device_id,
165 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 168 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
166 : task_runner_(task_runner), 169 : task_runner_(task_runner),
167 enrollment_domain_(enrollment_domain), 170 enrollment_domain_(enrollment_domain),
168 device_id_(device_id), 171 device_id_(device_id),
169 heartbeat_enabled_(false), 172 heartbeat_enabled_(false),
170 heartbeat_interval_(base::TimeDelta::FromMilliseconds( 173 heartbeat_interval_(
171 kDefaultHeartbeatIntervalMs)), 174 base::TimeDelta::FromMilliseconds(kDefaultHeartbeatIntervalMs)),
175 cloud_policy_client_(cloud_policy_client),
172 gcm_driver_(driver), 176 gcm_driver_(driver),
173 weak_factory_(this) { 177 weak_factory_(this) {
174 // If no GCMDriver (e.g. this is loaded as part of an unrelated unit test) 178 // If no GCMDriver (e.g. this is loaded as part of an unrelated unit test)
175 // do nothing as no heartbeats can be sent. 179 // do nothing as no heartbeats can be sent.
176 if (!gcm_driver_) 180 if (!gcm_driver_)
177 return; 181 return;
178 182
179 heartbeat_frequency_observer_ = 183 heartbeat_frequency_observer_ =
180 chromeos::CrosSettings::Get()->AddSettingsObserver( 184 chromeos::CrosSettings::Get()->AddSettingsObserver(
181 chromeos::kHeartbeatFrequency, 185 chromeos::kHeartbeatFrequency,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 task_runner_->PostDelayedTask( 294 task_runner_->PostDelayedTask(
291 FROM_HERE, heartbeat_callback_.callback(), delay); 295 FROM_HERE, heartbeat_callback_.callback(), delay);
292 } 296 }
293 297
294 void HeartbeatScheduler::OnRegistrationComplete( 298 void HeartbeatScheduler::OnRegistrationComplete(
295 const std::string& registration_id) { 299 const std::string& registration_id) {
296 DCHECK(!registration_id.empty()); 300 DCHECK(!registration_id.empty());
297 registration_helper_.reset(); 301 registration_helper_.reset();
298 registration_id_ = registration_id; 302 registration_id_ = registration_id;
299 303
304 if (cloud_policy_client_) {
305 // TODO(binjin): Avoid sending the same GCM id to the server.
306 // See http://crbug.com/516375
307 cloud_policy_client_->UpdateGcmId(
308 registration_id,
309 base::Bind(&HeartbeatScheduler::OnGcmIdUpdateRequestSent,
310 weak_factory_.GetWeakPtr()));
311 }
312
300 // Now that GCM registration is complete, start sending heartbeats. 313 // Now that GCM registration is complete, start sending heartbeats.
301 ScheduleNextHeartbeat(); 314 ScheduleNextHeartbeat();
302 } 315 }
303 316
304 void HeartbeatScheduler::SendHeartbeat() { 317 void HeartbeatScheduler::SendHeartbeat() {
305 DCHECK(!registration_id_.empty()); 318 DCHECK(!registration_id_.empty());
306 if (!gcm_driver_ || !heartbeat_enabled_) 319 if (!gcm_driver_ || !heartbeat_enabled_)
307 return; 320 return;
308 321
309 gcm::OutgoingMessage message; 322 gcm::OutgoingMessage message;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 const std::string& app_id, 378 const std::string& app_id,
366 const gcm::GCMClient::SendErrorDetails& details) { 379 const gcm::GCMClient::SendErrorDetails& details) {
367 // Ignore send errors - we already are notified above in OnHeartbeatSent(). 380 // Ignore send errors - we already are notified above in OnHeartbeatSent().
368 } 381 }
369 382
370 void HeartbeatScheduler::OnSendAcknowledged(const std::string& app_id, 383 void HeartbeatScheduler::OnSendAcknowledged(const std::string& app_id,
371 const std::string& message_id) { 384 const std::string& message_id) {
372 DVLOG(1) << "Heartbeat sent with message_id: " << message_id; 385 DVLOG(1) << "Heartbeat sent with message_id: " << message_id;
373 } 386 }
374 387
388 void HeartbeatScheduler::OnGcmIdUpdateRequestSent(bool success) {
389 // TODO(binjin): Handle the failure, probably by exponential backoff.
390 LOG_IF(WARNING, !success) << "Failed to send GCM id to DM server";
391 }
392
375 } // namespace policy 393 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/heartbeat_scheduler.h ('k') | chrome/browser/chromeos/policy/heartbeat_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698