OLD | NEW |
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_commands_service.
h" | 5 #include "components/policy/core/common/remote_commands/remote_commands_service.
h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/chromeos/logging.h" |
13 #include "base/time/tick_clock.h" | 13 #include "base/time/tick_clock.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 15 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
16 #include "components/policy/core/common/remote_commands/remote_commands_factory.
h" | 16 #include "components/policy/core/common/remote_commands/remote_commands_factory.
h" |
17 | 17 |
18 namespace policy { | 18 namespace policy { |
19 | 19 |
20 namespace em = enterprise_management; | 20 namespace em = enterprise_management; |
21 | 21 |
22 RemoteCommandsService::RemoteCommandsService( | 22 RemoteCommandsService::RemoteCommandsService( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 71 } |
72 | 72 |
73 void RemoteCommandsService::SetClockForTesting( | 73 void RemoteCommandsService::SetClockForTesting( |
74 std::unique_ptr<base::TickClock> clock) { | 74 std::unique_ptr<base::TickClock> clock) { |
75 queue_.SetClockForTesting(std::move(clock)); | 75 queue_.SetClockForTesting(std::move(clock)); |
76 } | 76 } |
77 | 77 |
78 void RemoteCommandsService::EnqueueCommand( | 78 void RemoteCommandsService::EnqueueCommand( |
79 const enterprise_management::RemoteCommand& command) { | 79 const enterprise_management::RemoteCommand& command) { |
80 if (!command.has_type() || !command.has_unique_id()) { | 80 if (!command.has_type() || !command.has_unique_id()) { |
81 LOG(WARNING) << "Invalid remote command from server."; | 81 CHROMEOS_SYSLOG(ERROR) << "Invalid remote command from server."; |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 // If the command is already fetched, ignore it. | 85 // If the command is already fetched, ignore it. |
86 if (std::find(fetched_command_ids_.begin(), fetched_command_ids_.end(), | 86 if (std::find(fetched_command_ids_.begin(), fetched_command_ids_.end(), |
87 command.unique_id()) != fetched_command_ids_.end()) { | 87 command.unique_id()) != fetched_command_ids_.end()) { |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 fetched_command_ids_.push_back(command.unique_id()); | 91 fetched_command_ids_.push_back(command.unique_id()); |
92 | 92 |
93 std::unique_ptr<RemoteCommandJob> job = | 93 std::unique_ptr<RemoteCommandJob> job = |
94 factory_->BuildJobForType(command.type()); | 94 factory_->BuildJobForType(command.type()); |
95 | 95 |
96 if (!job || !job->Init(queue_.GetNowTicks(), command)) { | 96 if (!job || !job->Init(queue_.GetNowTicks(), command)) { |
| 97 CHROMEOS_SYSLOG(ERROR) << "Initialization of remote command failed."; |
97 em::RemoteCommandResult ignored_result; | 98 em::RemoteCommandResult ignored_result; |
98 ignored_result.set_result( | 99 ignored_result.set_result( |
99 em::RemoteCommandResult_ResultType_RESULT_IGNORED); | 100 em::RemoteCommandResult_ResultType_RESULT_IGNORED); |
100 ignored_result.set_unique_id(command.unique_id()); | 101 ignored_result.set_unique_id(command.unique_id()); |
101 unsent_results_.push_back(ignored_result); | 102 unsent_results_.push_back(ignored_result); |
102 return; | 103 return; |
103 } | 104 } |
104 | 105 |
105 queue_.AddJob(std::move(job)); | 106 queue_.AddJob(std::move(job)); |
106 } | 107 } |
(...skipping 24 matching lines...) Expand all Loading... |
131 command->GetResultPayload(); | 132 command->GetResultPayload(); |
132 if (result_payload) | 133 if (result_payload) |
133 result.set_payload(*result_payload); | 134 result.set_payload(*result_payload); |
134 } else if (command->status() == RemoteCommandJob::EXPIRED || | 135 } else if (command->status() == RemoteCommandJob::EXPIRED || |
135 command->status() == RemoteCommandJob::INVALID) { | 136 command->status() == RemoteCommandJob::INVALID) { |
136 result.set_result(em::RemoteCommandResult_ResultType_RESULT_IGNORED); | 137 result.set_result(em::RemoteCommandResult_ResultType_RESULT_IGNORED); |
137 } else { | 138 } else { |
138 NOTREACHED(); | 139 NOTREACHED(); |
139 } | 140 } |
140 | 141 |
| 142 CHROMEOS_SYSLOG(WARNING) << "Remote command " << command->unique_id() |
| 143 << " finished with result " << result.result(); |
| 144 |
141 unsent_results_.push_back(result); | 145 unsent_results_.push_back(result); |
142 | 146 |
143 FetchRemoteCommands(); | 147 FetchRemoteCommands(); |
144 } | 148 } |
145 | 149 |
146 void RemoteCommandsService::OnRemoteCommandsFetched( | 150 void RemoteCommandsService::OnRemoteCommandsFetched( |
147 DeviceManagementStatus status, | 151 DeviceManagementStatus status, |
148 const std::vector<enterprise_management::RemoteCommand>& commands) { | 152 const std::vector<enterprise_management::RemoteCommand>& commands) { |
149 DCHECK(command_fetch_in_progress_); | 153 DCHECK(command_fetch_in_progress_); |
150 command_fetch_in_progress_ = false; | 154 command_fetch_in_progress_ = false; |
151 | 155 |
152 // TODO(binjin): Add retrying on errors. See http://crbug.com/466572. | 156 // TODO(binjin): Add retrying on errors. See http://crbug.com/466572. |
153 if (status == DM_STATUS_SUCCESS) { | 157 if (status == DM_STATUS_SUCCESS) { |
154 for (const auto& command : commands) | 158 for (const auto& command : commands) |
155 EnqueueCommand(command); | 159 EnqueueCommand(command); |
156 } | 160 } |
157 | 161 |
158 // Start another fetch request job immediately if there are unsent command | 162 // Start another fetch request job immediately if there are unsent command |
159 // results or enqueued fetch requests. | 163 // results or enqueued fetch requests. |
160 if (!unsent_results_.empty() || has_enqueued_fetch_request_) | 164 if (!unsent_results_.empty() || has_enqueued_fetch_request_) |
161 FetchRemoteCommands(); | 165 FetchRemoteCommands(); |
162 } | 166 } |
163 | 167 |
164 } // namespace policy | 168 } // namespace policy |
OLD | NEW |