Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/installer/util/beacons.h" | |
| 6 | |
| 7 #include "base/win/registry.h" | |
| 8 #include "base/win/win_util.h" | |
| 9 #include "chrome/installer/util/app_registration_data.h" | |
| 10 #include "chrome/installer/util/browser_distribution.h" | |
| 11 #include "chrome/installer/util/install_util.h" | |
| 12 #include "chrome/installer/util/shell_util.h" | |
| 13 | |
| 14 void UpdateDefaultBrowserBeaconForPath(const base::FilePath& chrome_exe) { | |
| 15 ignore_result(ShellUtil::GetChromeDefaultStateFromPath(chrome_exe)); | |
|
gab
2015/05/26 18:54:34
Not done reading this CL but I assume this means t
grt (UTC plus 2)
2015/05/26 20:54:01
Yes. The doc comment explains that it makes a chec
gab
2015/05/29 13:37:36
How about s/GetChromeDefaultStateFromPath/GetChrom
| |
| 16 } | |
| 17 | |
| 18 void UpdateDefaultBrowserBeacon(const base::FilePath& chrome_exe, | |
| 19 BrowserDistribution* distribution, | |
| 20 ShellUtil::DefaultState default_state) { | |
| 21 const bool system_install = !InstallUtil::IsPerUserInstall(chrome_exe); | |
| 22 const AppRegistrationData& registration_data = | |
| 23 distribution->GetAppRegistrationData(); | |
| 24 switch (default_state) { | |
| 25 case ShellUtil::NOT_DEFAULT: | |
| 26 Beacon::FirstNotDefault(system_install, registration_data)->Update(); | |
| 27 break; | |
| 28 case ShellUtil::IS_DEFAULT: | |
| 29 Beacon::LastWasDefault(system_install, registration_data)->Update(); | |
| 30 Beacon::FirstNotDefault(system_install, registration_data)->Remove(); | |
| 31 break; | |
| 32 case ShellUtil::UNKNOWN_DEFAULT: | |
| 33 break; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 void UpdateOsUpgradeBeacon(bool system_install, | |
| 38 BrowserDistribution* distribution) { | |
| 39 Beacon::LastOsUpgrade(system_install, distribution->GetAppRegistrationData()) | |
| 40 ->Update(); | |
| 41 } | |
| 42 | |
| 43 // Beacon ---------------------------------------------------------------------- | |
| 44 | |
| 45 Beacon::~Beacon() { | |
| 46 } | |
| 47 | |
| 48 // static | |
| 49 scoped_ptr<Beacon> Beacon::LastOsUpgrade( | |
| 50 bool system_install, | |
| 51 const AppRegistrationData& registration_data) { | |
| 52 return make_scoped_ptr(new Beacon(L"LastOsUpgrade", BeaconType::LAST, | |
| 53 BeaconScope::PER_INSTALL, system_install, | |
| 54 registration_data)); | |
| 55 } | |
| 56 | |
| 57 // static | |
| 58 scoped_ptr<Beacon> Beacon::LastWasDefault( | |
| 59 bool system_install, | |
| 60 const AppRegistrationData& registration_data) { | |
| 61 return make_scoped_ptr(new Beacon(L"LastWasDefault", BeaconType::LAST, | |
| 62 BeaconScope::PER_USER, system_install, | |
| 63 registration_data)); | |
| 64 } | |
| 65 | |
| 66 // static | |
| 67 scoped_ptr<Beacon> Beacon::FirstNotDefault( | |
| 68 bool system_install, | |
| 69 const AppRegistrationData& registration_data) { | |
| 70 return make_scoped_ptr(new Beacon(L"FirstNotDefault", BeaconType::FIRST, | |
| 71 BeaconScope::PER_USER, system_install, | |
| 72 registration_data)); | |
| 73 } | |
| 74 | |
| 75 void Beacon::Update() { | |
| 76 const REGSAM kAccess = KEY_WOW64_32KEY | KEY_QUERY_VALUE | KEY_SET_VALUE; | |
|
gab
2015/05/26 18:54:34
Haven't seen much installer code since you and Wil
grt (UTC plus 2)
2015/05/26 20:54:01
Yes. This is where Google Update keeps its state r
| |
| 77 base::win::RegKey key(root_, key_path_.c_str(), kAccess); | |
| 78 | |
| 79 // Nothing to update if the key couldn't be created. This should only be the | |
| 80 // case for a developer build. | |
| 81 if (!key.Valid()) | |
| 82 return; | |
| 83 | |
| 84 // Nothing to do if this beacon is tracking the first occurrence of an event | |
| 85 // that has already been recorded. | |
| 86 if (type_ == BeaconType::FIRST && key.HasValue(value_name_.c_str())) | |
| 87 return; | |
| 88 | |
| 89 FILETIME now(base::Time::Now().ToFileTime()); | |
|
gab
2015/05/26 18:54:34
Do we really need that precise of a timestamp? Fee
grt (UTC plus 2)
2015/05/26 20:54:01
FILETIME is a simple, well-documented platform typ
gab
2015/05/29 13:37:36
My argument against it is you need multiple lines
grt (UTC plus 2)
2015/05/29 15:31:10
Changed to storing using base::Time's internal val
| |
| 90 ULARGE_INTEGER value; | |
| 91 value.u.LowPart = now.dwLowDateTime; | |
| 92 value.u.HighPart = now.dwHighDateTime; | |
| 93 key.WriteValue(value_name_.c_str(), &value.QuadPart, sizeof(value.QuadPart), | |
| 94 REG_QWORD); | |
| 95 } | |
| 96 | |
| 97 void Beacon::Remove() { | |
| 98 const REGSAM kAccess = KEY_WOW64_32KEY | KEY_SET_VALUE; | |
| 99 base::win::RegKey key; | |
| 100 | |
| 101 if (key.Open(root_, key_path_.c_str(), kAccess) == ERROR_SUCCESS) | |
|
gab
2015/05/26 18:54:34
Feels weird to use key.Open() here and the RegKey(
grt (UTC plus 2)
2015/05/26 20:54:01
Done.
| |
| 102 key.DeleteValue(value_name_.c_str()); | |
| 103 } | |
| 104 | |
| 105 base::Time Beacon::Get() { | |
| 106 const REGSAM kAccess = KEY_WOW64_32KEY | KEY_QUERY_VALUE; | |
| 107 base::win::RegKey key; | |
| 108 int64_t value; | |
| 109 | |
| 110 if (key.Open(root_, key_path_.c_str(), kAccess) != ERROR_SUCCESS || | |
| 111 key.ReadInt64(value_name_.c_str(), &value) != ERROR_SUCCESS) { | |
| 112 return base::Time(); | |
| 113 } | |
| 114 | |
| 115 ULARGE_INTEGER intermediate; | |
| 116 intermediate.QuadPart = static_cast<ULONGLONG>(value); | |
| 117 FILETIME beacon_time; | |
| 118 beacon_time.dwLowDateTime = intermediate.u.LowPart; | |
| 119 beacon_time.dwHighDateTime = intermediate.u.HighPart; | |
| 120 return base::Time::FromFileTime(beacon_time); | |
| 121 } | |
| 122 | |
| 123 Beacon::Beacon(base::StringPiece16 name, | |
| 124 BeaconType type, | |
| 125 BeaconScope scope, | |
| 126 bool system_install, | |
| 127 const AppRegistrationData& registration_data) | |
| 128 : type_(type), | |
| 129 root_(system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER), | |
|
gab
2015/05/26 18:54:34
Remind me how ClientStateMedium works again? It's
grt (UTC plus 2)
2015/05/26 20:54:01
Yes.
| |
| 130 scope_(scope) { | |
| 131 Initialize(name, system_install, registration_data); | |
| 132 } | |
| 133 | |
| 134 void Beacon::Initialize(base::StringPiece16 name, | |
| 135 bool system_install, | |
| 136 const AppRegistrationData& registration_data) { | |
| 137 // When possible, beacons are located in the app's ClientState key. Per-user | |
| 138 // beacons for a per-machine install are located in a beacon-specific sub-key | |
| 139 // of the app's ClientStateMedium key. | |
| 140 if (!system_install || scope_ == BeaconScope::PER_INSTALL) { | |
| 141 key_path_ = registration_data.GetStateKey(); | |
| 142 value_name_ = name.as_string(); | |
| 143 } else { | |
| 144 key_path_ = registration_data.GetStateMediumKey(); | |
| 145 key_path_.push_back(L'\\'); | |
| 146 key_path_.append(name.data(), name.size()); | |
| 147 // This should never fail. If it does, the beacon will be written in the | |
| 148 // key's default value, which is okay since the majority case is likely a | |
| 149 // machine with a single user. | |
| 150 if (!base::win::GetUserSidString(&value_name_)) | |
| 151 NOTREACHED(); | |
| 152 } | |
| 153 } | |
| OLD | NEW |