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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/metrics/sparse_histogram.h" | 8 #include "base/metrics/sparse_histogram.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
11 #include "chrome/browser/chrome_elf_init_win.h" | 11 #include "chrome/browser/chrome_elf_init_win.h" |
12 #include "chrome_elf/blacklist/blacklist.h" | 12 #include "chrome_elf/blacklist/blacklist.h" |
13 #include "chrome_elf/chrome_elf_constants.h" | 13 #include "chrome_elf/chrome_elf_constants.h" |
14 #include "chrome_elf/dll_hash/dll_hash.h" | 14 #include "chrome_elf/dll_hash/dll_hash.h" |
15 #include "components/variations/variations_associated_data.h" | |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "version.h" // NOLINT | 17 #include "version.h" // NOLINT |
17 | 18 |
18 const char kBrowserBlacklistTrialName[] = "BrowserBlacklist"; | 19 const char kBrowserBlacklistTrialName[] = "BrowserBlacklist"; |
19 const char kBrowserBlacklistTrialDisabledGroupName[] = "NoBlacklist"; | 20 const char kBrowserBlacklistTrialDisabledGroupName[] = "NoBlacklist"; |
21 const char kBrowserBlacklistTrialEnabledGroupName[] = "Enabled"; | |
csharp
2014/05/29 20:51:52
Seems to be unused, remove?
krstnmnlsn
2014/05/30 14:09:13
Done.
| |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // How long to wait, in seconds, before reporting for the second (and last | 25 // How long to wait, in seconds, before reporting for the second (and last |
24 // time), what dlls were blocked from the browser process. | 26 // time), what dlls were blocked from the browser process. |
25 const int kBlacklistReportingDelaySec = 600; | 27 const int kBlacklistReportingDelaySec = 600; |
26 | 28 |
27 // This enum is used to define the buckets for an enumerated UMA histogram. | 29 // This enum is used to define the buckets for an enumerated UMA histogram. |
28 // Hence, | 30 // Hence, |
29 // (a) existing enumerated constants should never be deleted or reordered, and | 31 // (a) existing enumerated constants should never be deleted or reordered, and |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 | 82 |
81 } // namespace | 83 } // namespace |
82 | 84 |
83 void InitializeChromeElf() { | 85 void InitializeChromeElf() { |
84 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) == | 86 if (base::FieldTrialList::FindFullName(kBrowserBlacklistTrialName) == |
85 kBrowserBlacklistTrialDisabledGroupName) { | 87 kBrowserBlacklistTrialDisabledGroupName) { |
86 // Disable the blacklist for all future runs by removing the beacon. | 88 // Disable the blacklist for all future runs by removing the beacon. |
87 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER); | 89 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER); |
88 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath); | 90 blacklist_registry_key.DeleteKey(blacklist::kRegistryBeaconPath); |
89 } else { | 91 } else { |
92 AddFinchBlacklistToRegistry(); | |
90 BrowserBlacklistBeaconSetup(); | 93 BrowserBlacklistBeaconSetup(); |
91 } | 94 } |
92 | 95 |
93 // Report all successful blacklist interceptions. | 96 // Report all successful blacklist interceptions. |
94 ReportSuccessfulBlocks(); | 97 ReportSuccessfulBlocks(); |
95 | 98 |
96 // Schedule another task to report all sucessful interceptions later. | 99 // Schedule another task to report all sucessful interceptions later. |
97 // This time delay should be long enough to catch any dlls that attempt to | 100 // This time delay should be long enough to catch any dlls that attempt to |
98 // inject after Chrome has started up. | 101 // inject after Chrome has started up. |
99 content::BrowserThread::PostDelayedTask( | 102 content::BrowserThread::PostDelayedTask( |
100 content::BrowserThread::UI, | 103 content::BrowserThread::UI, |
101 FROM_HERE, | 104 FROM_HERE, |
102 base::Bind(&ReportSuccessfulBlocks), | 105 base::Bind(&ReportSuccessfulBlocks), |
103 base::TimeDelta::FromSeconds(kBlacklistReportingDelaySec)); | 106 base::TimeDelta::FromSeconds(kBlacklistReportingDelaySec)); |
104 } | 107 } |
105 | 108 |
109 void AddFinchBlacklistToRegistry() { | |
110 std::map<std::string, std::string> params; | |
111 if (chrome_variations::GetVariationParams(kBrowserBlacklistTrialName, | |
112 ¶ms)) { | |
113 base::win::RegKey finch_blacklist_registry_key(HKEY_CURRENT_USER, | |
csharp
2014/05/29 20:51:52
Incorrect indent (same for the following two lines
krstnmnlsn
2014/05/30 14:09:13
Done.
| |
114 blacklist::kRegistryFinchListPath, | |
115 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
116 | |
117 // No point in trying to continue if the registry key isn't valid. | |
csharp
2014/05/29 20:51:52
Should be indented 2 more spaces
krstnmnlsn
2014/05/30 14:09:13
Done.
| |
118 if (!finch_blacklist_registry_key.Valid()) | |
119 return; | |
120 | |
121 std::map<std::string, std::string>::iterator it = params.begin(); | |
122 while (it != params.end()) { | |
123 const char* name_str = (it->first).c_str(); | |
csharp
2014/05/29 20:51:52
The converting can be done with:
std::wstring wide
krstnmnlsn
2014/05/30 14:09:13
this is great!
| |
124 const char* val_str = (it->second).c_str(); | |
125 size_t name_len = MultiByteToWideChar(CP_UTF8, 0, name_str, -1, NULL, 0); | |
126 size_t val_len = MultiByteToWideChar(CP_UTF8, 0, val_str, -1, NULL, 0); | |
127 wchar_t* name = new wchar_t[name_len]; | |
128 wchar_t* val = new wchar_t[val_len]; | |
129 MultiByteToWideChar(CP_UTF8, 0, name_str, -1, name, name_len); | |
130 MultiByteToWideChar(CP_UTF8, 0, val_str, -1, val, val_len); | |
131 finch_blacklist_registry_key.WriteValue(name, val); | |
132 | |
133 delete[] name; | |
134 delete[] val; | |
135 | |
136 ++it; | |
137 } | |
138 } | |
139 } | |
140 | |
106 void BrowserBlacklistBeaconSetup() { | 141 void BrowserBlacklistBeaconSetup() { |
107 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, | 142 base::win::RegKey blacklist_registry_key(HKEY_CURRENT_USER, |
108 blacklist::kRegistryBeaconPath, | 143 blacklist::kRegistryBeaconPath, |
109 KEY_QUERY_VALUE | KEY_SET_VALUE); | 144 KEY_QUERY_VALUE | KEY_SET_VALUE); |
110 | 145 |
111 // No point in trying to continue if the registry key isn't valid. | 146 // No point in trying to continue if the registry key isn't valid. |
112 if (!blacklist_registry_key.Valid()) | 147 if (!blacklist_registry_key.Valid()) |
113 return; | 148 return; |
114 | 149 |
115 // Record the results of the last blacklist setup. | 150 // Record the results of the last blacklist setup. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 LONG set_state = blacklist_registry_key.WriteValue( | 188 LONG set_state = blacklist_registry_key.WriteValue( |
154 blacklist::kBeaconState, | 189 blacklist::kBeaconState, |
155 blacklist::BLACKLIST_ENABLED); | 190 blacklist::BLACKLIST_ENABLED); |
156 | 191 |
157 // Only report the blacklist as getting setup when both registry writes | 192 // Only report the blacklist as getting setup when both registry writes |
158 // succeed, since otherwise the blacklist wasn't properly setup. | 193 // succeed, since otherwise the blacklist wasn't properly setup. |
159 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) | 194 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) |
160 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); | 195 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); |
161 } | 196 } |
162 } | 197 } |
OLD | NEW |