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/metrics/plugin_metrics_provider.h" | 5 #include "chrome/browser/metrics/plugin_metrics_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 void PluginMetricsProvider::ProvideStabilityMetrics( | 134 void PluginMetricsProvider::ProvideStabilityMetrics( |
135 metrics::SystemProfileProto* system_profile_proto) { | 135 metrics::SystemProfileProto* system_profile_proto) { |
136 RecordCurrentStateIfPending(); | 136 RecordCurrentStateIfPending(); |
137 const base::ListValue* plugin_stats_list = local_state_->GetList( | 137 const base::ListValue* plugin_stats_list = local_state_->GetList( |
138 prefs::kStabilityPluginStats); | 138 prefs::kStabilityPluginStats); |
139 if (!plugin_stats_list) | 139 if (!plugin_stats_list) |
140 return; | 140 return; |
141 | 141 |
142 metrics::SystemProfileProto::Stability* stability = | 142 metrics::SystemProfileProto::Stability* stability = |
143 system_profile_proto->mutable_stability(); | 143 system_profile_proto->mutable_stability(); |
144 for (base::ListValue::const_iterator iter = plugin_stats_list->begin(); | 144 for (const auto& value : *plugin_stats_list) { |
145 iter != plugin_stats_list->end(); ++iter) { | 145 base::DictionaryValue* plugin_dict; |
146 if (!(*iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 146 if (!value->GetAsDictionary(&plugin_dict)) { |
147 NOTREACHED(); | 147 NOTREACHED(); |
148 continue; | 148 continue; |
149 } | 149 } |
150 base::DictionaryValue* plugin_dict = | |
151 static_cast<base::DictionaryValue*>(*iter); | |
152 | 150 |
153 // Note that this search is potentially a quadratic operation, but given the | 151 // Note that this search is potentially a quadratic operation, but given the |
154 // low number of plugins installed on a "reasonable" setup, this should be | 152 // low number of plugins installed on a "reasonable" setup, this should be |
155 // fine. | 153 // fine. |
156 // TODO(isherman): Verify that this does not show up as a hotspot in | 154 // TODO(isherman): Verify that this does not show up as a hotspot in |
157 // profiler runs. | 155 // profiler runs. |
158 const metrics::SystemProfileProto::Plugin* system_profile_plugin = NULL; | 156 const metrics::SystemProfileProto::Plugin* system_profile_plugin = NULL; |
159 std::string plugin_name; | 157 std::string plugin_name; |
160 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); | 158 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
161 for (int i = 0; i < system_profile_proto->plugin_size(); ++i) { | 159 for (int i = 0; i < system_profile_proto->plugin_size(); ++i) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 local_state_->ClearPref(prefs::kStabilityPluginStats); | 201 local_state_->ClearPref(prefs::kStabilityPluginStats); |
204 } | 202 } |
205 | 203 |
206 // Saves plugin-related updates from the in-object buffer to Local State | 204 // Saves plugin-related updates from the in-object buffer to Local State |
207 // for retrieval next time we send a Profile log (generally next launch). | 205 // for retrieval next time we send a Profile log (generally next launch). |
208 void PluginMetricsProvider::RecordCurrentState() { | 206 void PluginMetricsProvider::RecordCurrentState() { |
209 ListPrefUpdate update(local_state_, prefs::kStabilityPluginStats); | 207 ListPrefUpdate update(local_state_, prefs::kStabilityPluginStats); |
210 base::ListValue* plugins = update.Get(); | 208 base::ListValue* plugins = update.Get(); |
211 DCHECK(plugins); | 209 DCHECK(plugins); |
212 | 210 |
213 for (base::ListValue::iterator value_iter = plugins->begin(); | 211 for (const auto& value : *plugins) { |
214 value_iter != plugins->end(); ++value_iter) { | 212 base::DictionaryValue* plugin_dict; |
215 if (!(*value_iter)->IsType(base::Value::TYPE_DICTIONARY)) { | 213 if (!value->GetAsDictionary(&plugin_dict)) { |
216 NOTREACHED(); | 214 NOTREACHED(); |
217 continue; | 215 continue; |
218 } | 216 } |
219 | 217 |
220 base::DictionaryValue* plugin_dict = | |
221 static_cast<base::DictionaryValue*>(*value_iter); | |
222 base::string16 plugin_name; | 218 base::string16 plugin_name; |
223 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); | 219 plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
224 if (plugin_name.empty()) { | 220 if (plugin_name.empty()) { |
225 NOTREACHED(); | 221 NOTREACHED(); |
226 continue; | 222 continue; |
227 } | 223 } |
228 | 224 |
229 if (child_process_stats_buffer_.find(plugin_name) == | 225 if (child_process_stats_buffer_.find(plugin_name) == |
230 child_process_stats_buffer_.end()) { | 226 child_process_stats_buffer_.end()) { |
231 continue; | 227 continue; |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 374 } |
379 | 375 |
380 bool PluginMetricsProvider::RecordCurrentStateIfPending() { | 376 bool PluginMetricsProvider::RecordCurrentStateIfPending() { |
381 if (!weak_ptr_factory_.HasWeakPtrs()) | 377 if (!weak_ptr_factory_.HasWeakPtrs()) |
382 return false; | 378 return false; |
383 | 379 |
384 weak_ptr_factory_.InvalidateWeakPtrs(); | 380 weak_ptr_factory_.InvalidateWeakPtrs(); |
385 RecordCurrentState(); | 381 RecordCurrentState(); |
386 return true; | 382 return true; |
387 } | 383 } |
OLD | NEW |