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 // We can set the state to disabled without checking that the maximum number |
127 RecordBlacklistSetupEvent(BLACKLIST_THUNK_SETUP_FAILED); | 132 // of attempts was exceeded because blacklist.cc has already done this. |
128 break; | 133 RecordBlacklistSetupEvent(BLACKLIST_SETUP_FAILED); |
129 case blacklist::BLACKLIST_INTERCEPTING: | 134 blacklist_registry_key.WriteValue(blacklist::kBeaconState, |
130 RecordBlacklistSetupEvent(BLACKLIST_INTERCEPTION_FAILED); | 135 blacklist::BLACKLIST_DISABLED); |
131 break; | 136 } else if (blacklist_state == blacklist::BLACKLIST_DISABLED) { |
132 } | 137 RecordBlacklistSetupEvent(BLACKLIST_SETUP_DISABLED); |
133 | |
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 } | 138 } |
141 | 139 |
142 // Find the last recorded blacklist version. | 140 // Find the last recorded blacklist version. |
143 base::string16 blacklist_version; | 141 base::string16 blacklist_version; |
144 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion, | 142 blacklist_registry_key.ReadValue(blacklist::kBeaconVersion, |
145 &blacklist_version); | 143 &blacklist_version); |
146 | 144 |
147 if (blacklist_version != TEXT(CHROME_VERSION_STRING)) { | 145 if (blacklist_version != TEXT(CHROME_VERSION_STRING)) { |
148 // The blacklist hasn't been enabled for this version yet, so enable it. | 146 // The blacklist hasn't been enabled for this version yet, so enable it |
| 147 // and reset the failure count to zero. |
149 LONG set_version = blacklist_registry_key.WriteValue( | 148 LONG set_version = blacklist_registry_key.WriteValue( |
150 blacklist::kBeaconVersion, | 149 blacklist::kBeaconVersion, |
151 TEXT(CHROME_VERSION_STRING)); | 150 TEXT(CHROME_VERSION_STRING)); |
152 | 151 |
153 LONG set_state = blacklist_registry_key.WriteValue( | 152 LONG set_state = blacklist_registry_key.WriteValue( |
154 blacklist::kBeaconState, | 153 blacklist::kBeaconState, |
155 blacklist::BLACKLIST_ENABLED); | 154 blacklist::BLACKLIST_ENABLED); |
156 | 155 |
| 156 blacklist_registry_key.WriteValue(blacklist::kBeaconAttemptCount, |
| 157 static_cast<DWORD>(0)); |
| 158 |
157 // Only report the blacklist as getting setup when both registry writes | 159 // Only report the blacklist as getting setup when both registry writes |
158 // succeed, since otherwise the blacklist wasn't properly setup. | 160 // succeed, since otherwise the blacklist wasn't properly setup. |
159 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) | 161 if (set_version == ERROR_SUCCESS && set_state == ERROR_SUCCESS) |
160 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); | 162 RecordBlacklistSetupEvent(BLACKLIST_SETUP_ENABLED); |
161 } | 163 } |
162 } | 164 } |
OLD | NEW |