OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/win/chrome_elf_init.h" | 5 #include "chrome/browser/win/chrome_elf_init.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 } // namespace | 89 } // namespace |
90 | 90 |
91 void InitializeChromeElf() { | 91 void InitializeChromeElf() { |
92 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) == | 92 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) == |
93 kBrowserBlacklistTrialDisabledGroupName) { | 93 kBrowserBlacklistTrialDisabledGroupName) { |
94 // Disable the blacklist for all future runs by removing the beacon. | 94 // Disable the blacklist for all future runs by removing the beacon. |
95 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER); | 95 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER); |
96 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath); | 96 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath); |
97 } else { | 97 } else { |
98 AddFinchBlacklistToRegistry(); | |
99 BrowserBlacklistBeaconSetup(); | 98 BrowserBlacklistBeaconSetup(); |
100 } | 99 } |
101 | 100 |
102 // Report all successful blacklist interceptions. | 101 // Report all successful blacklist interceptions. |
103 ReportSuccessfulBlocks(); | 102 ReportSuccessfulBlocks(); |
104 | 103 |
105 // Schedule another task to report all successful interceptions later. | 104 // Schedule another task to report all successful interceptions later. |
106 // This time delay should be long enough to catch any dlls that attempt to | 105 // This time delay should be long enough to catch any dlls that attempt to |
107 // inject after Chrome has started up. | 106 // inject after Chrome has started up. |
108 content::BrowserThread::PostDelayedTask( | 107 content::BrowserThread::PostDelayedTask( |
109 content::BrowserThread::UI, | 108 content::BrowserThread::UI, |
110 FROM_HERE, | 109 FROM_HERE, |
111 base::Bind(&ReportSuccessfulBlocks), | 110 base::Bind(&ReportSuccessfulBlocks), |
112 base::TimeDelta::FromSeconds(kBlacklistReportingDelaySec)); | 111 base::TimeDelta::FromSeconds(kBlacklistReportingDelaySec)); |
113 } | 112 } |
114 | 113 |
115 // Note that running multiple chrome instances with distinct user data | |
116 // directories could lead to deletion (and/or replacement) of the finch | |
117 // blacklist registry data in one instance before the second has a chance to | |
118 // read those values. | |
119 void AddFinchBlacklistToRegistry() { | |
120 base::win::RegKey finch_blacklist_registry_key( | |
121 HKEY_CURRENT_USER, blacklist::kRegistryFinchListPath, KEY_SET_VALUE); | |
122 | |
123 // No point in trying to continue if the registry key isn't valid. | |
124 if (!finch_blacklist_registry_key.Valid()) | |
125 return; | |
126 | |
127 // Delete and recreate the key to clear the registry. | |
128 finch_blacklist_registry_key.DeleteKey(L""); | |
129 finch_blacklist_registry_key.Create( | |
130 HKEY_CURRENT_USER, blacklist::kRegistryFinchListPath, KEY_SET_VALUE); | |
131 | |
132 std::map<std::string, std::string> params; | |
133 std::string value = variations::GetVariationParamValue( | |
134 kBrowserBlacklistTrialName, blacklist::kRegistryFinchListValueNameStr); | |
135 if (value.empty()) | |
136 return; | |
137 base::string16 value_wcs = base::UTF8ToWide(value); | |
138 | |
139 // The dll names are comma-separated in this param value. We need to turn | |
140 // this into REG_MULTI_SZ format (double-null terminates). | |
141 // Note that the strings are wide character in registry. | |
142 value_wcs.push_back(L'\0'); | |
143 value_wcs.push_back(L'\0'); | |
144 std::replace(value_wcs.begin(), value_wcs.end(), L',', L'\0'); | |
145 | |
146 finch_blacklist_registry_key.WriteValue( | |
147 blacklist::kRegistryFinchListValueName, value_wcs.data(), | |
148 (value_wcs.size() * sizeof(wchar_t)), REG_MULTI_SZ); | |
149 } | |
150 | |
151 void BrowserBlacklistBeaconSetup() { | 114 void BrowserBlacklistBeaconSetup() { |
152 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, | 115 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, |
153 blacklist::kRegistryBeaconPath, | 116 blacklist::kRegistryBeaconPath, |
154 KEY_QUERY_VALUE | KEY_SET_VALUE); | 117 KEY_QUERY_VALUE | KEY_SET_VALUE); |
155 | 118 |
156 // No point in trying to continue if the registry key isn't valid. | 119 // No point in trying to continue if the registry key isn't valid. |
157 if (!blacklist_registry_key.Valid()) | 120 if (!blacklist_registry_key.Valid()) |
158 return; | 121 return; |
159 | 122 |
160 // Record the results of the last blacklist setup. | 123 // Record the results of the last blacklist setup. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 169 |
207 blacklist_registry_key.WriteValue(blacklist::kBeaconAttemptCount, | 170 blacklist_registry_key.WriteValue(blacklist::kBeaconAttemptCount, |
208 static_cast<DWORD>(0)); | 171 static_cast<DWORD>(0)); |
209 | 172 |
210 // Only report the blacklist as getting setup when both registry writes | 173 // Only report the blacklist as getting setup when both registry writes |
211 // succeed, since otherwise the blacklist wasn't properly setup. | 174 // succeed, since otherwise the blacklist wasn't properly setup. |
212 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) | 175 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) |
213 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); | 176 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); |
214 } | 177 } |
215 } | 178 } |
OLD | NEW |