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

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

Issue 2670133002: Various cleanups. (Closed)
Patch Set: huangs comments Created 3 years, 10 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 // mini_installer.exe is the first exe that is run when chrome is being 5 // mini_installer.exe is the first exe that is run when chrome is being
6 // installed or upgraded. It is designed to be extremely small (~5KB with no 6 // installed or upgraded. It is designed to be extremely small (~5KB with no
7 // extra resources linked) and it has two main jobs: 7 // extra resources linked) and it has two main jobs:
8 // 1) unpack the resources (possibly decompressing some) 8 // 1) unpack the resources (possibly decompressing some)
9 // 2) run the real installer (setup.exe) with appropriate flags. 9 // 2) run the real installer (setup.exe) with appropriate flags.
10 // 10 //
(...skipping 19 matching lines...) Expand all
30 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx 30 // http://msdn.microsoft.com/en-us/library/windows/desktop/aa387694.aspx
31 #define SystemFunction036 NTAPI SystemFunction036 31 #define SystemFunction036 NTAPI SystemFunction036
32 #include <NTSecAPI.h> 32 #include <NTSecAPI.h>
33 #undef SystemFunction036 33 #undef SystemFunction036
34 34
35 #include <sddl.h> 35 #include <sddl.h>
36 #include <shellapi.h> 36 #include <shellapi.h>
37 #include <stdlib.h> 37 #include <stdlib.h>
38 #include <stddef.h> 38 #include <stddef.h>
39 39
40 #include <initializer_list>
41
40 #include "chrome/installer/mini_installer/appid.h" 42 #include "chrome/installer/mini_installer/appid.h"
41 #include "chrome/installer/mini_installer/configuration.h" 43 #include "chrome/installer/mini_installer/configuration.h"
42 #include "chrome/installer/mini_installer/decompress.h" 44 #include "chrome/installer/mini_installer/decompress.h"
43 #include "chrome/installer/mini_installer/mini_installer_constants.h" 45 #include "chrome/installer/mini_installer/mini_installer_constants.h"
44 #include "chrome/installer/mini_installer/pe_resource.h" 46 #include "chrome/installer/mini_installer/pe_resource.h"
45 #include "chrome/installer/mini_installer/regkey.h" 47 #include "chrome/installer/mini_installer/regkey.h"
46 48
47 namespace mini_installer { 49 namespace mini_installer {
48 50
49 typedef StackString<MAX_PATH> PathString; 51 typedef StackString<MAX_PATH> PathString;
50 52
51 // This structure passes data back and forth for the processing 53 // This structure passes data back and forth for the processing
52 // of resource callbacks. 54 // of resource callbacks.
53 struct Context { 55 struct Context {
54 // Input to the call back method. Specifies the dir to save resources. 56 // Input to the call back method. Specifies the dir to save resources.
55 const wchar_t* base_path; 57 const wchar_t* base_path;
56 // First output from call back method. Full path of Chrome archive. 58 // First output from call back method. Full path of Chrome archive.
57 PathString* chrome_resource_path; 59 PathString* chrome_resource_path;
58 // Second output from call back method. Full path of Setup archive/exe. 60 // Second output from call back method. Full path of Setup archive/exe.
59 PathString* setup_resource_path; 61 PathString* setup_resource_path;
60 }; 62 };
61 63
64 // TODO(grt): Frame this in terms of whether or not the brand supports
65 // integation with Omaha, where Google Update is the Google-specific fork of
66 // the open-source Omaha project.
62 #if defined(GOOGLE_CHROME_BUILD) 67 #if defined(GOOGLE_CHROME_BUILD)
63 // Opens the Google Update ClientState key. If |binaries| is false, opens the 68 // Opens the Google Update ClientState key. If |binaries| is false, opens the
64 // key for Google Chrome or Chrome SxS (canary). If |binaries| is true and an 69 // key for Google Chrome or Chrome SxS (canary). If |binaries| is true and an
65 // existing multi-install Chrome is being updated, opens the key for the 70 // existing multi-install Chrome is being updated, opens the key for the
66 // binaries; otherwise, returns false. 71 // multi-install binaries; otherwise, returns false.
67 bool OpenInstallStateKey(const Configuration& configuration, 72 bool OpenInstallStateKey(const Configuration& configuration,
68 bool binaries, 73 bool binaries,
69 RegKey* key) { 74 RegKey* key) {
70 if (binaries && !configuration.is_updating_multi_chrome()) 75 if (binaries && !configuration.is_updating_multi_chrome())
71 return false; 76 return false;
72 const HKEY root_key = 77 const HKEY root_key =
73 configuration.is_system_level() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 78 configuration.is_system_level() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
74 const wchar_t* app_guid = binaries ? google_update::kMultiInstallAppGuid 79 const wchar_t* app_guid = binaries ? google_update::kMultiInstallAppGuid
75 : configuration.chrome_app_guid(); 80 : configuration.chrome_app_guid();
76 const REGSAM key_access = KEY_QUERY_VALUE | KEY_SET_VALUE; 81 const REGSAM key_access = KEY_QUERY_VALUE | KEY_SET_VALUE;
77 82
78 return OpenClientStateKey(root_key, app_guid, key_access, key) == 83 return OpenClientStateKey(root_key, app_guid, key_access, key) ==
79 ERROR_SUCCESS; 84 ERROR_SUCCESS;
80 } 85 }
81 86
82 // Writes install results into the registry where it is read by Google Update. 87 // Writes install results into the registry where it is read by Google Update.
83 // Don't write anything if there is already a result present, likely 88 // Don't write anything if there is already a result present, likely
84 // written by setup.exe. 89 // written by setup.exe.
85 void WriteInstallResults(const Configuration& configuration, 90 void WriteInstallResults(const Configuration& configuration,
86 ProcessExitResult result) { 91 ProcessExitResult result) {
87 // Calls to setup.exe will write a "success" result if everything was good 92 // Calls to setup.exe will write a "success" result if everything was good
88 // so we don't need to write anything from here. 93 // so we don't need to write anything from here.
89 if (result.IsSuccess()) 94 if (result.IsSuccess())
90 return; 95 return;
91 96
92 // Write the value in Chrome ClientState key and in the binaries' if an 97 // Write the value in Chrome ClientState key and in the binaries' if an
93 // existing multi-install Chrome is being updated. 98 // existing multi-install Chrome is being updated.
94 for (int i = 0; i < 2; ++i) { 99 for (bool binaries : {false, true}) {
95 RegKey key; 100 RegKey key;
96 DWORD value; 101 DWORD value;
97 if (OpenInstallStateKey(configuration, i != 0, &key)) { 102 if (OpenInstallStateKey(configuration, binaries, &key)) {
98 if (key.ReadDWValue(kInstallerResultRegistryValue, &value) != 103 if (key.ReadDWValue(kInstallerResultRegistryValue, &value) !=
99 ERROR_SUCCESS || 104 ERROR_SUCCESS ||
100 value == 0) { 105 value == 0) {
101 key.WriteDWValue(kInstallerResultRegistryValue, 106 key.WriteDWValue(kInstallerResultRegistryValue,
102 result.exit_code ? 1 /* FAILED_CUSTOM_ERROR */ 107 result.exit_code ? 1 /* FAILED_CUSTOM_ERROR */
103 : 0 /* SUCCESS */); 108 : 0 /* SUCCESS */);
104 key.WriteDWValue(kInstallerErrorRegistryValue, result.exit_code); 109 key.WriteDWValue(kInstallerErrorRegistryValue, result.exit_code);
105 key.WriteDWValue(kInstallerExtraCode1RegistryValue, 110 key.WriteDWValue(kInstallerExtraCode1RegistryValue,
106 result.windows_error); 111 result.windows_error);
107 } 112 }
108 } 113 }
109 } 114 }
110 } 115 }
111 116
112 // This function sets the flag in registry to indicate that Google Update 117 // This function sets the flag in registry to indicate that Google Update
113 // should try full installer next time. If the current installer works, this 118 // should try full installer next time. If the current installer works, this
114 // flag is cleared by setup.exe at the end of install. 119 // flag is cleared by setup.exe at the end of install.
115 void SetInstallerFlags(const Configuration& configuration) { 120 void SetInstallerFlags(const Configuration& configuration) {
116 StackString<128> value; 121 StackString<128> value;
117 122
118 for (int i = 0; i < 2; ++i) { 123 for (bool binaries : {false, true}) {
119 RegKey key; 124 RegKey key;
120 if (!OpenInstallStateKey(configuration, i != 0, &key)) 125 if (!OpenInstallStateKey(configuration, binaries, &key))
121 continue; 126 continue;
122 127
123 LONG ret = key.ReadSZValue(kApRegistryValue, value.get(), value.capacity()); 128 LONG ret = key.ReadSZValue(kApRegistryValue, value.get(), value.capacity());
124 129
125 // The conditions below are handling two cases: 130 // The conditions below are handling two cases:
126 // 1. When ap value is present, we want to add the required tag only if it 131 // 1. When ap value is present, we want to add the required tag only if it
127 // is not present. 132 // is not present.
128 // 2. When ap value is missing, we are going to create it with the required 133 // 2. When ap value is missing, we are going to create it with the required
129 // tag. 134 // tag.
130 if ((ret == ERROR_SUCCESS) || (ret == ERROR_FILE_NOT_FOUND)) { 135 if ((ret == ERROR_SUCCESS) || (ret == ERROR_FILE_NOT_FOUND)) {
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get()); 859 DeleteExtractedFiles(base_path.get(), archive_path.get(), setup_path.get());
855 860
856 #if defined(GOOGLE_CHROME_BUILD) 861 #if defined(GOOGLE_CHROME_BUILD)
857 WriteInstallResults(configuration, exit_code); 862 WriteInstallResults(configuration, exit_code);
858 #endif 863 #endif
859 864
860 return exit_code; 865 return exit_code;
861 } 866 }
862 867
863 } // namespace mini_installer 868 } // namespace mini_installer
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/configuration_test.cc ('k') | chrome/installer/mini_installer/mini_installer_constants.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698