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

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

Issue 1136943004: add flags to recovery executable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 #if !defined(OS_CHROMEOS) 82 #if !defined(OS_CHROMEOS)
83 // Checks if elevated recovery simulation switch was present on the command 83 // Checks if elevated recovery simulation switch was present on the command
84 // line. This is for testing purpose. 84 // line. This is for testing purpose.
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(
92 const base::FilePath& command,
93 const base::DictionaryValue& manifest,
94 bool is_deferred_run,
95 const Version& version) {
96 base::CommandLine command_line(command);
97
98 // Add a flag to for re-attempted install with elevated privilege so that the
99 // recovery executable can report back accordingly.
100 if (is_deferred_run)
101 command_line.AppendArg("/deferredrun");
102
103 std::string arguments;
104 if (manifest.GetStringASCII("x-recovery-args", &arguments))
105 command_line.AppendArg(arguments);
106 std::string add_version;
107 if (manifest.GetStringASCII("x-recovery-add-version", &add_version) &&
108 add_version == "yes") {
109 std::string version_string = "/version ";
110 version_string += version.GetString();
111 command_line.AppendArg(version_string);
112 }
113
114 return command_line;
115 }
116
91 #if defined(OS_WIN) 117 #if defined(OS_WIN)
92 scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) { 118 scoped_ptr<base::DictionaryValue> ReadManifest(const base::FilePath& manifest) {
93 JSONFileValueDeserializer deserializer(manifest); 119 JSONFileValueDeserializer deserializer(manifest);
94 std::string error; 120 std::string error;
95 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &error)); 121 scoped_ptr<base::Value> root(deserializer.Deserialize(NULL, &error));
96 if (root.get() && root->IsType(base::Value::TYPE_DICTIONARY)) { 122 if (root.get() && root->IsType(base::Value::TYPE_DICTIONARY)) {
97 return scoped_ptr<base::DictionaryValue>( 123 return scoped_ptr<base::DictionaryValue>(
98 static_cast<base::DictionaryValue*>(root.release())); 124 static_cast<base::DictionaryValue*>(root.release()));
99 } 125 }
100 return scoped_ptr<base::DictionaryValue>(); 126 return scoped_ptr<base::DictionaryValue>();
(...skipping 24 matching lines...) Expand all
125 std::string name; 151 std::string name;
126 manifest->GetStringASCII("name", &name); 152 manifest->GetStringASCII("name", &name);
127 if (name != kRecoveryManifestName) 153 if (name != kRecoveryManifestName)
128 return; 154 return;
129 std::string proposed_version; 155 std::string proposed_version;
130 manifest->GetStringASCII("version", &proposed_version); 156 manifest->GetStringASCII("version", &proposed_version);
131 const Version version(proposed_version.c_str()); 157 const Version version(proposed_version.c_str());
132 if (!version.IsValid()) 158 if (!version.IsValid())
133 return; 159 return;
134 160
135 base::CommandLine cmdline(main_file); 161 const bool is_deferred_run = true;
136 std::string arguments; 162 const auto cmdline = GetRecoveryInstallCommandLine(
137 if (manifest->GetStringASCII("x-recovery-args", &arguments)) 163 main_file, *manifest, is_deferred_run, version);
138 cmdline.AppendArg(arguments);
139 std::string add_version;
140 if (manifest->GetStringASCII("x-recovery-add-version", &add_version) &&
141 add_version == "yes") {
142 cmdline.AppendSwitchASCII("version", version.GetString());
143 }
144 164
145 RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED); 165 RecordRecoveryComponentUMAEvent(RCE_RUNNING_ELEVATED);
146 166
147 base::LaunchOptions options; 167 base::LaunchOptions options;
148 options.start_hidden = true; 168 options.start_hidden = true;
149 base::Process process = base::LaunchElevatedProcess(cmdline, options); 169 base::Process process = base::LaunchElevatedProcess(cmdline, options);
150 170
151 base::WorkerPool::PostTask( 171 base::WorkerPool::PostTask(
152 FROM_HERE, 172 FROM_HERE,
153 base::Bind(&WaitForElevatedInstallToComplete, base::Passed(&process)), 173 base::Bind(&WaitForElevatedInstallToComplete, base::Passed(&process)),
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (base::PathExists(path) && !base::DeleteFile(path, true)) 344 if (base::PathExists(path) && !base::DeleteFile(path, true))
325 return false; 345 return false;
326 if (!base::Move(unpack_path, path)) { 346 if (!base::Move(unpack_path, path)) {
327 DVLOG(1) << "Recovery component move failed."; 347 DVLOG(1) << "Recovery component move failed.";
328 return false; 348 return false;
329 } 349 }
330 350
331 base::FilePath main_file = path.Append(kRecoveryFileName); 351 base::FilePath main_file = path.Append(kRecoveryFileName);
332 if (!base::PathExists(main_file)) 352 if (!base::PathExists(main_file))
333 return false; 353 return false;
354
334 // Run the recovery component. 355 // Run the recovery component.
335 base::CommandLine cmdline(main_file); 356 const bool is_deferred_run = false;
336 std::string arguments; 357 const auto cmdline = GetRecoveryInstallCommandLine(
337 if (manifest.GetStringASCII("x-recovery-args", &arguments)) 358 main_file, manifest, is_deferred_run, current_version_);
338 cmdline.AppendArg(arguments);
339 std::string add_version;
340 if (manifest.GetStringASCII("x-recovery-add-version", &add_version) &&
341 add_version == "yes") {
342 cmdline.AppendSwitchASCII("version", current_version_.GetString());
343 }
344 359
345 if (!RunInstallCommand(cmdline, path)) { 360 if (!RunInstallCommand(cmdline, path)) {
346 return false; 361 return false;
347 } 362 }
348 363
349 current_version_ = version; 364 current_version_ = version;
350 if (prefs_) { 365 if (prefs_) {
351 BrowserThread::PostTask( 366 BrowserThread::PostTask(
352 BrowserThread::UI, 367 BrowserThread::UI,
353 FROM_HERE, 368 FROM_HERE,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 #endif // OS_WIN 417 #endif // OS_WIN
403 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); 418 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
404 } 419 }
405 420
406 void DeclinedElevatedRecoveryInstall(PrefService* prefs) { 421 void DeclinedElevatedRecoveryInstall(PrefService* prefs) {
407 DCHECK_CURRENTLY_ON(BrowserThread::UI); 422 DCHECK_CURRENTLY_ON(BrowserThread::UI);
408 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false); 423 prefs->SetBoolean(prefs::kRecoveryComponentNeedsElevation, false);
409 } 424 }
410 425
411 } // namespace component_updater 426 } // namespace component_updater
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698