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

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

Issue 1133613002: Revert of mini_installer: Change to use _countof rather than base's arraysize macro. (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
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 //
11 // In order to be really small the app doesn't link against the CRT and 11 // In order to be really small the app doesn't link against the CRT and
12 // defines the following compiler/linker flags: 12 // defines the following compiler/linker flags:
13 // EnableIntrinsicFunctions="true" compiler: /Oi 13 // EnableIntrinsicFunctions="true" compiler: /Oi
14 // BasicRuntimeChecks="0" 14 // BasicRuntimeChecks="0"
15 // BufferSecurityCheck="false" compiler: /GS- 15 // BufferSecurityCheck="false" compiler: /GS-
16 // EntryPointSymbol="MainEntryPoint" linker: /ENTRY 16 // EntryPointSymbol="MainEntryPoint" linker: /ENTRY
17 // IgnoreAllDefaultLibraries="true" linker: /NODEFAULTLIB 17 // IgnoreAllDefaultLibraries="true" linker: /NODEFAULTLIB
18 // OptimizeForWindows98="1" liker: /OPT:NOWIN98 18 // OptimizeForWindows98="1" liker: /OPT:NOWIN98
19 // linker: /SAFESEH:NO 19 // linker: /SAFESEH:NO
20 20
21 // have the linker merge the sections, saving us ~500 bytes. 21 // have the linker merge the sections, saving us ~500 bytes.
22 #pragma comment(linker, "/MERGE:.rdata=.text") 22 #pragma comment(linker, "/MERGE:.rdata=.text")
23 23
24 #include <windows.h> 24 #include <windows.h>
25 #include <shellapi.h> 25 #include <shellapi.h>
26 #include <stdlib.h>
27 26
28 #include "chrome/installer/mini_installer/appid.h" 27 #include "chrome/installer/mini_installer/appid.h"
29 #include "chrome/installer/mini_installer/configuration.h" 28 #include "chrome/installer/mini_installer/configuration.h"
30 #include "chrome/installer/mini_installer/decompress.h" 29 #include "chrome/installer/mini_installer/decompress.h"
31 #include "chrome/installer/mini_installer/exit_code.h" 30 #include "chrome/installer/mini_installer/exit_code.h"
32 #include "chrome/installer/mini_installer/mini_installer_constants.h" 31 #include "chrome/installer/mini_installer/mini_installer_constants.h"
33 #include "chrome/installer/mini_installer/mini_string.h" 32 #include "chrome/installer/mini_installer/mini_string.h"
34 #include "chrome/installer/mini_installer/pe_resource.h" 33 #include "chrome/installer/mini_installer/pe_resource.h"
35 34
36 namespace mini_installer { 35 namespace mini_installer {
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 if (!work_dir->assign(base_path) || !work_dir->append(kTempPrefix)) 576 if (!work_dir->assign(base_path) || !work_dir->append(kTempPrefix))
578 return false; 577 return false;
579 578
580 // Store the location where we'll append the id. 579 // Store the location where we'll append the id.
581 size_t end = work_dir->length(); 580 size_t end = work_dir->length();
582 581
583 // Check if we'll have enough buffer space to continue. 582 // Check if we'll have enough buffer space to continue.
584 // The name of the directory will use up 11 chars and then we need to append 583 // The name of the directory will use up 11 chars and then we need to append
585 // the trailing backslash and a terminator. We've already added the prefix 584 // the trailing backslash and a terminator. We've already added the prefix
586 // to the buffer, so let's just make sure we've got enough space for the rest. 585 // to the buffer, so let's just make sure we've got enough space for the rest.
587 if ((work_dir->capacity() - end) < (_countof("fffff.tmp") + 1)) 586 if ((work_dir->capacity() - end) < (arraysize("fffff.tmp") + 1))
588 return false; 587 return false;
589 588
590 // Generate a unique id. We only use the lowest 20 bits, so take the top 589 // Generate a unique id. We only use the lowest 20 bits, so take the top
591 // 12 bits and xor them with the lower bits. 590 // 12 bits and xor them with the lower bits.
592 DWORD id = ::GetTickCount(); 591 DWORD id = ::GetTickCount();
593 id ^= (id >> 12); 592 id ^= (id >> 12);
594 593
595 int max_attempts = 10; 594 int max_attempts = 10;
596 while (max_attempts--) { 595 while (max_attempts--) {
597 // This converts 'id' to a string in the format "78563412" on windows 596 // This converts 'id' to a string in the format "78563412" on windows
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 }; 731 };
733 732
734 PathString temp; 733 PathString temp;
735 // GetTempPath always returns a path with a trailing backslash. 734 // GetTempPath always returns a path with a trailing backslash.
736 DWORD len = ::GetTempPath(temp.capacity(), temp.get()); 735 DWORD len = ::GetTempPath(temp.capacity(), temp.get());
737 // GetTempPath returns 0 or number of chars copied, not including the 736 // GetTempPath returns 0 or number of chars copied, not including the
738 // terminating '\0'. 737 // terminating '\0'.
739 if (!len || len >= temp.capacity()) 738 if (!len || len >= temp.capacity())
740 return; 739 return;
741 740
742 for (const wchar_t* directory_prefix : kDirectoryPrefixes) { 741 for (int i = 0; i < arraysize(kDirectoryPrefixes); ++i) {
743 DeleteDirectoriesWithPrefix(temp.get(), directory_prefix); 742 DeleteDirectoriesWithPrefix(temp.get(), kDirectoryPrefixes[i]);
744 } 743 }
745 } 744 }
746 745
747 // Checks the command line for specific mini installer flags. 746 // Checks the command line for specific mini installer flags.
748 // If the function returns true, the command line has been processed and all 747 // If the function returns true, the command line has been processed and all
749 // required actions taken. The installer must exit and return the returned 748 // required actions taken. The installer must exit and return the returned
750 // |exit_code|. 749 // |exit_code|.
751 bool ProcessNonInstallOperations(const Configuration& configuration, 750 bool ProcessNonInstallOperations(const Configuration& configuration,
752 ProcessExitCode* exit_code) { 751 ProcessExitCode* exit_code) {
753 bool ret = false; 752 bool ret = false;
(...skipping 15 matching lines...) Expand all
769 // Returns true if we should delete the temp files we create (default). 768 // Returns true if we should delete the temp files we create (default).
770 // Returns false iff the user has manually created a ChromeInstallerCleanup 769 // Returns false iff the user has manually created a ChromeInstallerCleanup
771 // string value in the registry under HKCU\\Software\\[Google|Chromium] 770 // string value in the registry under HKCU\\Software\\[Google|Chromium]
772 // and set its value to "0". That explicitly forbids the mini installer from 771 // and set its value to "0". That explicitly forbids the mini installer from
773 // deleting these files. 772 // deleting these files.
774 // Support for this has been publicly mentioned in troubleshooting tips so 773 // Support for this has been publicly mentioned in troubleshooting tips so
775 // we continue to support it. 774 // we continue to support it.
776 bool ShouldDeleteExtractedFiles() { 775 bool ShouldDeleteExtractedFiles() {
777 wchar_t value[2] = {0}; 776 wchar_t value[2] = {0};
778 if (ReadValueFromRegistry(HKEY_CURRENT_USER, kCleanupRegistryKey, 777 if (ReadValueFromRegistry(HKEY_CURRENT_USER, kCleanupRegistryKey,
779 kCleanupRegistryValue, value, _countof(value)) && 778 kCleanupRegistryValue, value, arraysize(value)) &&
780 value[0] == L'0') { 779 value[0] == L'0') {
781 return false; 780 return false;
782 } 781 }
783 782
784 return true; 783 return true;
785 } 784 }
786 785
787 // Main function. First gets a working dir, unpacks the resources and finally 786 // Main function. First gets a working dir, unpacks the resources and finally
788 // executes setup.exe to do the install/upgrade. 787 // executes setup.exe to do the install/upgrade.
789 ProcessExitCode WMain(HMODULE module) { 788 ProcessExitCode WMain(HMODULE module) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 #pragma function(memset) 862 #pragma function(memset)
864 void* memset(void* dest, int c, size_t count) { 863 void* memset(void* dest, int c, size_t count) {
865 void* start = dest; 864 void* start = dest;
866 while (count--) { 865 while (count--) {
867 *reinterpret_cast<char*>(dest) = static_cast<char>(c); 866 *reinterpret_cast<char*>(dest) = static_cast<char>(c);
868 dest = reinterpret_cast<char*>(dest) + 1; 867 dest = reinterpret_cast<char*>(dest) + 1;
869 } 868 }
870 return start; 869 return start;
871 } 870 }
872 } // extern "C" 871 } // extern "C"
OLDNEW
« no previous file with comments | « chrome/installer/mini_installer/decompress.cc ('k') | chrome/installer/mini_installer/mini_string.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698