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" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 enum BlacklistSetupEventType { | 32 enum BlacklistSetupEventType { |
33 // The blacklist beacon has placed to enable the browser blacklisting. | 33 // The blacklist beacon has placed to enable the browser blacklisting. |
34 BLACKLIST_SETUP_ENABLED = 0, | 34 BLACKLIST_SETUP_ENABLED = 0, |
35 | 35 |
36 // The blacklist was successfully enabled. | 36 // The blacklist was successfully enabled. |
37 BLACKLIST_SETUP_RAN_SUCCESSFULLY, | 37 BLACKLIST_SETUP_RAN_SUCCESSFULLY, |
38 | 38 |
39 // The blacklist setup code failed to execute. | 39 // The blacklist setup code failed to execute. |
40 BLACKLIST_SETUP_FAILED, | 40 BLACKLIST_SETUP_FAILED, |
41 | 41 |
42 // The blacklist thunk setup code failed to execute. | 42 // Depreciated. The blacklist thunk setup code failed to execute. |
43 BLACKLIST_THUNK_SETUP_FAILED, | 43 BLACKLIST_THUNK_SETUP_FAILED, |
44 | 44 |
45 // The blacklist interception code failed to execute. | 45 // Depreciated. The blacklist interception code failed to execute. |
46 BLACKLIST_INTERCEPTION_FAILED, | 46 BLACKLIST_INTERCEPTION_FAILED, |
47 | 47 |
48 // The blacklist was disabled for this run (after it failed too many times). | |
49 BLACKLIST_SETUP_DISABLED, | |
50 | |
48 // Always keep this at the end. | 51 // Always keep this at the end. |
49 BLACKLIST_SETUP_EVENT_MAX, | 52 BLACKLIST_SETUP_EVENT_MAX, |
50 }; | 53 }; |
51 | 54 |
52 void RecordBlacklistSetupEvent(BlacklistSetupEventType blacklist_setup_event) { | 55 void RecordBlacklistSetupEvent(BlacklistSetupEventType blacklist_setup_event) { |
53 UMA_HISTOGRAM_ENUMERATION("Blacklist.Setup", | 56 UMA_HISTOGRAM_ENUMERATION("Blacklist.Setup", |
54 blacklist_setup_event, | 57 blacklist_setup_event, |
55 BLACKLIST_SETUP_EVENT_MAX); | 58 BLACKLIST_SETUP_EVENT_MAX); |
56 } | 59 } |
57 | 60 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 113 |
111 // No point in trying to continue if the registry key isn't valid. | 114 // No point in trying to continue if the registry key isn't valid. |
112 if (!blacklist_registry_key.Valid()) | 115 if (!blacklist_registry_key.Valid()) |
113 return; | 116 return; |
114 | 117 |
115 // Record the results of the last blacklist setup. | 118 // Record the results of the last blacklist setup. |
116 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX; | 119 DWORD blacklist_state = blacklist::BLACKLIST_STATE_MAX; |
117 blacklist_registry_key.ReadValueDW(blacklist::kBeaconState, &blacklist_state); | 120 blacklist_registry_key.ReadValueDW(blacklist::kBeaconState, &blacklist_state); |
118 | 121 |
119 if (blacklist_state == blacklist::BLACKLIST_ENABLED) { | 122 if (blacklist_state == blacklist::BLACKLIST_ENABLED) { |
123 // The blacklist was enabled successfully so we record the event (along with | |
124 // the number of failed previous attempts). | |
120 RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY); | 125 RecordBlacklistSetupEvent(BLACKLIST_SETUP_RAN_SUCCESSFULLY); |
121 } else { | 126 DWORD attempt_count = 0; |
122 switch (blacklist_state) { | 127 blacklist_registry_key.ReadValueDW(blacklist::kBeaconAttemptCount, |
123 case blacklist::BLACKLIST_SETUP_RUNNING: | 128 &attempt_count); |
124 RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED); | 129 UMA_HISTOGRAM_COUNTS("Blacklist.RetryWorked", attempt_count); |
125 break; | 130 } else if (blacklist_state == blacklist::BLACKLIST_SETUP_FAILED) { |
126 case blacklist::BLACKLIST_THUNK_SETUP: | 131 // Can set the state to disabled without checking that the maximum number of |
csharp
2014/06/11 13:34:43
Nit: can -> We can
krstnmnlsn
2014/06/11 16:35:27
Done.
| |
127 RecordBlacklistSetupEvent(BLACKLIST_THUNK_SETUP_FAILED); | 132 // attempts was exceeded because the failed state indicates this was already |
csharp
2014/06/11 13:34:43
nit: because... -> because blacklist.cc would have
krstnmnlsn
2014/06/11 16:35:27
Done.
| |
128 break; | 133 // done (in blacklist.cc). |
129 case blacklist::BLACKLIST_INTERCEPTING: | 134 RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED); |
130 RecordBlacklistSetupEvent(BLACKLIST_INTERCEPTION_FAILED); | 135 blacklist_registry_key.WriteValue(blacklist::kBeaconState, |
131 break; | 136 blacklist::BLACKLIST_DISABLED); |
132 } | 137 } else if (blacklist_state == blacklist::BLACKLIST_DISABLED) { |
133 | 138 RecordBlacklistSetupEvent(BLACKLIST_SETUP_DISABLED); |
134 // Since some part of the blacklist failed, mark it as disabled | |
135 // for this version. | |
136 if (blacklist_state != blacklist::BLACKLIST_DISABLED) { | |
137 blacklist_registry_key.WriteValue(blacklist::kBeaconState, | |
138 blacklist::BLACKLIST_DISABLED); | |
139 } | |
140 } | 139 } |
141 | 140 |
142 // Find the last recorded blacklist version. | 141 // Find the last recorded blacklist version. |
143 base::string16 blacklist_version; | 142 base::string16 blacklist_version; |
144 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion, | 143 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion, |
145 &blacklist_version); | 144 &blacklist_version); |
146 | 145 |
147 if (blacklist_version != TEXT(CHROME_VERSION_STRING)) { | 146 if (blacklist_version != TEXT(CHROME_VERSION_STRING)) { |
148 // The blacklist hasn't been enabled for this version yet, so enable it. | 147 // The blacklist hasn't been enabled for this version yet, so enable it |
148 // and reset the failure count to zero. | |
149 LONG set_version = blacklist_registry_key.WriteValue( | 149 LONG set_version = blacklist_registry_key.WriteValue( |
150 blacklist::kBeaconVersion, | 150 blacklist::kBeaconVersion, |
151 TEXT(CHROME_VERSION_STRING)); | 151 TEXT(CHROME_VERSION_STRING)); |
152 | 152 |
153 LONG set_state = blacklist_registry_key.WriteValue( | 153 LONG set_state = blacklist_registry_key.WriteValue( |
154 blacklist::kBeaconState, | 154 blacklist::kBeaconState, |
155 blacklist::BLACKLIST_ENABLED); | 155 blacklist::BLACKLIST_ENABLED); |
156 | 156 |
157 blacklist_registry_key.WriteValue(blacklist::kBeaconAttemptCount, | |
158 static_cast<DWORD>(0)); | |
159 | |
157 // Only report the blacklist as getting setup when both registry writes | 160 // Only report the blacklist as getting setup when both registry writes |
158 // succeed, since otherwise the blacklist wasn't properly setup. | 161 // succeed, since otherwise the blacklist wasn't properly setup. |
159 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) | 162 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) |
160 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); | 163 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); |
161 } | 164 } |
162 } | 165 } |
OLD | NEW |