| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 DefaultComponentInstaller::~DefaultComponentInstaller() { | 49 DefaultComponentInstaller::~DefaultComponentInstaller() { |
| 50 } | 50 } |
| 51 | 51 |
| 52 void DefaultComponentInstaller::Register( | 52 void DefaultComponentInstaller::Register( |
| 53 ComponentUpdateService* cus, | 53 ComponentUpdateService* cus, |
| 54 const base::Closure& callback) { | 54 const base::Closure& callback) { |
| 55 DCHECK(thread_checker_.CalledOnValidThread()); | 55 DCHECK(thread_checker_.CalledOnValidThread()); |
| 56 task_runner_ = cus->GetSequencedTaskRunner(); | 56 task_runner_ = cus->GetSequencedTaskRunner(); |
| 57 | 57 |
| 58 if (!installer_traits_) { | 58 if (!installer_traits_) { |
| 59 NOTREACHED() << "A DefaultComponentInstaller has been created but " | 59 LOG(ERROR) << "A DefaultComponentInstaller has been created but " |
| 60 << "has no installer traits."; | 60 << "has no installer traits."; |
| 61 return; | 61 return; |
| 62 } | 62 } |
| 63 task_runner_->PostTaskAndReply( | 63 task_runner_->PostTaskAndReply( |
| 64 FROM_HERE, | 64 FROM_HERE, |
| 65 base::Bind(&DefaultComponentInstaller::StartRegistration, | 65 base::Bind(&DefaultComponentInstaller::StartRegistration, |
| 66 this, cus), | 66 this, cus), |
| 67 base::Bind(&DefaultComponentInstaller::FinishRegistration, | 67 base::Bind(&DefaultComponentInstaller::FinishRegistration, |
| 68 this, cus, callback)); | 68 this, cus, callback)); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DefaultComponentInstaller::OnUpdateError(int error) { | 71 void DefaultComponentInstaller::OnUpdateError(int error) { |
| 72 NOTREACHED() << "Component update error: " << error; | 72 LOG(ERROR) << "Component update error: " << error; |
| 73 } | 73 } |
| 74 | 74 |
| 75 bool DefaultComponentInstaller::InstallHelper( | 75 bool DefaultComponentInstaller::InstallHelper( |
| 76 const base::DictionaryValue& manifest, | 76 const base::DictionaryValue& manifest, |
| 77 const base::FilePath& unpack_path, | 77 const base::FilePath& unpack_path, |
| 78 const base::FilePath& install_path) { | 78 const base::FilePath& install_path) { |
| 79 VLOG(1) << "InstallHelper: unpack_path=" << unpack_path.AsUTF8Unsafe() | 79 VLOG(1) << "InstallHelper: unpack_path=" << unpack_path.AsUTF8Unsafe() |
| 80 << " install_path=" << install_path.AsUTF8Unsafe(); | 80 << " install_path=" << install_path.AsUTF8Unsafe(); |
| 81 | 81 |
| 82 if (!base::Move(unpack_path, install_path)) { | 82 if (!base::Move(unpack_path, install_path)) { |
| (...skipping 62 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 // TODO(xhwang): The following LOG(WARNING) messages are added to help | |
| 156 // investigate http://crbug.com/614745. Remove redundant checks or convent them | |
| 157 // to VLOG(1) after investigation is completed. | |
| 158 bool DefaultComponentInstaller::FindPreinstallation() { | 155 bool DefaultComponentInstaller::FindPreinstallation() { |
| 159 base::FilePath path; | 156 base::FilePath path; |
| 160 if (!PathService::Get(DIR_COMPONENT_PREINSTALLED, &path)) { | 157 if (!PathService::Get(DIR_COMPONENT_PREINSTALLED, &path)) { |
| 161 LOG(WARNING) << "DIR_COMPONENT_PREINSTALLED does not exist."; | 158 DVLOG(1) << "DIR_COMPONENT_PREINSTALLED does not exist."; |
| 162 return false; | 159 return false; |
| 163 } | 160 } |
| 164 | 161 |
| 165 path = path.Append(installer_traits_->GetRelativeInstallDir()); | 162 path = path.Append(installer_traits_->GetRelativeInstallDir()); |
| 166 if (!base::PathExists(path)) { | 163 if (!base::PathExists(path)) { |
| 167 LOG(WARNING) << "Relative install dir does not exist: " | 164 DVLOG(1) << "Relative install dir does not exist: " << path.MaybeAsASCII(); |
| 168 << path.MaybeAsASCII(); | |
| 169 return false; | 165 return false; |
| 170 } | 166 } |
| 171 | 167 |
| 172 std::unique_ptr<base::DictionaryValue> manifest = | 168 std::unique_ptr<base::DictionaryValue> manifest = |
| 173 update_client::ReadManifest(path); | 169 update_client::ReadManifest(path); |
| 174 if (!manifest) { | 170 if (!manifest) { |
| 175 LOG(WARNING) << "Manifest does not exist: " << path.MaybeAsASCII(); | 171 DVLOG(1) << "Manifest does not exist: " << path.MaybeAsASCII(); |
| 176 return false; | 172 return false; |
| 177 } | 173 } |
| 178 | 174 |
| 179 if (!installer_traits_->VerifyInstallation(*manifest, path)) { | 175 if (!installer_traits_->VerifyInstallation(*manifest, path)) { |
| 180 LOG(WARNING) << "Installation verification failed: " << path.MaybeAsASCII(); | 176 DVLOG(1) << "Installation verification failed: " << path.MaybeAsASCII(); |
| 181 return false; | 177 return false; |
| 182 } | 178 } |
| 183 | 179 |
| 184 std::string version_lexical; | 180 std::string version_lexical; |
| 185 if (!manifest->GetStringASCII("version", &version_lexical)) { | 181 if (!manifest->GetStringASCII("version", &version_lexical)) { |
| 186 LOG(WARNING) << "Failed to get component version from the manifest."; | 182 DVLOG(1) << "Failed to get component version from the manifest."; |
| 187 return false; | 183 return false; |
| 188 } | 184 } |
| 189 | 185 |
| 190 const base::Version version(version_lexical); | 186 const base::Version version(version_lexical); |
| 191 if (!version.IsValid()) { | 187 if (!version.IsValid()) { |
| 192 LOG(WARNING) << "Version in the manifest is invalid:" << version_lexical; | 188 DVLOG(1) << "Version in the manifest is invalid:" << version_lexical; |
| 193 return false; | 189 return false; |
| 194 } | 190 } |
| 195 | 191 |
| 196 LOG(WARNING) << "Preinstalled component found for " | 192 VLOG(1) << "Preinstalled component found for " << installer_traits_->GetName() |
| 197 << installer_traits_->GetName() << " at " << path.MaybeAsASCII() | 193 << " at " << path.MaybeAsASCII() << " with version " << version |
| 198 << " with version " << version << "."; | 194 << "."; |
| 199 | 195 |
| 200 current_install_dir_ = path; | 196 current_install_dir_ = path; |
| 201 current_manifest_ = std::move(manifest); | 197 current_manifest_ = std::move(manifest); |
| 202 current_version_ = version; | 198 current_version_ = version; |
| 203 return true; | 199 return true; |
| 204 } | 200 } |
| 205 | 201 |
| 206 void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { | 202 void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { |
| 207 LOG(WARNING) << __FUNCTION__ << " for " << installer_traits_->GetName(); | 203 VLOG(1) << __FUNCTION__ << " for " << installer_traits_->GetName(); |
| 208 DCHECK(task_runner_.get()); | 204 DCHECK(task_runner_.get()); |
| 209 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 205 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 210 | 206 |
| 211 base::Version latest_version(kNullVersion); | 207 base::Version latest_version(kNullVersion); |
| 212 | 208 |
| 213 // First check for an installation set up alongside Chrome itself. | 209 // First check for an installation set up alongside Chrome itself. |
| 214 if (FindPreinstallation()) | 210 if (FindPreinstallation()) |
| 215 latest_version = current_version_; | 211 latest_version = current_version_; |
| 216 | 212 |
| 217 // Then check for a higher-versioned user-wide installation. | 213 // Then check for a higher-versioned user-wide installation. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // Delete the base directory if it's empty now. | 309 // Delete the base directory if it's empty now. |
| 314 if (base::IsDirectoryEmpty(base_dir)) { | 310 if (base::IsDirectoryEmpty(base_dir)) { |
| 315 if (base::DeleteFile(base_dir, false)) | 311 if (base::DeleteFile(base_dir, false)) |
| 316 DLOG(ERROR) << "Couldn't delete " << base_dir.value(); | 312 DLOG(ERROR) << "Couldn't delete " << base_dir.value(); |
| 317 } | 313 } |
| 318 } | 314 } |
| 319 | 315 |
| 320 void DefaultComponentInstaller::FinishRegistration( | 316 void DefaultComponentInstaller::FinishRegistration( |
| 321 ComponentUpdateService* cus, | 317 ComponentUpdateService* cus, |
| 322 const base::Closure& callback) { | 318 const base::Closure& callback) { |
| 323 LOG(WARNING) << __FUNCTION__ << " for " << installer_traits_->GetName(); | 319 VLOG(1) << __FUNCTION__ << " for " << installer_traits_->GetName(); |
| 324 DCHECK(thread_checker_.CalledOnValidThread()); | 320 DCHECK(thread_checker_.CalledOnValidThread()); |
| 325 | 321 |
| 326 if (installer_traits_->CanAutoUpdate()) { | 322 if (installer_traits_->CanAutoUpdate()) { |
| 327 CrxComponent crx; | 323 CrxComponent crx; |
| 328 crx.name = installer_traits_->GetName(); | 324 crx.name = installer_traits_->GetName(); |
| 329 crx.requires_network_encryption = | 325 crx.requires_network_encryption = |
| 330 installer_traits_->RequiresNetworkEncryption(); | 326 installer_traits_->RequiresNetworkEncryption(); |
| 331 crx.installer = this; | 327 crx.installer = this; |
| 332 crx.version = current_version_; | 328 crx.version = current_version_; |
| 333 crx.fingerprint = current_fingerprint_; | 329 crx.fingerprint = current_fingerprint_; |
| 334 installer_traits_->GetHash(&crx.pk_hash); | 330 installer_traits_->GetHash(&crx.pk_hash); |
| 335 if (!cus->RegisterComponent(crx)) { | 331 if (!cus->RegisterComponent(crx)) { |
| 336 LOG(WARNING) << "Component registration failed for " | 332 LOG(ERROR) << "Component registration failed for " |
| 337 << installer_traits_->GetName(); | 333 << installer_traits_->GetName(); |
| 338 return; | 334 return; |
| 339 } | 335 } |
| 340 | 336 |
| 341 if (!callback.is_null()) | 337 if (!callback.is_null()) |
| 342 callback.Run(); | 338 callback.Run(); |
| 343 } | 339 } |
| 344 | 340 |
| 345 if (!current_manifest_) { | 341 if (!current_manifest_) { |
| 346 LOG(WARNING) << "No component found for " << installer_traits_->GetName(); | 342 DVLOG(1) << "No component found for " << installer_traits_->GetName(); |
| 347 return; | 343 return; |
| 348 } | 344 } |
| 349 | 345 |
| 350 std::unique_ptr<base::DictionaryValue> manifest_copy( | 346 std::unique_ptr<base::DictionaryValue> manifest_copy( |
| 351 current_manifest_->DeepCopy()); | 347 current_manifest_->DeepCopy()); |
| 352 ComponentReady(std::move(manifest_copy)); | 348 ComponentReady(std::move(manifest_copy)); |
| 353 } | 349 } |
| 354 | 350 |
| 355 void DefaultComponentInstaller::ComponentReady( | 351 void DefaultComponentInstaller::ComponentReady( |
| 356 std::unique_ptr<base::DictionaryValue> manifest) { | 352 std::unique_ptr<base::DictionaryValue> manifest) { |
| 357 VLOG(1) << "Component ready, version " << current_version_.GetString() | 353 VLOG(1) << "Component ready, version " << current_version_.GetString() |
| 358 << " in " << current_install_dir_.value(); | 354 << " in " << current_install_dir_.value(); |
| 359 installer_traits_->ComponentReady(current_version_, current_install_dir_, | 355 installer_traits_->ComponentReady(current_version_, current_install_dir_, |
| 360 std::move(manifest)); | 356 std::move(manifest)); |
| 361 } | 357 } |
| 362 | 358 |
| 363 } // namespace component_updater | 359 } // namespace component_updater |
| OLD | NEW |