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 20 matching lines...) Expand all Loading... | |
31 // Version "0" corresponds to no installed version. By the server's conventions, | 31 // Version "0" corresponds to no installed version. By the server's conventions, |
32 // we represent it as a dotted quad. | 32 // we represent it as a dotted quad. |
33 const char kNullVersion[] = "0.0.0.0"; | 33 const char kNullVersion[] = "0.0.0.0"; |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 ComponentInstallerTraits::~ComponentInstallerTraits() { | 37 ComponentInstallerTraits::~ComponentInstallerTraits() { |
38 } | 38 } |
39 | 39 |
40 DefaultComponentInstaller::DefaultComponentInstaller( | 40 DefaultComponentInstaller::DefaultComponentInstaller( |
41 scoped_ptr<ComponentInstallerTraits> installer_traits) | 41 std::unique_ptr<ComponentInstallerTraits> installer_traits) |
42 : current_version_(kNullVersion), | 42 : current_version_(kNullVersion), |
43 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) { | 43 main_task_runner_(base::ThreadTaskRunnerHandle::Get()) { |
44 installer_traits_ = std::move(installer_traits); | 44 installer_traits_ = std::move(installer_traits); |
45 } | 45 } |
46 | 46 |
47 DefaultComponentInstaller::~DefaultComponentInstaller() { | 47 DefaultComponentInstaller::~DefaultComponentInstaller() { |
48 } | 48 } |
49 | 49 |
50 void DefaultComponentInstaller::Register( | 50 void DefaultComponentInstaller::Register( |
51 ComponentUpdateService* cus, | 51 ComponentUpdateService* cus, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 installer_traits_->GetBaseDirectory().AppendASCII(version.GetString()); | 110 installer_traits_->GetBaseDirectory().AppendASCII(version.GetString()); |
111 if (base::PathExists(install_path)) { | 111 if (base::PathExists(install_path)) { |
112 if (!base::DeleteFile(install_path, true)) | 112 if (!base::DeleteFile(install_path, true)) |
113 return false; | 113 return false; |
114 } | 114 } |
115 if (!InstallHelper(manifest, unpack_path, install_path)) { | 115 if (!InstallHelper(manifest, unpack_path, install_path)) { |
116 base::DeleteFile(install_path, true); | 116 base::DeleteFile(install_path, true); |
117 return false; | 117 return false; |
118 } | 118 } |
119 current_version_ = version; | 119 current_version_ = version; |
120 // TODO(ddorwin): Change the parameter to scoped_ptr<base::DictionaryValue> | 120 // TODO(ddorwin): Change the parameter to |
121 // std::unique_ptr<base::DictionaryValue> | |
121 // so we can avoid this DeepCopy. | 122 // so we can avoid this DeepCopy. |
danakj
2016/04/26 01:27:53
fix comment wrapping
dcheng
2016/04/26 01:35:02
Done.
| |
122 current_manifest_.reset(manifest.DeepCopy()); | 123 current_manifest_.reset(manifest.DeepCopy()); |
123 scoped_ptr<base::DictionaryValue> manifest_copy( | 124 std::unique_ptr<base::DictionaryValue> manifest_copy( |
124 current_manifest_->DeepCopy()); | 125 current_manifest_->DeepCopy()); |
125 main_task_runner_->PostTask( | 126 main_task_runner_->PostTask( |
126 FROM_HERE, | 127 FROM_HERE, |
127 base::Bind(&DefaultComponentInstaller::ComponentReady, | 128 base::Bind(&DefaultComponentInstaller::ComponentReady, |
128 this, base::Passed(&manifest_copy))); | 129 this, base::Passed(&manifest_copy))); |
129 return true; | 130 return true; |
130 } | 131 } |
131 | 132 |
132 bool DefaultComponentInstaller::GetInstalledFile( | 133 bool DefaultComponentInstaller::GetInstalledFile( |
133 const std::string& file, | 134 const std::string& file, |
(...skipping 21 matching lines...) Expand all Loading... | |
155 base::FilePath base_dir = installer_traits_->GetBaseDirectory(); | 156 base::FilePath base_dir = installer_traits_->GetBaseDirectory(); |
156 if (!base::PathExists(base_dir) && !base::CreateDirectory(base_dir)) { | 157 if (!base::PathExists(base_dir) && !base::CreateDirectory(base_dir)) { |
157 PLOG(ERROR) << "Could not create the base directory for " | 158 PLOG(ERROR) << "Could not create the base directory for " |
158 << installer_traits_->GetName() << " (" | 159 << installer_traits_->GetName() << " (" |
159 << base_dir.MaybeAsASCII() << ")."; | 160 << base_dir.MaybeAsASCII() << ")."; |
160 return; | 161 return; |
161 } | 162 } |
162 | 163 |
163 base::FilePath latest_path; | 164 base::FilePath latest_path; |
164 base::Version latest_version(kNullVersion); | 165 base::Version latest_version(kNullVersion); |
165 scoped_ptr<base::DictionaryValue> latest_manifest; | 166 std::unique_ptr<base::DictionaryValue> latest_manifest; |
166 | 167 |
167 std::vector<base::FilePath> older_paths; | 168 std::vector<base::FilePath> older_paths; |
168 base::FileEnumerator file_enumerator( | 169 base::FileEnumerator file_enumerator( |
169 base_dir, false, base::FileEnumerator::DIRECTORIES); | 170 base_dir, false, base::FileEnumerator::DIRECTORIES); |
170 for (base::FilePath path = file_enumerator.Next(); | 171 for (base::FilePath path = file_enumerator.Next(); |
171 !path.value().empty(); | 172 !path.value().empty(); |
172 path = file_enumerator.Next()) { | 173 path = file_enumerator.Next()) { |
173 base::Version version(path.BaseName().MaybeAsASCII()); | 174 base::Version version(path.BaseName().MaybeAsASCII()); |
174 | 175 |
175 // Ignore folders that don't have valid version names. These folders are not | 176 // Ignore folders that don't have valid version names. These folders are not |
176 // managed by component installer so do not try to remove them. | 177 // managed by component installer so do not try to remove them. |
177 if (!version.IsValid()) | 178 if (!version.IsValid()) |
178 continue; | 179 continue; |
179 | 180 |
180 // |version| not newer than the latest found version (kNullVersion if no | 181 // |version| not newer than the latest found version (kNullVersion if no |
181 // version has been found yet) is marked for removal. | 182 // version has been found yet) is marked for removal. |
182 if (version.CompareTo(latest_version) <= 0) { | 183 if (version.CompareTo(latest_version) <= 0) { |
183 older_paths.push_back(path); | 184 older_paths.push_back(path); |
184 continue; | 185 continue; |
185 } | 186 } |
186 | 187 |
187 scoped_ptr<base::DictionaryValue> manifest = | 188 std::unique_ptr<base::DictionaryValue> manifest = |
188 update_client::ReadManifest(path); | 189 update_client::ReadManifest(path); |
189 if (!manifest || !installer_traits_->VerifyInstallation(*manifest, path)) { | 190 if (!manifest || !installer_traits_->VerifyInstallation(*manifest, path)) { |
190 PLOG(ERROR) << "Failed to read manifest or verify installation for " | 191 PLOG(ERROR) << "Failed to read manifest or verify installation for " |
191 << installer_traits_->GetName() << " (" << path.MaybeAsASCII() | 192 << installer_traits_->GetName() << " (" << path.MaybeAsASCII() |
192 << ")."; | 193 << ")."; |
193 older_paths.push_back(path); | 194 older_paths.push_back(path); |
194 continue; | 195 continue; |
195 } | 196 } |
196 | 197 |
197 // New valid |version| folder found! | 198 // New valid |version| folder found! |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 return; | 273 return; |
273 } | 274 } |
274 | 275 |
275 if (!callback.is_null()) | 276 if (!callback.is_null()) |
276 callback.Run(); | 277 callback.Run(); |
277 } | 278 } |
278 | 279 |
279 if (!current_manifest_) | 280 if (!current_manifest_) |
280 return; | 281 return; |
281 | 282 |
282 scoped_ptr<base::DictionaryValue> manifest_copy( | 283 std::unique_ptr<base::DictionaryValue> manifest_copy( |
283 current_manifest_->DeepCopy()); | 284 current_manifest_->DeepCopy()); |
284 ComponentReady(std::move(manifest_copy)); | 285 ComponentReady(std::move(manifest_copy)); |
285 } | 286 } |
286 | 287 |
287 void DefaultComponentInstaller::ComponentReady( | 288 void DefaultComponentInstaller::ComponentReady( |
288 scoped_ptr<base::DictionaryValue> manifest) { | 289 std::unique_ptr<base::DictionaryValue> manifest) { |
289 VLOG(1) << "Component ready, version " << current_version_.GetString() | 290 VLOG(1) << "Component ready, version " << current_version_.GetString() |
290 << " in " << GetInstallDirectory().value(); | 291 << " in " << GetInstallDirectory().value(); |
291 installer_traits_->ComponentReady(current_version_, GetInstallDirectory(), | 292 installer_traits_->ComponentReady(current_version_, GetInstallDirectory(), |
292 std::move(manifest)); | 293 std::move(manifest)); |
293 } | 294 } |
294 | 295 |
295 } // namespace component_updater | 296 } // namespace component_updater |
OLD | NEW |