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

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

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