| 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 // This file declares util functions for setup project. | 5 // This file declares util functions for setup project. |
| 6 | 6 |
| 7 #include "chrome/installer/setup/setup_util.h" | 7 #include "chrome/installer/setup/setup_util.h" |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <iterator> | 13 #include <iterator> |
| 14 #include <limits> | 14 #include <limits> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 20 #include "base/cpu.h" | 20 #include "base/cpu.h" |
| 21 #include "base/files/file_enumerator.h" | 21 #include "base/files/file_enumerator.h" |
| 22 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
| 23 #include "base/files/file_util.h" | 23 #include "base/files/file_util.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/macros.h" | 25 #include "base/macros.h" |
| 26 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
| 27 #include "base/metrics/histogram.h" | 27 #include "base/metrics/histogram.h" |
| 28 #include "base/numerics/safe_conversions.h" | 28 #include "base/numerics/safe_conversions.h" |
| 29 #include "base/strings/string_number_conversions.h" | |
| 30 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
| 31 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 32 #include "base/time/time.h" | |
| 33 #include "base/version.h" | 31 #include "base/version.h" |
| 34 #include "base/win/registry.h" | 32 #include "base/win/registry.h" |
| 35 #include "base/win/windows_version.h" | 33 #include "base/win/windows_version.h" |
| 36 #include "chrome/installer/setup/installer_state.h" | 34 #include "chrome/installer/setup/installer_state.h" |
| 37 #include "chrome/installer/setup/setup_constants.h" | 35 #include "chrome/installer/setup/setup_constants.h" |
| 38 #include "chrome/installer/setup/user_hive_visitor.h" | 36 #include "chrome/installer/setup/user_hive_visitor.h" |
| 39 #include "chrome/installer/util/app_registration_data.h" | 37 #include "chrome/installer/util/app_registration_data.h" |
| 40 #include "chrome/installer/util/google_update_constants.h" | 38 #include "chrome/installer/util/google_update_constants.h" |
| 39 #include "chrome/installer/util/google_update_settings.h" |
| 41 #include "chrome/installer/util/install_util.h" | 40 #include "chrome/installer/util/install_util.h" |
| 42 #include "chrome/installer/util/installation_state.h" | 41 #include "chrome/installer/util/installation_state.h" |
| 43 #include "chrome/installer/util/master_preferences.h" | 42 #include "chrome/installer/util/master_preferences.h" |
| 44 #include "chrome/installer/util/master_preferences_constants.h" | 43 #include "chrome/installer/util/master_preferences_constants.h" |
| 45 #include "chrome/installer/util/non_updating_app_registration_data.h" | 44 #include "chrome/installer/util/non_updating_app_registration_data.h" |
| 46 #include "chrome/installer/util/updating_app_registration_data.h" | 45 #include "chrome/installer/util/updating_app_registration_data.h" |
| 47 #include "chrome/installer/util/util_constants.h" | 46 #include "chrome/installer/util/util_constants.h" |
| 48 #include "courgette/courgette.h" | 47 #include "courgette/courgette.h" |
| 49 #include "courgette/third_party/bsdiff/bsdiff.h" | 48 #include "courgette/third_party/bsdiff/bsdiff.h" |
| 50 | 49 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 66 return reg_path; | 65 return reg_path; |
| 67 #else | 66 #else |
| 68 return base::string16(L"Chromium"); | 67 return base::string16(L"Chromium"); |
| 69 #endif | 68 #endif |
| 70 } | 69 } |
| 71 | 70 |
| 72 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's | 71 // Returns true if the "lastrun" value in |root|\|key_path| (a path to Chrome's |
| 73 // ClientState key for a user) indicates that Chrome has been used within the | 72 // ClientState key for a user) indicates that Chrome has been used within the |
| 74 // last 28 days. | 73 // last 28 days. |
| 75 bool IsActivelyUsedIn(HKEY root, const wchar_t* key_path) { | 74 bool IsActivelyUsedIn(HKEY root, const wchar_t* key_path) { |
| 76 // This duplicates some logic in GoogleUpdateSettings::GetLastRunTime, which | |
| 77 // is suitable for use from the context of Chrome but not from the installer | |
| 78 // because it was implemented with the assumption that | |
| 79 // BrowserDistribution::GetDistribution() will always be the right thing. | |
| 80 // This is true in Chrome, but not in the installer in a multi-install world. | |
| 81 // Once multi-install goes away, this assumption will once again become true | |
| 82 // for the installer, and this new code here can then be deleted. | |
| 83 VLOG(1) << "IsActivelyUsedIn probing " << root << "\\" << key_path; | 75 VLOG(1) << "IsActivelyUsedIn probing " << root << "\\" << key_path; |
| 84 base::win::RegKey key; | 76 int days_ago_last_run = GoogleUpdateSettings::GetLastRunTime(); |
| 85 LONG result = key.Open(root, key_path, KEY_WOW64_32KEY | KEY_QUERY_VALUE); | 77 if (days_ago_last_run >= 0) { |
| 86 if (result != ERROR_SUCCESS) { | 78 VLOG(1) << "Found a user that last ran Chrome " << days_ago_last_run |
| 87 ::SetLastError(result); | 79 << " days ago."; |
| 88 PLOG_IF(ERROR, result != ERROR_FILE_NOT_FOUND) << "Failed opening " << root | 80 return days_ago_last_run <= 28; |
| 89 << "\\" << key_path; | |
| 90 return false; | |
| 91 } | 81 } |
| 92 base::string16 last_run_time_string; | 82 return false; |
| 93 result = | |
| 94 key.ReadValue(google_update::kRegLastRunTimeField, &last_run_time_string); | |
| 95 if (result != ERROR_SUCCESS) { | |
| 96 ::SetLastError(result); | |
| 97 PLOG_IF(ERROR, result != ERROR_FILE_NOT_FOUND) | |
| 98 << "Failed reading " << root << "\\" << key_path << "@" | |
| 99 << google_update::kRegLastRunTimeField; | |
| 100 return false; | |
| 101 } | |
| 102 int64_t last_run_time_value = 0; | |
| 103 if (!base::StringToInt64(last_run_time_string, &last_run_time_value)) | |
| 104 return false; | |
| 105 base::Time last_run_time = base::Time::FromInternalValue(last_run_time_value); | |
| 106 int days_ago_last_run = | |
| 107 (base::Time::NowFromSystemTime() - last_run_time).InDays(); | |
| 108 VLOG(1) << "Found a user that last ran Chrome " << days_ago_last_run | |
| 109 << " days ago."; | |
| 110 return days_ago_last_run <= 28; | |
| 111 } | 83 } |
| 112 | 84 |
| 113 // A visitor for user hives, run by VisitUserHives. |client_state_path| is the | 85 // A visitor for user hives, run by VisitUserHives. |client_state_path| is the |
| 114 // path to Chrome's ClientState key. |is_used| is set to true if Chrome has been | 86 // path to Chrome's ClientState key. |is_used| is set to true if Chrome has been |
| 115 // used within the last 28 days based on the contents of |user_hive|, in which | 87 // used within the last 28 days based on the contents of |user_hive|, in which |
| 116 // case |false| is returned to halt the hive visits. |user_sid| and |user_hive| | 88 // case |false| is returned to halt the hive visits. |user_sid| and |user_hive| |
| 117 // are provided by VisitUserHives. | 89 // are provided by VisitUserHives. |
| 118 bool OnUserHive(const base::string16& client_state_path, | 90 bool OnUserHive(const base::string16& client_state_path, |
| 119 bool* is_used, | 91 bool* is_used, |
| 120 const wchar_t* user_sid, | 92 const wchar_t* user_sid, |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 } | 824 } |
| 853 | 825 |
| 854 ScopedTokenPrivilege::~ScopedTokenPrivilege() { | 826 ScopedTokenPrivilege::~ScopedTokenPrivilege() { |
| 855 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { | 827 if (is_enabled_ && previous_privileges_.PrivilegeCount != 0) { |
| 856 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, | 828 ::AdjustTokenPrivileges(token_.Get(), FALSE, &previous_privileges_, |
| 857 sizeof(TOKEN_PRIVILEGES), NULL, NULL); | 829 sizeof(TOKEN_PRIVILEGES), NULL, NULL); |
| 858 } | 830 } |
| 859 } | 831 } |
| 860 | 832 |
| 861 } // namespace installer | 833 } // namespace installer |
| OLD | NEW |