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

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: Syslog logging in upload_job_impl Created 4 years, 6 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/chromeos/logging.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
13 #include "base/sys_info.h" 14 #include "base/sys_info.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "chromeos/dbus/power_manager_client.h" 17 #include "chromeos/dbus/power_manager_client.h"
17 #include "policy/proto/device_management_backend.pb.h" 18 #include "policy/proto/device_management_backend.pb.h"
18 19
19 namespace policy { 20 namespace policy {
(...skipping 26 matching lines...) Expand all
46 } 47 }
47 48
48 bool DeviceCommandRebootJob::IsExpired(base::TimeTicks now) { 49 bool DeviceCommandRebootJob::IsExpired(base::TimeTicks now) {
49 return now > issued_time() + base::TimeDelta::FromMinutes( 50 return now > issued_time() + base::TimeDelta::FromMinutes(
50 kCommandExpirationTimeInMinutes); 51 kCommandExpirationTimeInMinutes);
51 } 52 }
52 53
53 void DeviceCommandRebootJob::RunImpl( 54 void DeviceCommandRebootJob::RunImpl(
54 const CallbackWithResult& succeeded_callback, 55 const CallbackWithResult& succeeded_callback,
55 const CallbackWithResult& failed_callback) { 56 const CallbackWithResult& failed_callback) {
57 CHROMEOS_SYSLOG(WARNING) << "Running reboot command.";
58
56 // Determines the time delta between the command having been issued and the 59 // Determines the time delta between the command having been issued and the
57 // boot time of the system. 60 // boot time of the system.
58 const base::TimeDelta uptime = base::SysInfo::Uptime(); 61 const base::TimeDelta uptime = base::SysInfo::Uptime();
59 const base::TimeTicks boot_time = base::TimeTicks::Now() - uptime; 62 const base::TimeTicks boot_time = base::TimeTicks::Now() - uptime;
60 const base::TimeDelta delta = boot_time - issued_time(); 63 const base::TimeDelta delta = boot_time - issued_time();
61 // If the reboot command was issued before the system booted, we inform the 64 // 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 65 // server that the reboot succeeded. Otherwise, the reboot must still be
63 // performed and we invoke it. |kMinimumUptimeInMinutes| defines a lower limit 66 // performed and we invoke it. |kMinimumUptimeInMinutes| defines a lower limit
64 // on the uptime to avoid uninterruptable reboot loops. 67 // on the uptime to avoid uninterruptable reboot loops.
65 if (delta > base::TimeDelta()) { 68 if (delta > base::TimeDelta()) {
69 CHROMEOS_SYSLOG(WARNING) << "Ignoring reboot command issued " << delta
70 << " before current boot time";
66 base::ThreadTaskRunnerHandle::Get()->PostTask( 71 base::ThreadTaskRunnerHandle::Get()->PostTask(
67 FROM_HERE, base::Bind(succeeded_callback, nullptr)); 72 FROM_HERE, base::Bind(succeeded_callback, nullptr));
68 return; 73 return;
69 } 74 }
70 75
71 const base::TimeDelta kZeroTimeDelta; 76 const base::TimeDelta kZeroTimeDelta;
72 reboot_timer_.Start( 77 base::TimeDelta reboot_delay =
73 FROM_HERE,
74 std::max(base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes) - uptime, 78 std::max(base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes) - uptime,
75 kZeroTimeDelta), 79 kZeroTimeDelta);
76 base::Bind(&DeviceCommandRebootJob::Reboot, 80 if (reboot_delay > kZeroTimeDelta) {
77 weak_ptr_factory_.GetWeakPtr())); 81 CHROMEOS_SYSLOG(WARNING) << "Rebooting in " << reboot_delay << ".";
82 } else {
83 CHROMEOS_SYSLOG(WARNING) << "Rebooting immediately.";
84 }
85 reboot_timer_.Start(FROM_HERE, reboot_delay,
86 base::Bind(&DeviceCommandRebootJob::Reboot,
87 weak_ptr_factory_.GetWeakPtr()));
78 } 88 }
79 89
80 void DeviceCommandRebootJob::TerminateImpl() { 90 void DeviceCommandRebootJob::TerminateImpl() {
81 weak_ptr_factory_.InvalidateWeakPtrs(); 91 weak_ptr_factory_.InvalidateWeakPtrs();
82 } 92 }
83 93
84 base::TimeDelta DeviceCommandRebootJob::GetCommmandTimeout() const { 94 base::TimeDelta DeviceCommandRebootJob::GetCommmandTimeout() const {
85 return base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes); 95 return base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes);
86 } 96 }
87 97
88 void DeviceCommandRebootJob::Reboot() const { 98 void DeviceCommandRebootJob::Reboot() const {
89 power_manager_client_->RequestRestart(); 99 power_manager_client_->RequestRestart();
90 } 100 }
91 101
92 } // namespace policy 102 } // namespace policy
OLDNEW
« no previous file with comments | « base/chromeos/logging.h ('k') | chrome/browser/chromeos/policy/remote_commands/device_command_screenshot_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698