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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 // Using unretained references is allowed in this case since the life time of | 63 // Using unretained references is allowed in this case since the life time of |
64 // the UpdateClient instance exceeds the life time of its inner members, | 64 // the UpdateClient instance exceeds the life time of its inner members, |
65 // including any thread objects that might execute callbacks bound to it. | 65 // including any thread objects that might execute callbacks bound to it. |
66 UpdateClientImpl::UpdateClientImpl( | 66 UpdateClientImpl::UpdateClientImpl( |
67 const scoped_refptr<Configurator>& config, | 67 const scoped_refptr<Configurator>& config, |
68 scoped_ptr<PingManager> ping_manager, | 68 scoped_ptr<PingManager> ping_manager, |
69 UpdateChecker::Factory update_checker_factory, | 69 UpdateChecker::Factory update_checker_factory, |
70 CrxDownloader::Factory crx_downloader_factory) | 70 CrxDownloader::Factory crx_downloader_factory) |
71 : is_stopped_(false), | 71 : is_stopped_(false), |
72 config_(config), | 72 config_(config), |
73 ping_manager_(ping_manager.Pass()), | 73 ping_manager_(std::move(ping_manager)), |
74 update_engine_( | 74 update_engine_( |
75 new UpdateEngine(config, | 75 new UpdateEngine(config, |
76 update_checker_factory, | 76 update_checker_factory, |
77 crx_downloader_factory, | 77 crx_downloader_factory, |
78 ping_manager_.get(), | 78 ping_manager_.get(), |
79 base::Bind(&UpdateClientImpl::NotifyObservers, | 79 base::Bind(&UpdateClientImpl::NotifyObservers, |
80 base::Unretained(this)))) {} | 80 base::Unretained(this)))) {} |
81 | 81 |
82 UpdateClientImpl::~UpdateClientImpl() { | 82 UpdateClientImpl::~UpdateClientImpl() { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 18 matching lines...) Expand all Loading... |
102 ids.push_back(id); | 102 ids.push_back(id); |
103 | 103 |
104 // Partially applies |completion_callback| to OnTaskComplete, so this | 104 // Partially applies |completion_callback| to OnTaskComplete, so this |
105 // argument is available when the task completes, along with the task itself. | 105 // argument is available when the task completes, along with the task itself. |
106 const auto callback = | 106 const auto callback = |
107 base::Bind(&UpdateClientImpl::OnTaskComplete, this, completion_callback); | 107 base::Bind(&UpdateClientImpl::OnTaskComplete, this, completion_callback); |
108 scoped_ptr<TaskUpdate> task(new TaskUpdate(update_engine_.get(), true, ids, | 108 scoped_ptr<TaskUpdate> task(new TaskUpdate(update_engine_.get(), true, ids, |
109 crx_data_callback, callback)); | 109 crx_data_callback, callback)); |
110 | 110 |
111 // Install tasks are run concurrently and never queued up. | 111 // Install tasks are run concurrently and never queued up. |
112 RunTask(task.Pass()); | 112 RunTask(std::move(task)); |
113 } | 113 } |
114 | 114 |
115 void UpdateClientImpl::Update(const std::vector<std::string>& ids, | 115 void UpdateClientImpl::Update(const std::vector<std::string>& ids, |
116 const CrxDataCallback& crx_data_callback, | 116 const CrxDataCallback& crx_data_callback, |
117 const CompletionCallback& completion_callback) { | 117 const CompletionCallback& completion_callback) { |
118 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
119 | 119 |
120 const auto callback = | 120 const auto callback = |
121 base::Bind(&UpdateClientImpl::OnTaskComplete, this, completion_callback); | 121 base::Bind(&UpdateClientImpl::OnTaskComplete, this, completion_callback); |
122 scoped_ptr<TaskUpdate> task(new TaskUpdate(update_engine_.get(), false, ids, | 122 scoped_ptr<TaskUpdate> task(new TaskUpdate(update_engine_.get(), false, ids, |
123 crx_data_callback, callback)); | 123 crx_data_callback, callback)); |
124 | 124 |
125 // If no other tasks are running at the moment, run this update task. | 125 // If no other tasks are running at the moment, run this update task. |
126 // Otherwise, queue the task up. | 126 // Otherwise, queue the task up. |
127 if (tasks_.empty()) { | 127 if (tasks_.empty()) { |
128 RunTask(task.Pass()); | 128 RunTask(std::move(task)); |
129 } else { | 129 } else { |
130 task_queue_.push(task.release()); | 130 task_queue_.push(task.release()); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 void UpdateClientImpl::RunTask(scoped_ptr<Task> task) { | 134 void UpdateClientImpl::RunTask(scoped_ptr<Task> task) { |
135 DCHECK(thread_checker_.CalledOnValidThread()); | 135 DCHECK(thread_checker_.CalledOnValidThread()); |
136 base::ThreadTaskRunnerHandle::Get()->PostTask( | 136 base::ThreadTaskRunnerHandle::Get()->PostTask( |
137 FROM_HERE, base::Bind(&Task::Run, base::Unretained(task.get()))); | 137 FROM_HERE, base::Bind(&Task::Run, base::Unretained(task.get()))); |
138 tasks_.insert(task.release()); | 138 tasks_.insert(task.release()); |
(...skipping 16 matching lines...) Expand all Loading... |
155 // Delete the completed task. A task can be completed because the update | 155 // Delete the completed task. A task can be completed because the update |
156 // engine has run it or because it has been canceled but never run. | 156 // engine has run it or because it has been canceled but never run. |
157 delete task; | 157 delete task; |
158 | 158 |
159 if (is_stopped_) | 159 if (is_stopped_) |
160 return; | 160 return; |
161 | 161 |
162 // Pick up a task from the queue if the queue has pending tasks and no other | 162 // Pick up a task from the queue if the queue has pending tasks and no other |
163 // task is running. | 163 // task is running. |
164 if (tasks_.empty() && !task_queue_.empty()) { | 164 if (tasks_.empty() && !task_queue_.empty()) { |
165 RunTask(scoped_ptr<Task>(task_queue_.front()).Pass()); | 165 RunTask(scoped_ptr<Task>(task_queue_.front())); |
166 task_queue_.pop(); | 166 task_queue_.pop(); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void UpdateClientImpl::AddObserver(Observer* observer) { | 170 void UpdateClientImpl::AddObserver(Observer* observer) { |
171 DCHECK(thread_checker_.CalledOnValidThread()); | 171 DCHECK(thread_checker_.CalledOnValidThread()); |
172 observer_list_.AddObserver(observer); | 172 observer_list_.AddObserver(observer); |
173 } | 173 } |
174 | 174 |
175 void UpdateClientImpl::RemoveObserver(Observer* observer) { | 175 void UpdateClientImpl::RemoveObserver(Observer* observer) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 while (!task_queue_.empty()) { | 222 while (!task_queue_.empty()) { |
223 const auto task(task_queue_.front()); | 223 const auto task(task_queue_.front()); |
224 task_queue_.pop(); | 224 task_queue_.pop(); |
225 task->Cancel(); | 225 task->Cancel(); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 scoped_refptr<UpdateClient> UpdateClientFactory( | 229 scoped_refptr<UpdateClient> UpdateClientFactory( |
230 const scoped_refptr<Configurator>& config) { | 230 const scoped_refptr<Configurator>& config) { |
231 scoped_ptr<PingManager> ping_manager(new PingManager(*config)); | 231 scoped_ptr<PingManager> ping_manager(new PingManager(*config)); |
232 return new UpdateClientImpl(config, ping_manager.Pass(), | 232 return new UpdateClientImpl(config, std::move(ping_manager), |
233 &UpdateChecker::Create, &CrxDownloader::Create); | 233 &UpdateChecker::Create, &CrxDownloader::Create); |
234 } | 234 } |
235 | 235 |
236 } // namespace update_client | 236 } // namespace update_client |
OLD | NEW |