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