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

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

Issue 15908002: Differential updates for components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/component_updater/component_patcher_win.h"
6
7 #include <string>
8
9 #include "base/base_paths.h"
10 #include "base/command_line.h"
11 #include "base/file_util.h"
12 #include "base/path_service.h"
13 #include "base/process_util.h"
14 #include "base/string_util.h"
15 #include "chrome/installer/util/util_constants.h"
16
17 namespace {
18
19 std::string PatchTypeToCommandLineSwitch(PatchType patch_type) {
20 if (patch_type == PATCH_TYPE_COURGETTE) {
21 return std::string(installer::switches::kCourgette);
22 } else if (patch_type == PATCH_TYPE_BSDIFF) {
23 return std::string(installer::switches::kBsdiff);
24 } else {
25 return std::string();
26 }
27 }
28
29 // Finds the path to the setup.exe. First, it looks for the program in the
30 // "installer" directory. If the program is not found there, it tries to find it
31 // in the directory where chrome.dll. Returns the path to the setup.exe, if the
32 // path exists, otherwise it returns an an empty path.
33 base::FilePath FindSetupProgram() {
34 base::FilePath exe_dir;
35 if (!PathService::Get(base::DIR_MODULE, &exe_dir))
36 return base::FilePath();
37
38 const std::string installer_dir(WideToASCII(installer::kInstallerDir));
39 const std::string setup_exe(WideToASCII(installer::kSetupExe));
40
41 base::FilePath setup_path = exe_dir;
42 setup_path = setup_path.AppendASCII(installer_dir);
43 setup_path = setup_path.AppendASCII(setup_exe);
44 if (file_util::PathExists(setup_path))
45 return setup_path;
46
47 setup_path = exe_dir;
48 setup_path = setup_path.AppendASCII(setup_exe);
49 if (file_util::PathExists(setup_path))
50 return setup_path;
51
52 return base::FilePath();
53 }
54
55 } // namespace
56
57 // Applies the patch to the input file. Returns DELTA_OK if the pacth was
58 // successfully applied, DELTA_OPERATION_FAILURE if the patch operation
59 // encountered errors, and DELTA_PATCH_PROCESS_FAILURE if there was an error
60 // when running the patch code out of process. In the error case, detailed error
61 // information could be returned in the error parameter.
62 DeltaUpdateResult ComponentPatcherWin::Patch(PatchType patch_type,
63 const base::FilePath& input_file,
64 const base::FilePath& patch_file,
65 const base::FilePath& output_file,
66 int* error) {
67 *error = 0;
68
69 const base::FilePath exe_path = FindSetupProgram();
70 if (exe_path.empty()) {
71 return DELTA_PATCH_PROCESS_FAILURE;
72 }
73
74 const std::string patch_type_str(PatchTypeToCommandLineSwitch(patch_type));
75
76 CommandLine cl(CommandLine::NO_PROGRAM);
77 cl.AppendSwitchASCII(installer::switches::kPatch, patch_type_str.c_str());
78 cl.AppendSwitchPath(installer::switches::kInputFile, input_file);
79 cl.AppendSwitchPath(installer::switches::kPatchFile, patch_file);
80 cl.AppendSwitchPath(installer::switches::kOutputFile, output_file);
81
82 base::LaunchOptions launch_options;
83 launch_options.wait = true;
84 launch_options.start_hidden = true;
85 CommandLine setup_path(exe_path);
86 setup_path.AppendArguments(cl, false);
87
88 base::ProcessHandle ph;
89 int exit_code = 0;
90 if (!base::LaunchProcess(setup_path, launch_options, &ph) ||
91 !base::WaitForExitCode(ph, &exit_code)) {
92 return DELTA_PATCH_PROCESS_FAILURE;
93 }
94
95 *error = exit_code;
96 return *error ? DELTA_OPERATION_FAILURE : DELTA_OK;
97 }
98
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698