OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/update_client/update_client.h" | 5 #include "components/update_client/update_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 189 } |
190 | 190 |
191 bool UpdateClientImpl::GetCrxUpdateState(const std::string& id, | 191 bool UpdateClientImpl::GetCrxUpdateState(const std::string& id, |
192 CrxUpdateItem* update_item) const { | 192 CrxUpdateItem* update_item) const { |
193 return update_engine_->GetUpdateState(id, update_item); | 193 return update_engine_->GetUpdateState(id, update_item); |
194 } | 194 } |
195 | 195 |
196 bool UpdateClientImpl::IsUpdating(const std::string& id) const { | 196 bool UpdateClientImpl::IsUpdating(const std::string& id) const { |
197 DCHECK(thread_checker_.CalledOnValidThread()); | 197 DCHECK(thread_checker_.CalledOnValidThread()); |
198 | 198 |
199 for (const auto& task : tasks_) { | 199 for (const auto* task : tasks_) { |
200 const auto ids(task->GetIds()); | 200 const auto ids(task->GetIds()); |
201 if (std::find(ids.begin(), ids.end(), id) != ids.end()) { | 201 if (std::find(ids.begin(), ids.end(), id) != ids.end()) { |
202 return true; | 202 return true; |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 return false; | 206 return false; |
207 } | 207 } |
208 | 208 |
209 void UpdateClientImpl::Stop() { | 209 void UpdateClientImpl::Stop() { |
210 DCHECK(thread_checker_.CalledOnValidThread()); | 210 DCHECK(thread_checker_.CalledOnValidThread()); |
211 | 211 |
212 is_stopped_ = true; | 212 is_stopped_ = true; |
213 | 213 |
214 // In the current implementation it is sufficient to cancel the pending | 214 // In the current implementation it is sufficient to cancel the pending |
215 // tasks only. The tasks that are run by the update engine will stop | 215 // tasks only. The tasks that are run by the update engine will stop |
216 // making progress naturally, as the main task runner stops running task | 216 // making progress naturally, as the main task runner stops running task |
217 // actions. Upon the browser shutdown, the resources employed by the active | 217 // actions. Upon the browser shutdown, the resources employed by the active |
218 // tasks will leak, as the operating system kills the thread associated with | 218 // tasks will leak, as the operating system kills the thread associated with |
219 // the update engine task runner. Further refactoring may be needed in this | 219 // the update engine task runner. Further refactoring may be needed in this |
220 // area, to cancel the running tasks by canceling the current action update. | 220 // area, to cancel the running tasks by canceling the current action update. |
221 // This behavior would be expected, correct, and result in no resource leaks | 221 // This behavior would be expected, correct, and result in no resource leaks |
222 // in all cases, in shutdown or not. | 222 // in all cases, in shutdown or not. |
223 // | 223 // |
224 // Cancel the pending tasks. These tasks are safe to cancel and delete since | 224 // Cancel the pending tasks. These tasks are safe to cancel and delete since |
225 // they have not picked up by the update engine, and not shared with any | 225 // they have not picked up by the update engine, and not shared with any |
226 // task runner yet. | 226 // task runner yet. |
227 while (!task_queue_.empty()) { | 227 while (!task_queue_.empty()) { |
228 const auto task(task_queue_.front()); | 228 auto* task(task_queue_.front()); |
229 task_queue_.pop(); | 229 task_queue_.pop(); |
230 task->Cancel(); | 230 task->Cancel(); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 void UpdateClientImpl::SendUninstallPing(const std::string& id, | 234 void UpdateClientImpl::SendUninstallPing(const std::string& id, |
235 const Version& version, | 235 const Version& version, |
236 int reason) { | 236 int reason) { |
237 DCHECK(thread_checker_.CalledOnValidThread()); | 237 DCHECK(thread_checker_.CalledOnValidThread()); |
238 | 238 |
(...skipping 14 matching lines...) Expand all Loading... |
253 std::unique_ptr<PingManager> ping_manager(new PingManager(config)); | 253 std::unique_ptr<PingManager> ping_manager(new PingManager(config)); |
254 return new UpdateClientImpl(config, std::move(ping_manager), | 254 return new UpdateClientImpl(config, std::move(ping_manager), |
255 &UpdateChecker::Create, &CrxDownloader::Create); | 255 &UpdateChecker::Create, &CrxDownloader::Create); |
256 } | 256 } |
257 | 257 |
258 void RegisterPrefs(PrefRegistrySimple* registry) { | 258 void RegisterPrefs(PrefRegistrySimple* registry) { |
259 PersistedData::RegisterPrefs(registry); | 259 PersistedData::RegisterPrefs(registry); |
260 } | 260 } |
261 | 261 |
262 } // namespace update_client | 262 } // namespace update_client |
OLD | NEW |