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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 task_runner_ = cus->GetSequencedTaskRunner(); | 48 task_runner_ = cus->GetSequencedTaskRunner(); |
49 | 49 |
50 if (!installer_traits_) { | 50 if (!installer_traits_) { |
51 NOTREACHED() << "A DefaultComponentInstaller has been created but " | 51 NOTREACHED() << "A DefaultComponentInstaller has been created but " |
52 << "has no installer traits."; | 52 << "has no installer traits."; |
53 return; | 53 return; |
54 } | 54 } |
55 task_runner_->PostTask( | 55 task_runner_->PostTask( |
56 FROM_HERE, | 56 FROM_HERE, |
57 base::Bind(&DefaultComponentInstaller::StartRegistration, | 57 base::Bind(&DefaultComponentInstaller::StartRegistration, |
58 base::Unretained(this), | 58 this, cus)); |
59 cus)); | |
60 } | 59 } |
61 | 60 |
62 void DefaultComponentInstaller::OnUpdateError(int error) { | 61 void DefaultComponentInstaller::OnUpdateError(int error) { |
63 NOTREACHED() << "Component update error: " << error; | 62 NOTREACHED() << "Component update error: " << error; |
64 } | 63 } |
65 | 64 |
66 bool DefaultComponentInstaller::InstallHelper( | 65 bool DefaultComponentInstaller::InstallHelper( |
67 const base::DictionaryValue& manifest, | 66 const base::DictionaryValue& manifest, |
68 const base::FilePath& unpack_path, | 67 const base::FilePath& unpack_path, |
69 const base::FilePath& install_path) { | 68 const base::FilePath& install_path) { |
(...skipping 26 matching lines...) Expand all Loading... |
96 return false; | 95 return false; |
97 } | 96 } |
98 current_version_ = version; | 97 current_version_ = version; |
99 // TODO(ddorwin): Change the parameter to scoped_ptr<base::DictionaryValue> | 98 // TODO(ddorwin): Change the parameter to scoped_ptr<base::DictionaryValue> |
100 // so we can avoid this DeepCopy. | 99 // so we can avoid this DeepCopy. |
101 current_manifest_.reset(manifest.DeepCopy()); | 100 current_manifest_.reset(manifest.DeepCopy()); |
102 scoped_ptr<base::DictionaryValue> manifest_copy( | 101 scoped_ptr<base::DictionaryValue> manifest_copy( |
103 current_manifest_->DeepCopy()); | 102 current_manifest_->DeepCopy()); |
104 main_task_runner_->PostTask( | 103 main_task_runner_->PostTask( |
105 FROM_HERE, | 104 FROM_HERE, |
106 base::Bind(&ComponentInstallerTraits::ComponentReady, | 105 base::Bind(&DefaultComponentInstaller::ComponentReady, |
107 base::Unretained(installer_traits_.get()), | 106 this, base::Passed(&manifest_copy))); |
108 current_version_, | |
109 GetInstallDirectory(), | |
110 base::Passed(&manifest_copy))); | |
111 return true; | 107 return true; |
112 } | 108 } |
113 | 109 |
114 bool DefaultComponentInstaller::GetInstalledFile( | 110 bool DefaultComponentInstaller::GetInstalledFile( |
115 const std::string& file, | 111 const std::string& file, |
116 base::FilePath* installed_file) { | 112 base::FilePath* installed_file) { |
117 if (current_version_.Equals(base::Version(kNullVersion))) | 113 if (current_version_.Equals(base::Version(kNullVersion))) |
118 return false; // No component has been installed yet. | 114 return false; // No component has been installed yet. |
119 | 115 |
120 *installed_file = installer_traits_->GetBaseDirectory() | 116 *installed_file = installer_traits_->GetBaseDirectory() |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 186 } |
191 | 187 |
192 // Remove older versions of the component. None should be in use during | 188 // Remove older versions of the component. None should be in use during |
193 // browser startup. | 189 // browser startup. |
194 for (const auto& older_path : older_paths) | 190 for (const auto& older_path : older_paths) |
195 base::DeleteFile(older_path, true); | 191 base::DeleteFile(older_path, true); |
196 | 192 |
197 main_task_runner_->PostTask( | 193 main_task_runner_->PostTask( |
198 FROM_HERE, | 194 FROM_HERE, |
199 base::Bind(&DefaultComponentInstaller::FinishRegistration, | 195 base::Bind(&DefaultComponentInstaller::FinishRegistration, |
200 base::Unretained(this), | 196 this, cus)); |
201 cus)); | |
202 } | 197 } |
203 | 198 |
204 base::FilePath DefaultComponentInstaller::GetInstallDirectory() { | 199 base::FilePath DefaultComponentInstaller::GetInstallDirectory() { |
205 return installer_traits_->GetBaseDirectory() | 200 return installer_traits_->GetBaseDirectory() |
206 .AppendASCII(current_version_.GetString()); | 201 .AppendASCII(current_version_.GetString()); |
207 } | 202 } |
208 | 203 |
209 void DefaultComponentInstaller::FinishRegistration( | 204 void DefaultComponentInstaller::FinishRegistration( |
210 ComponentUpdateService* cus) { | 205 ComponentUpdateService* cus) { |
211 DCHECK(thread_checker_.CalledOnValidThread()); | 206 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 11 matching lines...) Expand all Loading... |
223 << installer_traits_->GetName(); | 218 << installer_traits_->GetName(); |
224 return; | 219 return; |
225 } | 220 } |
226 } | 221 } |
227 | 222 |
228 if (!current_manifest_) | 223 if (!current_manifest_) |
229 return; | 224 return; |
230 | 225 |
231 scoped_ptr<base::DictionaryValue> manifest_copy( | 226 scoped_ptr<base::DictionaryValue> manifest_copy( |
232 current_manifest_->DeepCopy()); | 227 current_manifest_->DeepCopy()); |
| 228 ComponentReady(manifest_copy.Pass()); |
| 229 } |
| 230 |
| 231 void DefaultComponentInstaller::ComponentReady( |
| 232 scoped_ptr<base::DictionaryValue> manifest) { |
233 installer_traits_->ComponentReady( | 233 installer_traits_->ComponentReady( |
234 current_version_, GetInstallDirectory(), manifest_copy.Pass()); | 234 current_version_, GetInstallDirectory(), manifest.Pass()); |
235 } | 235 } |
236 | 236 |
237 } // namespace component_updater | 237 } // namespace component_updater |
OLD | NEW |