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/component_updater/default_component_installer.h" | 5 #include "components/component_updater/default_component_installer.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 bool DefaultComponentInstaller::Uninstall() { | 147 bool DefaultComponentInstaller::Uninstall() { |
148 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
149 task_runner_->PostTask( | 149 task_runner_->PostTask( |
150 FROM_HERE, | 150 FROM_HERE, |
151 base::Bind(&DefaultComponentInstaller::UninstallOnTaskRunner, this)); | 151 base::Bind(&DefaultComponentInstaller::UninstallOnTaskRunner, this)); |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 bool DefaultComponentInstaller::FindPreinstallation() { | 155 bool DefaultComponentInstaller::FindPreinstallation( |
156 base::FilePath path; | 156 const base::FilePath& root) { |
157 if (!PathService::Get(DIR_COMPONENT_PREINSTALLED, &path)) { | 157 base::FilePath path = root.Append(installer_traits_->GetRelativeInstallDir()); |
158 DVLOG(1) << "DIR_COMPONENT_PREINSTALLED does not exist."; | |
159 return false; | |
160 } | |
161 | |
162 path = path.Append(installer_traits_->GetRelativeInstallDir()); | |
163 if (!base::PathExists(path)) { | 158 if (!base::PathExists(path)) { |
164 DVLOG(1) << "Relative install dir does not exist: " << path.MaybeAsASCII(); | 159 DVLOG(1) << "Relative install dir does not exist: " << path.MaybeAsASCII(); |
165 return false; | 160 return false; |
166 } | 161 } |
167 | 162 |
168 std::unique_ptr<base::DictionaryValue> manifest = | 163 std::unique_ptr<base::DictionaryValue> manifest = |
169 update_client::ReadManifest(path); | 164 update_client::ReadManifest(path); |
170 if (!manifest) { | 165 if (!manifest) { |
171 DVLOG(1) << "Manifest does not exist: " << path.MaybeAsASCII(); | 166 DVLOG(1) << "Manifest does not exist: " << path.MaybeAsASCII(); |
172 return false; | 167 return false; |
(...skipping 27 matching lines...) Expand all Loading... |
200 } | 195 } |
201 | 196 |
202 void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { | 197 void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { |
203 VLOG(1) << __FUNCTION__ << " for " << installer_traits_->GetName(); | 198 VLOG(1) << __FUNCTION__ << " for " << installer_traits_->GetName(); |
204 DCHECK(task_runner_.get()); | 199 DCHECK(task_runner_.get()); |
205 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 200 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
206 | 201 |
207 base::Version latest_version(kNullVersion); | 202 base::Version latest_version(kNullVersion); |
208 | 203 |
209 // First check for an installation set up alongside Chrome itself. | 204 // First check for an installation set up alongside Chrome itself. |
210 if (FindPreinstallation()) | 205 base::FilePath root; |
| 206 if (PathService::Get(DIR_COMPONENT_PREINSTALLED, &root) && |
| 207 FindPreinstallation(root)) { |
211 latest_version = current_version_; | 208 latest_version = current_version_; |
| 209 } |
| 210 |
| 211 // If there is a distinct alternate root, check there as well, and override |
| 212 // anything found in the basic root. |
| 213 base::FilePath root_alternate; |
| 214 if (PathService::Get(DIR_COMPONENT_PREINSTALLED_ALT, &root_alternate) && |
| 215 root != root_alternate && FindPreinstallation(root_alternate)) { |
| 216 latest_version = current_version_; |
| 217 } |
212 | 218 |
213 // Then check for a higher-versioned user-wide installation. | 219 // Then check for a higher-versioned user-wide installation. |
214 base::FilePath latest_path; | 220 base::FilePath latest_path; |
215 std::unique_ptr<base::DictionaryValue> latest_manifest; | 221 std::unique_ptr<base::DictionaryValue> latest_manifest; |
216 base::FilePath base_dir; | 222 base::FilePath base_dir; |
217 if (!PathService::Get(DIR_COMPONENT_USER, &base_dir)) | 223 if (!PathService::Get(DIR_COMPONENT_USER, &base_dir)) |
218 return; | 224 return; |
219 base_dir = base_dir.Append(installer_traits_->GetRelativeInstallDir()); | 225 base_dir = base_dir.Append(installer_traits_->GetRelativeInstallDir()); |
220 if (!base::PathExists(base_dir) && !base::CreateDirectory(base_dir)) { | 226 if (!base::PathExists(base_dir) && !base::CreateDirectory(base_dir)) { |
221 PLOG(ERROR) << "Could not create the base directory for " | 227 PLOG(ERROR) << "Could not create the base directory for " |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 357 |
352 void DefaultComponentInstaller::ComponentReady( | 358 void DefaultComponentInstaller::ComponentReady( |
353 std::unique_ptr<base::DictionaryValue> manifest) { | 359 std::unique_ptr<base::DictionaryValue> manifest) { |
354 VLOG(1) << "Component ready, version " << current_version_.GetString() | 360 VLOG(1) << "Component ready, version " << current_version_.GetString() |
355 << " in " << current_install_dir_.value(); | 361 << " in " << current_install_dir_.value(); |
356 installer_traits_->ComponentReady(current_version_, current_install_dir_, | 362 installer_traits_->ComponentReady(current_version_, current_install_dir_, |
357 std::move(manifest)); | 363 std::move(manifest)); |
358 } | 364 } |
359 | 365 |
360 } // namespace component_updater | 366 } // namespace component_updater |
OLD | NEW |