Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: chrome/browser/component_updater/recovery_component_installer.cc

Issue 1281313003: base: Remove using:: declaration from version.h header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/component_updater/recovery_component_installer.h" 5 #include "chrome/browser/component_updater/recovery_component_installer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 bool SimulatingElevatedRecovery() { 85 bool SimulatingElevatedRecovery() {
86 return base::CommandLine::ForCurrentProcess()->HasSwitch( 86 return base::CommandLine::ForCurrentProcess()->HasSwitch(
87 switches::kSimulateElevatedRecovery); 87 switches::kSimulateElevatedRecovery);
88 } 88 }
89 #endif // !defined(OS_CHROMEOS) 89 #endif // !defined(OS_CHROMEOS)
90 90
91 base::CommandLine GetRecoveryInstallCommandLine( 91 base::CommandLine GetRecoveryInstallCommandLine(
92 const base::FilePath& command, 92 const base::FilePath& command,
93 const base::DictionaryValue& manifest, 93 const base::DictionaryValue& manifest,
94 bool is_deferred_run, 94 bool is_deferred_run,
95 const Version& version) { 95 const base::Version& version) {
96 base::CommandLine command_line(command); 96 base::CommandLine command_line(command);
97 97
98 // Add a flag to for re-attempted install with elevated privilege so that the 98 // Add a flag to for re-attempted install with elevated privilege so that the
99 // recovery executable can report back accordingly. 99 // recovery executable can report back accordingly.
100 if (is_deferred_run) 100 if (is_deferred_run)
101 command_line.AppendArg("/deferredrun"); 101 command_line.AppendArg("/deferredrun");
102 102
103 std::string arguments; 103 std::string arguments;
104 if (manifest.GetStringASCII("x-recovery-args", &arguments)) 104 if (manifest.GetStringASCII("x-recovery-args", &arguments))
105 command_line.AppendArg(arguments); 105 command_line.AppendArg(arguments);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (!base::PathExists(main_file) || !base::PathExists(manifest_file)) 147 if (!base::PathExists(main_file) || !base::PathExists(manifest_file))
148 return; 148 return;
149 149
150 scoped_ptr<base::DictionaryValue> manifest(ReadManifest(manifest_file)); 150 scoped_ptr<base::DictionaryValue> manifest(ReadManifest(manifest_file));
151 std::string name; 151 std::string name;
152 manifest->GetStringASCII("name", &name); 152 manifest->GetStringASCII("name", &name);
153 if (name != kRecoveryManifestName) 153 if (name != kRecoveryManifestName)
154 return; 154 return;
155 std::string proposed_version; 155 std::string proposed_version;
156 manifest->GetStringASCII("version", &proposed_version); 156 manifest->GetStringASCII("version", &proposed_version);
157 const Version version(proposed_version.c_str()); 157 const base::Version version(proposed_version.c_str());
158 if (!version.IsValid()) 158 if (!version.IsValid())
159 return; 159 return;
160 160
161 const bool is_deferred_run = true; 161 const bool is_deferred_run = true;
162 const auto cmdline = GetRecoveryInstallCommandLine( 162 const auto cmdline = GetRecoveryInstallCommandLine(
163 main_file, *manifest, is_deferred_run, version); 163 main_file, *manifest, is_deferred_run, version);
164 164
165 RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED); 165 RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED);
166 166
167 base::LaunchOptions options; 167 base::LaunchOptions options;
(...skipping 20 matching lines...) Expand all
188 // or repair the Google update installation. This is a last resort safety 188 // or repair the Google update installation. This is a last resort safety
189 // mechanism. 189 // mechanism.
190 // For user Chrome, recovery component just installs silently. For machine 190 // For user Chrome, recovery component just installs silently. For machine
191 // Chrome, elevation may be needed. If that happens, the installer will set 191 // Chrome, elevation may be needed. If that happens, the installer will set
192 // preference flag prefs::kRecoveryComponentNeedsElevation to request that. 192 // preference flag prefs::kRecoveryComponentNeedsElevation to request that.
193 // There is a global error service monitors this flag and will pop up 193 // There is a global error service monitors this flag and will pop up
194 // bubble if the flag is set to true. 194 // bubble if the flag is set to true.
195 // See chrome/browser/recovery/recovery_install_global_error.cc for details. 195 // See chrome/browser/recovery/recovery_install_global_error.cc for details.
196 class RecoveryComponentInstaller : public update_client::CrxInstaller { 196 class RecoveryComponentInstaller : public update_client::CrxInstaller {
197 public: 197 public:
198 RecoveryComponentInstaller(const Version& version, PrefService* prefs); 198 RecoveryComponentInstaller(const base::Version& version, PrefService* prefs);
199 199
200 // ComponentInstaller implementation: 200 // ComponentInstaller implementation:
201 void OnUpdateError(int error) override; 201 void OnUpdateError(int error) override;
202 202
203 bool Install(const base::DictionaryValue& manifest, 203 bool Install(const base::DictionaryValue& manifest,
204 const base::FilePath& unpack_path) override; 204 const base::FilePath& unpack_path) override;
205 205
206 bool GetInstalledFile(const std::string& file, 206 bool GetInstalledFile(const std::string& file,
207 base::FilePath* installed_file) override; 207 base::FilePath* installed_file) override;
208 208
209 bool Uninstall() override; 209 bool Uninstall() override;
210 210
211 private: 211 private:
212 ~RecoveryComponentInstaller() override {} 212 ~RecoveryComponentInstaller() override {}
213 213
214 bool RunInstallCommand(const base::CommandLine& cmdline, 214 bool RunInstallCommand(const base::CommandLine& cmdline,
215 const base::FilePath& installer_folder) const; 215 const base::FilePath& installer_folder) const;
216 216
217 Version current_version_; 217 base::Version current_version_;
218 PrefService* prefs_; 218 PrefService* prefs_;
219 }; 219 };
220 220
221 void SimulateElevatedRecoveryHelper(PrefService* prefs) { 221 void SimulateElevatedRecoveryHelper(PrefService* prefs) {
222 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); 222 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true);
223 } 223 }
224 224
225 void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) { 225 void RecoveryRegisterHelper(ComponentUpdateService* cus, PrefService* prefs) {
226 DCHECK_CURRENTLY_ON(BrowserThread::UI); 226 DCHECK_CURRENTLY_ON(BrowserThread::UI);
227 Version version(prefs->GetString(prefs::kRecoveryComponentVersion)); 227 base::Version version(prefs->GetString(prefs::kRecoveryComponentVersion));
228 if (!version.IsValid()) { 228 if (!version.IsValid()) {
229 NOTREACHED(); 229 NOTREACHED();
230 return; 230 return;
231 } 231 }
232 232
233 update_client::CrxComponent recovery; 233 update_client::CrxComponent recovery;
234 recovery.name = "recovery"; 234 recovery.name = "recovery";
235 recovery.installer = new RecoveryComponentInstaller(version, prefs); 235 recovery.installer = new RecoveryComponentInstaller(version, prefs);
236 recovery.version = version; 236 recovery.version = version;
237 recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]); 237 recovery.pk_hash.assign(kSha2Hash, &kSha2Hash[sizeof(kSha2Hash)]);
238 if (!cus->RegisterComponent(recovery)) { 238 if (!cus->RegisterComponent(recovery)) {
239 NOTREACHED() << "Recovery component registration failed."; 239 NOTREACHED() << "Recovery component registration failed.";
240 } 240 }
241 } 241 }
242 242
243 void RecoveryUpdateVersionHelper(const Version& version, PrefService* prefs) { 243 void RecoveryUpdateVersionHelper(const base::Version& version,
244 PrefService* prefs) {
244 DCHECK_CURRENTLY_ON(BrowserThread::UI); 245 DCHECK_CURRENTLY_ON(BrowserThread::UI);
245 prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString()); 246 prefs->SetString(prefs::kRecoveryComponentVersion, version.GetString());
246 } 247 }
247 248
248 void SetPrefsForElevatedRecoveryInstall(const base::FilePath& unpack_path, 249 void SetPrefsForElevatedRecoveryInstall(const base::FilePath& unpack_path,
249 PrefService* prefs) { 250 PrefService* prefs) {
250 DCHECK_CURRENTLY_ON(BrowserThread::UI); 251 DCHECK_CURRENTLY_ON(BrowserThread::UI);
251 prefs->SetFilePath(prefs::kRecoveryComponentUnpackPath, unpack_path); 252 prefs->SetFilePath(prefs::kRecoveryComponentUnpackPath, unpack_path);
252 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true); 253 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, true);
253 } 254 }
254 255
255 RecoveryComponentInstaller::RecoveryComponentInstaller(const Version& version, 256 RecoveryComponentInstaller::RecoveryComponentInstaller(
256 PrefService* prefs) 257 const base::Version& version,
258 PrefService* prefs)
257 : current_version_(version), prefs_(prefs) { 259 : current_version_(version), prefs_(prefs) {
258 DCHECK(version.IsValid()); 260 DCHECK(version.IsValid());
259 } 261 }
260 262
261 void RecoveryComponentInstaller::OnUpdateError(int error) { 263 void RecoveryComponentInstaller::OnUpdateError(int error) {
262 RecordRecoveryComponentUMAEvent(RCE_COMPONENT_DOWNLOAD_ERROR); 264 RecordRecoveryComponentUMAEvent(RCE_COMPONENT_DOWNLOAD_ERROR);
263 NOTREACHED() << "Recovery component update error: " << error; 265 NOTREACHED() << "Recovery component update error: " << error;
264 } 266 }
265 267
266 #if defined(OS_WIN) 268 #if defined(OS_WIN)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 #endif // defined(OS_WIN) 323 #endif // defined(OS_WIN)
322 324
323 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest, 325 bool RecoveryComponentInstaller::Install(const base::DictionaryValue& manifest,
324 const base::FilePath& unpack_path) { 326 const base::FilePath& unpack_path) {
325 std::string name; 327 std::string name;
326 manifest.GetStringASCII("name", &name); 328 manifest.GetStringASCII("name", &name);
327 if (name != kRecoveryManifestName) 329 if (name != kRecoveryManifestName)
328 return false; 330 return false;
329 std::string proposed_version; 331 std::string proposed_version;
330 manifest.GetStringASCII("version", &proposed_version); 332 manifest.GetStringASCII("version", &proposed_version);
331 Version version(proposed_version.c_str()); 333 base::Version version(proposed_version.c_str());
332 if (!version.IsValid()) 334 if (!version.IsValid())
333 return false; 335 return false;
334 if (current_version_.CompareTo(version) >= 0) 336 if (current_version_.CompareTo(version) >= 0)
335 return false; 337 return false;
336 338
337 // Passed the basic tests. Copy the installation to a permanent directory. 339 // Passed the basic tests. Copy the installation to a permanent directory.
338 base::FilePath path; 340 base::FilePath path;
339 if (!PathService::Get(DIR_RECOVERY_BASE, &path)) 341 if (!PathService::Get(DIR_RECOVERY_BASE, &path))
340 return false; 342 return false;
341 if (!base::PathExists(path) && !base::CreateDirectory(path)) 343 if (!base::PathExists(path) && !base::CreateDirectory(path))
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 #endif // OS_WIN 419 #endif // OS_WIN
418 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); 420 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
419 } 421 }
420 422
421 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { 423 void DeclinedElevatedRecoveryInstall(PrefService* prefs) {
422 DCHECK_CURRENTLY_ON(BrowserThread::UI); 424 DCHECK_CURRENTLY_ON(BrowserThread::UI);
423 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); 425 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
424 } 426 }
425 427
426 } // namespace component_updater 428 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698