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

Side by Side Diff: components/policy/core/common/remote_commands/remote_command_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 "components/policy/core/common/remote_commands/remote_command_job.h" 5 #include "components/policy/core/common/remote_commands/remote_command_job.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/chromeos/logging.h"
11 11
12 namespace policy { 12 namespace policy {
13 13
14 namespace { 14 namespace {
15 15
16 const int kDefaultCommandTimeoutInMinutes = 3; 16 const int kDefaultCommandTimeoutInMinutes = 3;
17 17
18 } // namespace 18 } // namespace
19 19
20 namespace em = enterprise_management; 20 namespace em = enterprise_management;
(...skipping 20 matching lines...) Expand all
41 if (command.has_age_of_command()) { 41 if (command.has_age_of_command()) {
42 // Use age of command provided by server to estimate the command issued time 42 // Use age of command provided by server to estimate the command issued time
43 // as a local TimeTick. We need to store issued time instead of age of 43 // as a local TimeTick. We need to store issued time instead of age of
44 // command, since the execution time of command might be different from the 44 // command, since the execution time of command might be different from the
45 // time we got it from server. 45 // time we got it from server.
46 // It's just an estimation since we lost the time the response was 46 // It's just an estimation since we lost the time the response was
47 // transmitted over the network. 47 // transmitted over the network.
48 issued_time_ = 48 issued_time_ =
49 now - base::TimeDelta::FromMilliseconds(command.age_of_command()); 49 now - base::TimeDelta::FromMilliseconds(command.age_of_command());
50 } else { 50 } else {
51 LOG(WARNING) << "No age_of_command provided be server for command " 51 CHROMEOS_SYSLOG(WARNING)
52 << unique_id_ << "."; 52 << "No age_of_command provided be server for command " << unique_id_
53 << ".";
53 // Otherwise, assuming the command was issued just now. 54 // Otherwise, assuming the command was issued just now.
54 issued_time_ = now; 55 issued_time_ = now;
55 } 56 }
56 57
57 if (!ParseCommandPayload(command.payload())) 58 if (!ParseCommandPayload(command.payload()))
58 return false; 59 return false;
59 60
61 switch (command.type()) {
62 case em::RemoteCommand_Type_COMMAND_ECHO_TEST: {
63 CHROMEOS_SYSLOG(WARNING) << "Remote echo test command " << unique_id_
64 << " initialized.";
65 break;
66 }
67 case em::RemoteCommand_Type_DEVICE_REBOOT: {
68 CHROMEOS_SYSLOG(WARNING) << "Remote reboot command " << unique_id_
69 << " initialized.";
70 break;
71 }
72 case em::RemoteCommand_Type_DEVICE_SCREENSHOT: {
73 CHROMEOS_SYSLOG(WARNING) << "Remote screenshot command " << unique_id_
74 << " initialized.";
75 break;
76 }
77 }
60 status_ = NOT_STARTED; 78 status_ = NOT_STARTED;
61 return true; 79 return true;
62 } 80 }
63 81
64 bool RemoteCommandJob::Run(base::TimeTicks now, 82 bool RemoteCommandJob::Run(base::TimeTicks now,
65 const FinishedCallback& finished_callback) { 83 const FinishedCallback& finished_callback) {
66 DCHECK(thread_checker_.CalledOnValidThread()); 84 DCHECK(thread_checker_.CalledOnValidThread());
67 85
68 if (status_ == INVALID) 86 if (status_ == INVALID) {
87 CHROMEOS_SYSLOG(ERROR) << "Remote command " << unique_id_ << " is invalid.";
69 return false; 88 return false;
89 }
70 90
71 DCHECK_EQ(NOT_STARTED, status_); 91 DCHECK_EQ(NOT_STARTED, status_);
72 92
73 if (IsExpired(now)) { 93 if (IsExpired(now)) {
94 CHROMEOS_SYSLOG(ERROR) << "Remote command " << unique_id_
95 << " expired (it was issued " << now - issued_time_
96 << " ago).";
74 status_ = EXPIRED; 97 status_ = EXPIRED;
75 return false; 98 return false;
76 } 99 }
77 100
78 execution_started_time_ = now; 101 execution_started_time_ = now;
79 status_ = RUNNING; 102 status_ = RUNNING;
80 finished_callback_ = finished_callback; 103 finished_callback_ = finished_callback;
81 104
82 RunImpl(base::Bind(&RemoteCommandJob::OnCommandExecutionFinishedWithResult, 105 RunImpl(base::Bind(&RemoteCommandJob::OnCommandExecutionFinishedWithResult,
83 weak_factory_.GetWeakPtr(), true), 106 weak_factory_.GetWeakPtr(), true),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 DCHECK_EQ(RUNNING, status_); 170 DCHECK_EQ(RUNNING, status_);
148 status_ = succeeded ? SUCCEEDED : FAILED; 171 status_ = succeeded ? SUCCEEDED : FAILED;
149 172
150 result_payload_ = std::move(result_payload); 173 result_payload_ = std::move(result_payload);
151 174
152 if (!finished_callback_.is_null()) 175 if (!finished_callback_.is_null())
153 finished_callback_.Run(); 176 finished_callback_.Run();
154 } 177 }
155 178
156 } // namespace policy 179 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698