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

Side by Side Diff: components/policy/core/common/remote_commands/remote_commands_service.cc

Issue 2453993004: Match server version of DM API proto. (Closed)
Patch Set: Style and comment fixes. Created 4 years, 1 month 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_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
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return true; 76 return true;
77 } 77 }
78 78
79 void RemoteCommandsService::SetClockForTesting( 79 void RemoteCommandsService::SetClockForTesting(
80 std::unique_ptr<base::TickClock> clock) { 80 std::unique_ptr<base::TickClock> clock) {
81 queue_.SetClockForTesting(std::move(clock)); 81 queue_.SetClockForTesting(std::move(clock));
82 } 82 }
83 83
84 void RemoteCommandsService::EnqueueCommand( 84 void RemoteCommandsService::EnqueueCommand(
85 const enterprise_management::RemoteCommand& command) { 85 const enterprise_management::RemoteCommand& command) {
86 if (!command.has_type() || !command.has_unique_id()) { 86 if (!command.has_type() || !command.has_command_id()) {
87 SYSLOG(ERROR) << "Invalid remote command from server."; 87 SYSLOG(ERROR) << "Invalid remote command from server.";
88 return; 88 return;
89 } 89 }
90 90
91 // If the command is already fetched, ignore it. 91 // If the command is already fetched, ignore it.
92 if (std::find(fetched_command_ids_.begin(), fetched_command_ids_.end(), 92 if (std::find(fetched_command_ids_.begin(), fetched_command_ids_.end(),
93 command.unique_id()) != fetched_command_ids_.end()) { 93 command.command_id()) != fetched_command_ids_.end()) {
94 return; 94 return;
95 } 95 }
96 96
97 fetched_command_ids_.push_back(command.unique_id()); 97 fetched_command_ids_.push_back(command.command_id());
98 98
99 std::unique_ptr<RemoteCommandJob> job = 99 std::unique_ptr<RemoteCommandJob> job =
100 factory_->BuildJobForType(command.type()); 100 factory_->BuildJobForType(command.type());
101 101
102 if (!job || !job->Init(queue_.GetNowTicks(), command)) { 102 if (!job || !job->Init(queue_.GetNowTicks(), command)) {
103 SYSLOG(ERROR) << "Initialization of remote command failed."; 103 SYSLOG(ERROR) << "Initialization of remote command failed.";
104 em::RemoteCommandResult ignored_result; 104 em::RemoteCommandResult ignored_result;
105 ignored_result.set_result( 105 ignored_result.set_result(
106 em::RemoteCommandResult_ResultType_RESULT_IGNORED); 106 em::RemoteCommandResult_ResultType_RESULT_IGNORED);
107 ignored_result.set_unique_id(command.unique_id()); 107 ignored_result.set_command_id(command.command_id());
108 unsent_results_.push_back(ignored_result); 108 unsent_results_.push_back(ignored_result);
109 return; 109 return;
110 } 110 }
111 111
112 queue_.AddJob(std::move(job)); 112 queue_.AddJob(std::move(job));
113 } 113 }
114 114
115 void RemoteCommandsService::OnJobStarted(RemoteCommandJob* command) { 115 void RemoteCommandsService::OnJobStarted(RemoteCommandJob* command) {
116 } 116 }
117 117
118 void RemoteCommandsService::OnJobFinished(RemoteCommandJob* command) { 118 void RemoteCommandsService::OnJobFinished(RemoteCommandJob* command) {
119 has_finished_command_ = true; 119 has_finished_command_ = true;
120 lastest_finished_command_id_ = command->unique_id(); 120 lastest_finished_command_id_ = command->unique_id();
121 // TODO(binjin): Attempt to sync |lastest_finished_command_id_| to some 121 // TODO(binjin): Attempt to sync |lastest_finished_command_id_| to some
122 // persistent source, so that we can reload it later without relying solely on 122 // persistent source, so that we can reload it later without relying solely on
123 // the server to keep our last acknowledged command ID. 123 // the server to keep our last acknowledged command ID.
124 // See http://crbug.com/466572. 124 // See http://crbug.com/466572.
125 125
126 em::RemoteCommandResult result; 126 em::RemoteCommandResult result;
127 result.set_unique_id(command->unique_id()); 127 result.set_command_id(command->unique_id());
128 result.set_timestamp((command->execution_started_time() - 128 result.set_timestamp((command->execution_started_time() -
129 base::TimeTicks::UnixEpoch()).InMilliseconds()); 129 base::TimeTicks::UnixEpoch()).InMilliseconds());
130 130
131 if (command->status() == RemoteCommandJob::SUCCEEDED || 131 if (command->status() == RemoteCommandJob::SUCCEEDED ||
132 command->status() == RemoteCommandJob::FAILED) { 132 command->status() == RemoteCommandJob::FAILED) {
133 if (command->status() == RemoteCommandJob::SUCCEEDED) 133 if (command->status() == RemoteCommandJob::SUCCEEDED)
134 result.set_result(em::RemoteCommandResult_ResultType_RESULT_SUCCESS); 134 result.set_result(em::RemoteCommandResult_ResultType_RESULT_SUCCESS);
135 else 135 else
136 result.set_result(em::RemoteCommandResult_ResultType_RESULT_FAILURE); 136 result.set_result(em::RemoteCommandResult_ResultType_RESULT_FAILURE);
137 const std::unique_ptr<std::string> result_payload = 137 const std::unique_ptr<std::string> result_payload =
(...skipping 29 matching lines...) Expand all
167 EnqueueCommand(command); 167 EnqueueCommand(command);
168 } 168 }
169 169
170 // Start another fetch request job immediately if there are unsent command 170 // Start another fetch request job immediately if there are unsent command
171 // results or enqueued fetch requests. 171 // results or enqueued fetch requests.
172 if (!unsent_results_.empty() || has_enqueued_fetch_request_) 172 if (!unsent_results_.empty() || has_enqueued_fetch_request_)
173 FetchRemoteCommands(); 173 FetchRemoteCommands();
174 } 174 }
175 175
176 } // namespace policy 176 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698