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

Side by Side Diff: chrome/browser/chromeos/policy/remote_commands/device_command_reboot_job.cc

Issue 1923943003: Add logging to remote commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused include Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 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/remote_commands/device_command_reboot_j ob.h" 5 #include "chrome/browser/chromeos/policy/remote_commands/device_command_reboot_j ob.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 bool DeviceCommandRebootJob::IsExpired(base::TimeTicks now) { 48 bool DeviceCommandRebootJob::IsExpired(base::TimeTicks now) {
49 return now > issued_time() + base::TimeDelta::FromMinutes( 49 return now > issued_time() + base::TimeDelta::FromMinutes(
50 kCommandExpirationTimeInMinutes); 50 kCommandExpirationTimeInMinutes);
51 } 51 }
52 52
53 void DeviceCommandRebootJob::RunImpl( 53 void DeviceCommandRebootJob::RunImpl(
54 const CallbackWithResult& succeeded_callback, 54 const CallbackWithResult& succeeded_callback,
55 const CallbackWithResult& failed_callback) { 55 const CallbackWithResult& failed_callback) {
56 LOG(WARNING) << "Running reboot command.";
57
56 // Determines the time delta between the command having been issued and the 58 // Determines the time delta between the command having been issued and the
57 // boot time of the system. 59 // boot time of the system.
58 const base::TimeDelta uptime = base::SysInfo::Uptime(); 60 const base::TimeDelta uptime = base::SysInfo::Uptime();
59 const base::TimeTicks boot_time = base::TimeTicks::Now() - uptime; 61 const base::TimeTicks boot_time = base::TimeTicks::Now() - uptime;
60 const base::TimeDelta delta = boot_time - issued_time(); 62 const base::TimeDelta delta = boot_time - issued_time();
61 // If the reboot command was issued before the system booted, we inform the 63 // If the reboot command was issued before the system booted, we inform the
62 // server that the reboot succeeded. Otherwise, the reboot must still be 64 // server that the reboot succeeded. Otherwise, the reboot must still be
63 // performed and we invoke it. |kMinimumUptimeInMinutes| defines a lower limit 65 // performed and we invoke it. |kMinimumUptimeInMinutes| defines a lower limit
64 // on the uptime to avoid uninterruptable reboot loops. 66 // on the uptime to avoid uninterruptable reboot loops.
65 if (delta > base::TimeDelta()) { 67 if (delta > base::TimeDelta()) {
68 LOG(WARNING) << "Reboot command already has been executed.";
Andrew T Wilson (Slow) 2016/05/04 14:43:22 Change this to something like: "Ignoring reboot co
Marton Hunyady 2016/05/09 13:48:15 Done.
66 base::ThreadTaskRunnerHandle::Get()->PostTask( 69 base::ThreadTaskRunnerHandle::Get()->PostTask(
67 FROM_HERE, base::Bind(succeeded_callback, nullptr)); 70 FROM_HERE, base::Bind(succeeded_callback, nullptr));
68 return; 71 return;
69 } 72 }
70 73
71 const base::TimeDelta kZeroTimeDelta; 74 const base::TimeDelta kZeroTimeDelta;
72 reboot_timer_.Start( 75 base::TimeDelta reboot_delay =
73 FROM_HERE,
74 std::max(base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes) - uptime, 76 std::max(base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes) - uptime,
75 kZeroTimeDelta), 77 kZeroTimeDelta);
76 base::Bind(&DeviceCommandRebootJob::Reboot, 78 if (reboot_delay > kZeroTimeDelta) {
77 weak_ptr_factory_.GetWeakPtr())); 79 LOG(WARNING) << "Rebooting in " << reboot_delay << ".";
Andrew T Wilson (Slow) 2016/05/04 14:43:22 Add a unit here, e.g. "Rebooting in 1234 msecs."
Marton Hunyady 2016/05/09 13:48:15 reboot_delay is a base::TimeDelta, so it currently
80 } else {
81 LOG(WARNING) << "Rebooting immediately.";
82 }
83 reboot_timer_.Start(FROM_HERE, reboot_delay,
84 base::Bind(&DeviceCommandRebootJob::Reboot,
85 weak_ptr_factory_.GetWeakPtr()));
78 } 86 }
79 87
80 void DeviceCommandRebootJob::TerminateImpl() { 88 void DeviceCommandRebootJob::TerminateImpl() {
81 weak_ptr_factory_.InvalidateWeakPtrs(); 89 weak_ptr_factory_.InvalidateWeakPtrs();
82 } 90 }
83 91
84 base::TimeDelta DeviceCommandRebootJob::GetCommmandTimeout() const { 92 base::TimeDelta DeviceCommandRebootJob::GetCommmandTimeout() const {
85 return base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes); 93 return base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes);
86 } 94 }
87 95
88 void DeviceCommandRebootJob::Reboot() const { 96 void DeviceCommandRebootJob::Reboot() const {
89 power_manager_client_->RequestRestart(); 97 power_manager_client_->RequestRestart();
90 } 98 }
91 99
92 } // namespace policy 100 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698