| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/file_util.h" | 6 #include "base/file_util.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/values.h" | 9 #include "base/values.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| 11 // TODO(ddorwin): Find a better place for ReadManifest. |
| 12 #include "chrome/browser/component_updater/component_unpacker.h" |
| 11 #include "chrome/browser/component_updater/default_component_installer.h" | 13 #include "chrome/browser/component_updater/default_component_installer.h" |
| 12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 13 | 15 |
| 14 namespace { | 16 namespace { |
| 15 // Version "0" corresponds to no installed version. By the server's conventions, | 17 // Version "0" corresponds to no installed version. By the server's conventions, |
| 16 // we represent it as a dotted quad. | 18 // we represent it as a dotted quad. |
| 17 const char kNullVersion[] = "0.0.0.0"; | 19 const char kNullVersion[] = "0.0.0.0"; |
| 18 } // namespace | 20 } // namespace |
| 19 | 21 |
| 22 ComponentInstallerTraits::~ComponentInstallerTraits() { |
| 23 } |
| 24 |
| 20 DefaultComponentInstaller::DefaultComponentInstaller( | 25 DefaultComponentInstaller::DefaultComponentInstaller( |
| 21 scoped_ptr<ComponentInstallerTraits> installer_traits) | 26 scoped_ptr<ComponentInstallerTraits> installer_traits) |
| 22 : current_version_(kNullVersion) { | 27 : current_version_(kNullVersion) { |
| 23 installer_traits_ = installer_traits.Pass(); | 28 installer_traits_ = installer_traits.Pass(); |
| 24 } | 29 } |
| 25 | 30 |
| 26 DefaultComponentInstaller::~DefaultComponentInstaller() { | 31 DefaultComponentInstaller::~DefaultComponentInstaller() { |
| 27 } | 32 } |
| 28 | 33 |
| 29 void DefaultComponentInstaller::Register(ComponentUpdateService* cus) { | 34 void DefaultComponentInstaller::Register(ComponentUpdateService* cus) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 installer_traits_->GetBaseDirectory().AppendASCII(version.GetString()); | 74 installer_traits_->GetBaseDirectory().AppendASCII(version.GetString()); |
| 70 if (base::PathExists(install_path)) { | 75 if (base::PathExists(install_path)) { |
| 71 if (!base::DeleteFile(install_path, true)) | 76 if (!base::DeleteFile(install_path, true)) |
| 72 return false; | 77 return false; |
| 73 } | 78 } |
| 74 if (!InstallHelper(manifest, unpack_path, install_path)) { | 79 if (!InstallHelper(manifest, unpack_path, install_path)) { |
| 75 base::DeleteFile(install_path, true); | 80 base::DeleteFile(install_path, true); |
| 76 return false; | 81 return false; |
| 77 } | 82 } |
| 78 current_version_ = version; | 83 current_version_ = version; |
| 79 installer_traits_->ComponentReady(current_version_, GetInstallDirectory()); | 84 // TODO(ddorwin): Change the parameter to scoped_ptr<base::DictionaryValue> |
| 85 // so we can avoid this DeepCopy. |
| 86 current_manifest_.reset(manifest.DeepCopy()); |
| 87 installer_traits_->ComponentReady( |
| 88 current_version_, |
| 89 GetInstallDirectory(), |
| 90 scoped_ptr<base::DictionaryValue>(current_manifest_->DeepCopy()).Pass()); |
| 80 return true; | 91 return true; |
| 81 } | 92 } |
| 82 | 93 |
| 83 bool DefaultComponentInstaller::GetInstalledFile( | 94 bool DefaultComponentInstaller::GetInstalledFile( |
| 84 const std::string& file, | 95 const std::string& file, |
| 85 base::FilePath* installed_file) { | 96 base::FilePath* installed_file) { |
| 86 if (current_version_.Equals(base::Version(kNullVersion))) | 97 if (current_version_.Equals(base::Version(kNullVersion))) |
| 87 return false; // No component has been installed yet. | 98 return false; // No component has been installed yet. |
| 88 | 99 |
| 89 *installed_file = | 100 *installed_file = |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 137 } |
| 127 } else { | 138 } else { |
| 128 latest_dir = path; | 139 latest_dir = path; |
| 129 latest_version = version; | 140 latest_version = version; |
| 130 found = true; | 141 found = true; |
| 131 } | 142 } |
| 132 } | 143 } |
| 133 | 144 |
| 134 if (found) { | 145 if (found) { |
| 135 current_version_ = latest_version; | 146 current_version_ = latest_version; |
| 147 // TODO(ddorwin): Remove these members and pass them directly to |
| 148 // FinishRegistration(). |
| 136 base::ReadFileToString(latest_dir.AppendASCII("manifest.fingerprint"), | 149 base::ReadFileToString(latest_dir.AppendASCII("manifest.fingerprint"), |
| 137 ¤t_fingerprint_); | 150 ¤t_fingerprint_); |
| 151 current_manifest_= ReadManifest(latest_dir); |
| 152 if (!current_manifest_) { |
| 153 DLOG(ERROR) << "Failed to read manifest for " |
| 154 << installer_traits_->GetName() << " (" |
| 155 << base_dir.MaybeAsASCII() << ")."; |
| 156 return; |
| 157 } |
| 138 } | 158 } |
| 139 | 159 |
| 140 // Remove older versions of the component. None should be in use during | 160 // Remove older versions of the component. None should be in use during |
| 141 // browser startup. | 161 // browser startup. |
| 142 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); | 162 for (std::vector<base::FilePath>::iterator iter = older_dirs.begin(); |
| 143 iter != older_dirs.end(); ++iter) { | 163 iter != older_dirs.end(); ++iter) { |
| 144 base::DeleteFile(*iter, true); | 164 base::DeleteFile(*iter, true); |
| 145 } | 165 } |
| 146 | 166 |
| 147 content::BrowserThread::PostTask( | 167 content::BrowserThread::PostTask( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 167 installer_traits_->GetHash(&crx.pk_hash); | 187 installer_traits_->GetHash(&crx.pk_hash); |
| 168 ComponentUpdateService::Status status = cus->RegisterComponent(crx); | 188 ComponentUpdateService::Status status = cus->RegisterComponent(crx); |
| 169 if (status != ComponentUpdateService::kOk && | 189 if (status != ComponentUpdateService::kOk && |
| 170 status != ComponentUpdateService::kReplaced) { | 190 status != ComponentUpdateService::kReplaced) { |
| 171 NOTREACHED() << "Component registration failed for " | 191 NOTREACHED() << "Component registration failed for " |
| 172 << installer_traits_->GetName(); | 192 << installer_traits_->GetName(); |
| 173 return; | 193 return; |
| 174 } | 194 } |
| 175 | 195 |
| 176 if (current_version_.CompareTo(base::Version(kNullVersion)) > 0) { | 196 if (current_version_.CompareTo(base::Version(kNullVersion)) > 0) { |
| 197 // TODO(ddorwin): Call this function directly the UI thread. The only |
| 198 // implementation posts back to the UI thread. Then post to UI in Install(). |
| 199 scoped_ptr<base::DictionaryValue> manifest_copy( |
| 200 current_manifest_->DeepCopy()); |
| 177 content::BrowserThread::PostTask( | 201 content::BrowserThread::PostTask( |
| 178 content::BrowserThread::FILE, FROM_HERE, | 202 content::BrowserThread::FILE, FROM_HERE, |
| 179 base::Bind(&ComponentInstallerTraits::ComponentReady, | 203 base::Bind(&ComponentInstallerTraits::ComponentReady, |
| 180 base::Unretained(installer_traits_.get()), | 204 base::Unretained(installer_traits_.get()), |
| 181 current_version_, | 205 current_version_, |
| 182 GetInstallDirectory())); | 206 GetInstallDirectory(), |
| 207 base::Passed(&manifest_copy))); |
| 183 } | 208 } |
| 184 } | 209 } |
| OLD | NEW |