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

Side by Side Diff: chrome/installer/mini_installer/configuration.cc

Issue 1247993002: Return Windows error code when create-process fails. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: untabify and rebase 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/installer/mini_installer/configuration.h" 5 #include "chrome/installer/mini_installer/configuration.h"
6 6
7 #include <shellapi.h> // NOLINT 7 #include <shellapi.h> // NOLINT
8 8
9 #include "chrome/installer/mini_installer/appid.h" 9 #include "chrome/installer/mini_installer/appid.h"
10 #include "chrome/installer/mini_installer/mini_installer_constants.h"
10 #include "chrome/installer/mini_installer/mini_installer_resource.h" 11 #include "chrome/installer/mini_installer/mini_installer_resource.h"
12 #include "chrome/installer/mini_installer/regkey.h"
11 13
12 namespace mini_installer { 14 namespace mini_installer {
13 15
14 Configuration::Configuration() : args_(NULL) { 16 Configuration::Configuration() : args_(NULL) {
15 Clear(); 17 Clear();
16 } 18 }
17 19
18 Configuration::~Configuration() { 20 Configuration::~Configuration() {
19 Clear(); 21 Clear();
20 } 22 }
21 23
24 // When multi_install is true, we are potentially:
25 // 1. Performing a multi-install of some product(s) on a clean machine.
26 // Neither the product(s) nor the multi-installer will have a
27 // ClientState key in the registry, so there is no key to be modified.
28 // 2. Upgrading an existing multi-install. The multi-installer will have
29 // a ClientState key in the registry. Only it need be modified.
30 // 3. Migrating a single-install into a multi-install. The product will
31 // have a ClientState key in the registry. Only it need be modified.
32 // To handle all cases, we inspect the product's ClientState to see if it
33 // exists and its "ap" value does not contain "-multi". This is case 3,
34 // so we modify the product's ClientState. Otherwise, we check the
35 // multi-installer's ClientState and modify it if it exists.
36 // TODO(bcwhite): Write a unit test for this that uses registry virtualization.
37 void Configuration::SetChromeAppGuid() {
38 const HKEY root_key =
39 is_system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
40 const wchar_t* app_guid =
41 has_chrome_frame_ ?
42 google_update::kChromeFrameAppGuid :
43 is_side_by_side_ ? google_update::kSxSAppGuid
44 : google_update::kAppGuid;
45
46 // This is the value for single-install and case 3.
47 chrome_app_guid_ = app_guid;
48
49 if (is_multi_install_) {
50 ValueString value;
51 LONG ret = ERROR_SUCCESS;
52 if (ReadClientStateRegistryValue(root_key, app_guid, &ret, value)) {
53 // The product has a client state key. See if it's a single-install.
54 if (ret == ERROR_FILE_NOT_FOUND ||
55 (ret == ERROR_SUCCESS &&
56 !FindTagInStr(value.get(), kMultiInstallTag, NULL))) {
57 // yes -- case 3: use the existing key.
58 return;
59 }
60 }
61 // error, case 1, or case 2: modify the multi-installer's key.
62 chrome_app_guid_ = google_update::kMultiInstallAppGuid;
63 }
64 }
65
66 bool Configuration::ReadClientStateRegistryValue(
67 const HKEY root_key, const wchar_t* app_guid,
68 LONG* retval, ValueString& value) {
69 RegKey key;
70 if (!OpenClientStateKey(root_key, app_guid, KEY_QUERY_VALUE, &key))
71 return false;
72 *retval = key.ReadSZValue(kApRegistryValue, value.get(), value.capacity());
73 return true;
74 }
75
22 const wchar_t* Configuration::program() const { 76 const wchar_t* Configuration::program() const {
23 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0]; 77 return args_ == NULL || argument_count_ < 1 ? NULL : args_[0];
24 } 78 }
25 79
26 void Configuration::Clear() { 80 void Configuration::Clear() {
27 if (args_ != NULL) { 81 if (args_ != NULL) {
28 ::LocalFree(args_); 82 ::LocalFree(args_);
29 args_ = NULL; 83 args_ = NULL;
30 } 84 }
31 chrome_app_guid_ = google_update::kAppGuid; 85 chrome_app_guid_ = google_update::kAppGuid;
32 command_line_ = NULL; 86 command_line_ = NULL;
33 operation_ = INSTALL_PRODUCT; 87 operation_ = INSTALL_PRODUCT;
34 argument_count_ = 0; 88 argument_count_ = 0;
35 has_chrome_ = false; 89 has_chrome_ = false;
36 has_chrome_frame_ = false; 90 has_chrome_frame_ = false;
37 is_multi_install_ = false; 91 is_multi_install_ = false;
38 is_system_level_ = false; 92 is_system_level_ = false;
93 is_side_by_side_ = false;
39 previous_version_ = NULL; 94 previous_version_ = NULL;
40 } 95 }
41 96
42 bool Configuration::Initialize(HMODULE module) { 97 bool Configuration::Initialize(HMODULE module) {
43 Clear(); 98 Clear();
44 ReadResources(module); 99 ReadResources(module);
45 return ParseCommandLine(::GetCommandLine()); 100 return ParseCommandLine(::GetCommandLine());
46 } 101 }
47 102
48 // |command_line| is shared with this instance in the sense that this 103 // |command_line| is shared with this instance in the sense that this
49 // instance may refer to it at will throughout its lifetime, yet it will 104 // instance may refer to it at will throughout its lifetime, yet it will
50 // not release it. 105 // not release it.
51 bool Configuration::ParseCommandLine(const wchar_t* command_line) { 106 bool Configuration::ParseCommandLine(const wchar_t* command_line) {
52 command_line_ = command_line; 107 command_line_ = command_line;
53 args_ = ::CommandLineToArgvW(command_line_, &argument_count_); 108 args_ = ::CommandLineToArgvW(command_line_, &argument_count_);
54 if (args_ != NULL) { 109 if (args_ != NULL) {
55 for (int i = 1; i < argument_count_; ++i) { 110 for (int i = 1; i < argument_count_; ++i) {
56 if (0 == ::lstrcmpi(args_[i], L"--chrome-sxs")) 111 if (0 == ::lstrcmpi(args_[i], L"--chrome-sxs"))
57 chrome_app_guid_ = google_update::kSxSAppGuid; 112 is_side_by_side_ = true;
58 else if (0 == ::lstrcmpi(args_[i], L"--chrome")) 113 else if (0 == ::lstrcmpi(args_[i], L"--chrome"))
59 has_chrome_ = true; 114 has_chrome_ = true;
60 else if (0 == ::lstrcmpi(args_[i], L"--chrome-frame")) 115 else if (0 == ::lstrcmpi(args_[i], L"--chrome-frame"))
61 has_chrome_frame_ = true; 116 has_chrome_frame_ = true;
62 else if (0 == ::lstrcmpi(args_[i], L"--multi-install")) 117 else if (0 == ::lstrcmpi(args_[i], L"--multi-install"))
63 is_multi_install_ = true; 118 is_multi_install_ = true;
64 else if (0 == ::lstrcmpi(args_[i], L"--system-level")) 119 else if (0 == ::lstrcmpi(args_[i], L"--system-level"))
65 is_system_level_ = true; 120 is_system_level_ = true;
66 else if (0 == ::lstrcmpi(args_[i], L"--cleanup")) 121 else if (0 == ::lstrcmpi(args_[i], L"--cleanup"))
67 operation_ = CLEANUP; 122 operation_ = CLEANUP;
68 } 123 }
69 124
70 // Single-install defaults to Chrome. 125 SetChromeAppGuid();
71 if (!is_multi_install_) 126 if (!is_multi_install_) {
72 has_chrome_ = !has_chrome_frame_; 127 has_chrome_ = !has_chrome_frame_;
128 }
73 } 129 }
74 130
75 return args_ != NULL; 131 return args_ != NULL;
76 } 132 }
77 133
78 void Configuration::ReadResources(HMODULE module) { 134 void Configuration::ReadResources(HMODULE module) {
79 HRSRC resource_info_block = 135 HRSRC resource_info_block =
80 FindResource(module, MAKEINTRESOURCE(ID_PREVIOUS_VERSION), RT_RCDATA); 136 FindResource(module, MAKEINTRESOURCE(ID_PREVIOUS_VERSION), RT_RCDATA);
81 if (!resource_info_block) 137 if (!resource_info_block)
82 return; 138 return;
(...skipping 15 matching lines...) Expand all
98 size_t version_len = version_size / sizeof(wchar_t); 154 size_t version_len = version_size / sizeof(wchar_t);
99 155
100 // The string must be terminated. 156 // The string must be terminated.
101 if (version_string[version_len - 1]) 157 if (version_string[version_len - 1])
102 return; 158 return;
103 159
104 previous_version_ = version_string; 160 previous_version_ = version_string;
105 } 161 }
106 162
107 } // namespace mini_installer 163 } // namespace mini_installer
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/configuration.h ('k') | chrome/installer/mini_installer/configuration_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698