OLD | NEW |
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/setup/setup_main.h" | 5 #include "chrome/installer/setup/setup_main.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <msi.h> | 8 #include <msi.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/at_exit.h" | 14 #include "base/at_exit.h" |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/file_version_info.h" | 17 #include "base/file_version_info.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
20 #include "base/files/scoped_temp_dir.h" | 20 #include "base/files/scoped_temp_dir.h" |
21 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
| 22 #include "base/metrics/histogram_base.h" |
| 23 #include "base/metrics/histogram_persistence.h" |
| 24 #include "base/metrics/persistent_memory_allocator.h" |
22 #include "base/path_service.h" | 25 #include "base/path_service.h" |
23 #include "base/process/launch.h" | 26 #include "base/process/launch.h" |
24 #include "base/process/memory.h" | 27 #include "base/process/memory.h" |
25 #include "base/strings/string16.h" | 28 #include "base/strings/string16.h" |
26 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
27 #include "base/strings/string_util.h" | 30 #include "base/strings/string_util.h" |
28 #include "base/strings/stringprintf.h" | 31 #include "base/strings/stringprintf.h" |
29 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
30 #include "base/values.h" | 33 #include "base/values.h" |
31 #include "base/version.h" | 34 #include "base/version.h" |
(...skipping 1588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 } // namespace installer | 1623 } // namespace installer |
1621 | 1624 |
1622 int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, | 1625 int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, |
1623 wchar_t* command_line, int show_command) { | 1626 wchar_t* command_line, int show_command) { |
1624 // Check to see if the CPU is supported before doing anything else. There's | 1627 // Check to see if the CPU is supported before doing anything else. There's |
1625 // very little than can safely be accomplished if the CPU isn't supported | 1628 // very little than can safely be accomplished if the CPU isn't supported |
1626 // since dependent libraries (e.g., base) may use invalid instructions. | 1629 // since dependent libraries (e.g., base) may use invalid instructions. |
1627 if (!installer::IsProcessorSupported()) | 1630 if (!installer::IsProcessorSupported()) |
1628 return installer::CPU_NOT_SUPPORTED; | 1631 return installer::CPU_NOT_SUPPORTED; |
1629 | 1632 |
| 1633 // Create a persistent space for any histograms that can be reported later |
| 1634 // by the Chrome process. The "id" is a timestamp so that Chrome can tell |
| 1635 // if it has already reported these metrics. No name is given so no internal |
| 1636 // histograms are created or managed; such would be pointless because they |
| 1637 // would have to be created on the heap and thus never be persisted for |
| 1638 // reporting. |
| 1639 uint32_t allocator_id = static_cast<uint32_t>(base::Time::Now().ToTimeT()); |
| 1640 base::SetPersistentHistogramMemoryAllocator( |
| 1641 new base::LocalPersistentMemoryAllocator(1 << 20, // 1 MiB |
| 1642 allocator_id, |
| 1643 std::string())); |
| 1644 |
| 1645 // Now that histograms have a persistent place to be stored, the allocator |
| 1646 // itself can create histograms within that space. |
| 1647 base::GetPersistentHistogramMemoryAllocator() |
| 1648 ->CreateHistograms(google_update::kSetupHistogramAllocatorName); |
| 1649 |
1630 // The exit manager is in charge of calling the dtors of singletons. | 1650 // The exit manager is in charge of calling the dtors of singletons. |
1631 base::AtExitManager exit_manager; | 1651 base::AtExitManager exit_manager; |
1632 base::CommandLine::Init(0, NULL); | 1652 base::CommandLine::Init(0, NULL); |
1633 | 1653 |
1634 // install_util uses chrome paths. | 1654 // install_util uses chrome paths. |
1635 chrome::RegisterPathProvider(); | 1655 chrome::RegisterPathProvider(); |
1636 | 1656 |
1637 const MasterPreferences& prefs = MasterPreferences::ForCurrentProcess(); | 1657 const MasterPreferences& prefs = MasterPreferences::ForCurrentProcess(); |
1638 installer::InitInstallerLogging(prefs); | 1658 installer::InitInstallerLogging(prefs); |
1639 | 1659 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 // MSI demands that custom actions always return 0 (ERROR_SUCCESS) or it will | 1789 // MSI demands that custom actions always return 0 (ERROR_SUCCESS) or it will |
1770 // rollback the action. If we're uninstalling we want to avoid this, so always | 1790 // rollback the action. If we're uninstalling we want to avoid this, so always |
1771 // report success, squashing any more informative return codes. | 1791 // report success, squashing any more informative return codes. |
1772 if (!(installer_state.is_msi() && is_uninstall)) { | 1792 if (!(installer_state.is_msi() && is_uninstall)) { |
1773 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT | 1793 // Note that we allow the status installer::UNINSTALL_REQUIRES_REBOOT |
1774 // to pass through, since this is only returned on uninstall which is | 1794 // to pass through, since this is only returned on uninstall which is |
1775 // never invoked directly by Google Update. | 1795 // never invoked directly by Google Update. |
1776 return_code = InstallUtil::GetInstallReturnCode(install_status); | 1796 return_code = InstallUtil::GetInstallReturnCode(install_status); |
1777 } | 1797 } |
1778 | 1798 |
| 1799 // Save all the persistent histograms to a single file on disk for reading |
| 1800 // by the browser so it can be reported. For atomicity, first write to a |
| 1801 // temporary file and then rename it. The ImportantFileWriter would be good |
| 1802 // for this except it supports only std::string for its data. |
| 1803 base::FilePath file_path = installer_state.target_path().AppendASCII( |
| 1804 google_update::kSetupHistogramAllocatorName); |
| 1805 base::FilePath tmp_file_path; |
| 1806 base::DeleteFile(file_path, false); |
| 1807 if (base::CreateTemporaryFileInDir(file_path.DirName(), &tmp_file_path)) { |
| 1808 base::File histograms(tmp_file_path, |
| 1809 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
| 1810 if (histograms.IsValid()) { |
| 1811 base::PersistentMemoryAllocator* alloc = |
| 1812 base::GetPersistentHistogramMemoryAllocator(); |
| 1813 int used = static_cast<int>(alloc->used()); |
| 1814 if (histograms.Write(0, static_cast<const char*>(alloc->data()), |
| 1815 used) == used && |
| 1816 histograms.Flush()) { |
| 1817 histograms.Close(); |
| 1818 if (base::ReplaceFile(tmp_file_path, file_path, nullptr)) { |
| 1819 VLOG(1) << "Persistent histograms saved in file: " |
| 1820 << file_path.AsUTF8Unsafe(); |
| 1821 } |
| 1822 } |
| 1823 } |
| 1824 } |
| 1825 base::DeleteFile(tmp_file_path, false); |
| 1826 |
1779 VLOG(1) << "Installation complete, returning: " << return_code; | 1827 VLOG(1) << "Installation complete, returning: " << return_code; |
1780 | 1828 |
1781 return return_code; | 1829 return return_code; |
1782 } | 1830 } |
OLD | NEW |