| 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 #include "components/update_client/task_update.h" | 4 #include "components/update_client/task_update.h" |
| 5 | 5 |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "components/update_client/update_client.h" |
| 11 #include "components/update_client/update_engine.h" | 12 #include "components/update_client/update_engine.h" |
| 12 | 13 |
| 13 namespace update_client { | 14 namespace update_client { |
| 14 | 15 |
| 15 TaskUpdate::TaskUpdate(UpdateEngine* update_engine, | 16 TaskUpdate::TaskUpdate(UpdateEngine* update_engine, |
| 16 bool is_foreground, | 17 bool is_foreground, |
| 17 const std::vector<std::string>& ids, | 18 const std::vector<std::string>& ids, |
| 18 const UpdateClient::CrxDataCallback& crx_data_callback, | 19 const UpdateClient::CrxDataCallback& crx_data_callback, |
| 19 const Callback& callback) | 20 const Callback& callback) |
| 20 : update_engine_(update_engine), | 21 : update_engine_(update_engine), |
| 21 is_foreground_(is_foreground), | 22 is_foreground_(is_foreground), |
| 22 ids_(ids), | 23 ids_(ids), |
| 23 crx_data_callback_(crx_data_callback), | 24 crx_data_callback_(crx_data_callback), |
| 24 callback_(callback) { | 25 callback_(callback) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 TaskUpdate::~TaskUpdate() { | 28 TaskUpdate::~TaskUpdate() { |
| 28 DCHECK(thread_checker_.CalledOnValidThread()); | 29 DCHECK(thread_checker_.CalledOnValidThread()); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void TaskUpdate::Run() { | 32 void TaskUpdate::Run() { |
| 32 DCHECK(thread_checker_.CalledOnValidThread()); | 33 DCHECK(thread_checker_.CalledOnValidThread()); |
| 33 | 34 |
| 34 if (ids_.empty()) { | 35 if (ids_.empty()) { |
| 35 RunComplete(-1); | 36 TaskComplete(Error::ERROR_UPDATE_INVALID_ARGUMENT); |
| 36 return; | 37 return; |
| 37 } | 38 } |
| 38 | 39 |
| 39 update_engine_->Update( | 40 update_engine_->Update( |
| 40 is_foreground_, ids_, crx_data_callback_, | 41 is_foreground_, ids_, crx_data_callback_, |
| 41 base::Bind(&TaskUpdate::RunComplete, base::Unretained(this))); | 42 base::Bind(&TaskUpdate::TaskComplete, base::Unretained(this))); |
| 43 } |
| 44 |
| 45 void TaskUpdate::Cancel() { |
| 46 DCHECK(thread_checker_.CalledOnValidThread()); |
| 47 |
| 48 TaskComplete(Error::ERROR_UPDATE_CANCELED); |
| 42 } | 49 } |
| 43 | 50 |
| 44 std::vector<std::string> TaskUpdate::GetIds() const { | 51 std::vector<std::string> TaskUpdate::GetIds() const { |
| 45 return ids_; | 52 return ids_; |
| 46 } | 53 } |
| 47 | 54 |
| 48 void TaskUpdate::RunComplete(int error) { | 55 void TaskUpdate::TaskComplete(int error) { |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); | 56 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 | 57 |
| 51 callback_.Run(this, error); | 58 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 59 FROM_HERE, base::Bind(callback_, this, error)); |
| 52 } | 60 } |
| 53 | 61 |
| 54 } // namespace update_client | 62 } // namespace update_client |
| OLD | NEW |