Chromium Code Reviews| 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 DLOG(WARNING) << "DIR_COMPONENT_PREINSTALLED does not exist."; |
|
Sorin Jianu
2016/06/02 19:30:10
I've been using VLOG or DVLOG. My opinion is that
xhwang
2016/06/02 20:02:18
Done.
| |
| 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 DLOG(WARNING) << "Relative install dir does not exist: " |
| 168 << path.MaybeAsASCII(); | 165 << path.MaybeAsASCII(); |
| 169 return false; | 166 return false; |
| 170 } | 167 } |
| 171 | 168 |
| 172 std::unique_ptr<base::DictionaryValue> manifest = | 169 std::unique_ptr<base::DictionaryValue> manifest = |
| 173 update_client::ReadManifest(path); | 170 update_client::ReadManifest(path); |
| 174 if (!manifest) { | 171 if (!manifest) { |
| 175 LOG(WARNING) << "Manifest does not exist: " << path.MaybeAsASCII(); | 172 DLOG(WARNING) << "Manifest does not exist: " << path.MaybeAsASCII(); |
| 176 return false; | 173 return false; |
| 177 } | 174 } |
| 178 | 175 |
| 179 if (!installer_traits_->VerifyInstallation(*manifest, path)) { | 176 if (!installer_traits_->VerifyInstallation(*manifest, path)) { |
| 180 LOG(WARNING) << "Installation verification failed: " << path.MaybeAsASCII(); | 177 DLOG(WARNING) << "Installation verification failed: " |
| 178 << path.MaybeAsASCII(); | |
| 181 return false; | 179 return false; |
| 182 } | 180 } |
| 183 | 181 |
| 184 std::string version_lexical; | 182 std::string version_lexical; |
| 185 if (!manifest->GetStringASCII("version", &version_lexical)) { | 183 if (!manifest->GetStringASCII("version", &version_lexical)) { |
| 186 LOG(WARNING) << "Failed to get component version from the manifest."; | 184 DLOG(WARNING) << "Failed to get component version from the manifest."; |
| 187 return false; | 185 return false; |
| 188 } | 186 } |
| 189 | 187 |
| 190 const base::Version version(version_lexical); | 188 const base::Version version(version_lexical); |
| 191 if (!version.IsValid()) { | 189 if (!version.IsValid()) { |
| 192 LOG(WARNING) << "Version in the manifest is invalid:" << version_lexical; | 190 DLOG(WARNING) << "Version in the manifest is invalid:" << version_lexical; |
| 193 return false; | 191 return false; |
| 194 } | 192 } |
| 195 | 193 |
| 196 LOG(WARNING) << "Preinstalled component found for " | 194 VLOG(1) << "Preinstalled component found for " << installer_traits_->GetName() |
| 197 << installer_traits_->GetName() << " at " << path.MaybeAsASCII() | 195 << " at " << path.MaybeAsASCII() << " with version " << version |
| 198 << " with version " << version << "."; | 196 << "."; |
| 199 | 197 |
| 200 current_install_dir_ = path; | 198 current_install_dir_ = path; |
| 201 current_manifest_ = std::move(manifest); | 199 current_manifest_ = std::move(manifest); |
| 202 current_version_ = version; | 200 current_version_ = version; |
| 203 return true; | 201 return true; |
| 204 } | 202 } |
| 205 | 203 |
| 206 void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { | 204 void DefaultComponentInstaller::StartRegistration(ComponentUpdateService* cus) { |
| 207 LOG(WARNING) << __FUNCTION__ << " for " << installer_traits_->GetName(); | 205 VLOG(1) << __FUNCTION__ << " for " << installer_traits_->GetName(); |
| 208 DCHECK(task_runner_.get()); | 206 DCHECK(task_runner_.get()); |
| 209 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 207 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 210 | 208 |
| 211 base::Version latest_version(kNullVersion); | 209 base::Version latest_version(kNullVersion); |
| 212 | 210 |
| 213 // First check for an installation set up alongside Chrome itself. | 211 // First check for an installation set up alongside Chrome itself. |
| 214 if (FindPreinstallation()) | 212 if (FindPreinstallation()) |
| 215 latest_version = current_version_; | 213 latest_version = current_version_; |
| 216 | 214 |
| 217 // Then check for a higher-versioned user-wide installation. | 215 // 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. | 311 // Delete the base directory if it's empty now. |
| 314 if (base::IsDirectoryEmpty(base_dir)) { | 312 if (base::IsDirectoryEmpty(base_dir)) { |
| 315 if (base::DeleteFile(base_dir, false)) | 313 if (base::DeleteFile(base_dir, false)) |
| 316 DLOG(ERROR) << "Couldn't delete " << base_dir.value(); | 314 DLOG(ERROR) << "Couldn't delete " << base_dir.value(); |
| 317 } | 315 } |
| 318 } | 316 } |
| 319 | 317 |
| 320 void DefaultComponentInstaller::FinishRegistration( | 318 void DefaultComponentInstaller::FinishRegistration( |
| 321 ComponentUpdateService* cus, | 319 ComponentUpdateService* cus, |
| 322 const base::Closure& callback) { | 320 const base::Closure& callback) { |
| 323 LOG(WARNING) << __FUNCTION__ << " for " << installer_traits_->GetName(); | 321 VLOG(1) << __FUNCTION__ << " for " << installer_traits_->GetName(); |
| 324 DCHECK(thread_checker_.CalledOnValidThread()); | 322 DCHECK(thread_checker_.CalledOnValidThread()); |
| 325 | 323 |
| 326 if (installer_traits_->CanAutoUpdate()) { | 324 if (installer_traits_->CanAutoUpdate()) { |
| 327 CrxComponent crx; | 325 CrxComponent crx; |
| 328 crx.name = installer_traits_->GetName(); | 326 crx.name = installer_traits_->GetName(); |
| 329 crx.requires_network_encryption = | 327 crx.requires_network_encryption = |
| 330 installer_traits_->RequiresNetworkEncryption(); | 328 installer_traits_->RequiresNetworkEncryption(); |
| 331 crx.installer = this; | 329 crx.installer = this; |
| 332 crx.version = current_version_; | 330 crx.version = current_version_; |
| 333 crx.fingerprint = current_fingerprint_; | 331 crx.fingerprint = current_fingerprint_; |
| 334 installer_traits_->GetHash(&crx.pk_hash); | 332 installer_traits_->GetHash(&crx.pk_hash); |
| 335 if (!cus->RegisterComponent(crx)) { | 333 if (!cus->RegisterComponent(crx)) { |
| 336 LOG(WARNING) << "Component registration failed for " | 334 LOG(ERROR) << "Component registration failed for " |
| 337 << installer_traits_->GetName(); | 335 << installer_traits_->GetName(); |
| 338 return; | 336 return; |
| 339 } | 337 } |
| 340 | 338 |
| 341 if (!callback.is_null()) | 339 if (!callback.is_null()) |
| 342 callback.Run(); | 340 callback.Run(); |
| 343 } | 341 } |
| 344 | 342 |
| 345 if (!current_manifest_) { | 343 if (!current_manifest_) { |
| 346 LOG(WARNING) << "No component found for " << installer_traits_->GetName(); | 344 DLOG(WARNING) << "No component found for " << installer_traits_->GetName(); |
| 347 return; | 345 return; |
| 348 } | 346 } |
| 349 | 347 |
| 350 std::unique_ptr<base::DictionaryValue> manifest_copy( | 348 std::unique_ptr<base::DictionaryValue> manifest_copy( |
| 351 current_manifest_->DeepCopy()); | 349 current_manifest_->DeepCopy()); |
| 352 ComponentReady(std::move(manifest_copy)); | 350 ComponentReady(std::move(manifest_copy)); |
| 353 } | 351 } |
| 354 | 352 |
| 355 void DefaultComponentInstaller::ComponentReady( | 353 void DefaultComponentInstaller::ComponentReady( |
| 356 std::unique_ptr<base::DictionaryValue> manifest) { | 354 std::unique_ptr<base::DictionaryValue> manifest) { |
| 357 VLOG(1) << "Component ready, version " << current_version_.GetString() | 355 VLOG(1) << "Component ready, version " << current_version_.GetString() |
| 358 << " in " << current_install_dir_.value(); | 356 << " in " << current_install_dir_.value(); |
| 359 installer_traits_->ComponentReady(current_version_, current_install_dir_, | 357 installer_traits_->ComponentReady(current_version_, current_install_dir_, |
| 360 std::move(manifest)); | 358 std::move(manifest)); |
| 361 } | 359 } |
| 362 | 360 |
| 363 } // namespace component_updater | 361 } // namespace component_updater |
| OLD | NEW |