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

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

Issue 1548203002: Convert Pass()→std::move() in //components/[n-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bad headers Created 4 years, 12 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_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 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/time/tick_clock.h" 13 #include "base/time/tick_clock.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/policy/core/common/cloud/cloud_policy_client.h" 15 #include "components/policy/core/common/cloud/cloud_policy_client.h"
15 #include "components/policy/core/common/remote_commands/remote_commands_factory. h" 16 #include "components/policy/core/common/remote_commands/remote_commands_factory. h"
16 17
17 namespace policy { 18 namespace policy {
18 19
19 namespace em = enterprise_management; 20 namespace em = enterprise_management;
20 21
21 RemoteCommandsService::RemoteCommandsService( 22 RemoteCommandsService::RemoteCommandsService(
22 scoped_ptr<RemoteCommandsFactory> factory, 23 scoped_ptr<RemoteCommandsFactory> factory,
23 CloudPolicyClient* client) 24 CloudPolicyClient* client)
24 : factory_(factory.Pass()), client_(client), weak_factory_(this) { 25 : factory_(std::move(factory)), client_(client), weak_factory_(this) {
25 DCHECK(client_); 26 DCHECK(client_);
26 queue_.AddObserver(this); 27 queue_.AddObserver(this);
27 } 28 }
28 29
29 RemoteCommandsService::~RemoteCommandsService() { 30 RemoteCommandsService::~RemoteCommandsService() {
30 queue_.RemoveObserver(this); 31 queue_.RemoveObserver(this);
31 } 32 }
32 33
33 bool RemoteCommandsService::FetchRemoteCommands() { 34 bool RemoteCommandsService::FetchRemoteCommands() {
34 if (!client_->is_registered()) 35 if (!client_->is_registered())
(...skipping 20 matching lines...) Expand all
55 // It's safe to remove these IDs from |fetched_command_ids_| here, since 56 // It's safe to remove these IDs from |fetched_command_ids_| here, since
56 // it is guaranteed that there is no earlier fetch request in progress 57 // it is guaranteed that there is no earlier fetch request in progress
57 // anymore that could have returned these IDs. 58 // anymore that could have returned these IDs.
58 while (!fetched_command_ids_.empty() && 59 while (!fetched_command_ids_.empty() &&
59 fetched_command_ids_.front() != lastest_finished_command_id_) { 60 fetched_command_ids_.front() != lastest_finished_command_id_) {
60 fetched_command_ids_.pop_front(); 61 fetched_command_ids_.pop_front();
61 } 62 }
62 } 63 }
63 64
64 client_->FetchRemoteCommands( 65 client_->FetchRemoteCommands(
65 id_to_acknowledge.Pass(), previous_results, 66 std::move(id_to_acknowledge), previous_results,
66 base::Bind(&RemoteCommandsService::OnRemoteCommandsFetched, 67 base::Bind(&RemoteCommandsService::OnRemoteCommandsFetched,
67 weak_factory_.GetWeakPtr())); 68 weak_factory_.GetWeakPtr()));
68 69
69 return true; 70 return true;
70 } 71 }
71 72
72 void RemoteCommandsService::SetClockForTesting( 73 void RemoteCommandsService::SetClockForTesting(
73 scoped_ptr<base::TickClock> clock) { 74 scoped_ptr<base::TickClock> clock) {
74 queue_.SetClockForTesting(clock.Pass()); 75 queue_.SetClockForTesting(std::move(clock));
75 } 76 }
76 77
77 void RemoteCommandsService::EnqueueCommand( 78 void RemoteCommandsService::EnqueueCommand(
78 const enterprise_management::RemoteCommand& command) { 79 const enterprise_management::RemoteCommand& command) {
79 if (!command.has_type() || !command.has_unique_id()) { 80 if (!command.has_type() || !command.has_unique_id()) {
80 LOG(WARNING) << "Invalid remote command from server."; 81 LOG(WARNING) << "Invalid remote command from server.";
81 return; 82 return;
82 } 83 }
83 84
84 // If the command is already fetched, ignore it. 85 // If the command is already fetched, ignore it.
85 if (std::find(fetched_command_ids_.begin(), fetched_command_ids_.end(), 86 if (std::find(fetched_command_ids_.begin(), fetched_command_ids_.end(),
86 command.unique_id()) != fetched_command_ids_.end()) { 87 command.unique_id()) != fetched_command_ids_.end()) {
87 return; 88 return;
88 } 89 }
89 90
90 fetched_command_ids_.push_back(command.unique_id()); 91 fetched_command_ids_.push_back(command.unique_id());
91 92
92 scoped_ptr<RemoteCommandJob> job = factory_->BuildJobForType(command.type()); 93 scoped_ptr<RemoteCommandJob> job = factory_->BuildJobForType(command.type());
93 94
94 if (!job || !job->Init(queue_.GetNowTicks(), command)) { 95 if (!job || !job->Init(queue_.GetNowTicks(), command)) {
95 em::RemoteCommandResult ignored_result; 96 em::RemoteCommandResult ignored_result;
96 ignored_result.set_result( 97 ignored_result.set_result(
97 em::RemoteCommandResult_ResultType_RESULT_IGNORED); 98 em::RemoteCommandResult_ResultType_RESULT_IGNORED);
98 ignored_result.set_unique_id(command.unique_id()); 99 ignored_result.set_unique_id(command.unique_id());
99 unsent_results_.push_back(ignored_result); 100 unsent_results_.push_back(ignored_result);
100 return; 101 return;
101 } 102 }
102 103
103 queue_.AddJob(job.Pass()); 104 queue_.AddJob(std::move(job));
104 } 105 }
105 106
106 void RemoteCommandsService::OnJobStarted(RemoteCommandJob* command) { 107 void RemoteCommandsService::OnJobStarted(RemoteCommandJob* command) {
107 } 108 }
108 109
109 void RemoteCommandsService::OnJobFinished(RemoteCommandJob* command) { 110 void RemoteCommandsService::OnJobFinished(RemoteCommandJob* command) {
110 has_finished_command_ = true; 111 has_finished_command_ = true;
111 lastest_finished_command_id_ = command->unique_id(); 112 lastest_finished_command_id_ = command->unique_id();
112 // TODO(binjin): Attempt to sync |lastest_finished_command_id_| to some 113 // TODO(binjin): Attempt to sync |lastest_finished_command_id_| to some
113 // persistent source, so that we can reload it later without relying solely on 114 // persistent source, so that we can reload it later without relying solely on
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 EnqueueCommand(command); 153 EnqueueCommand(command);
153 } 154 }
154 155
155 // Start another fetch request job immediately if there are unsent command 156 // Start another fetch request job immediately if there are unsent command
156 // results or enqueued fetch requests. 157 // results or enqueued fetch requests.
157 if (!unsent_results_.empty() || has_enqueued_fetch_request_) 158 if (!unsent_results_.empty() || has_enqueued_fetch_request_)
158 FetchRemoteCommands(); 159 FetchRemoteCommands();
159 } 160 }
160 161
161 } // namespace policy 162 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698