Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1286)

Side by Side Diff: chrome/browser/about_flags.cc

Issue 344883002: Collect UMA statistics on which chrome://flags lead to chrome restart on ChromeOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/about_flags.h" 5 #include "chrome/browser/about_flags.h"
6 6
7 #include <stdint.h>
Ilya Sherman 2014/08/08 03:49:45 nit: This is already included in the header file.
Alexander Alekseev 2014/08/09 01:30:01 Done.
8
7 #include <iterator> 9 #include <iterator>
8 #include <map> 10 #include <map>
9 #include <set> 11 #include <set>
10 #include <utility> 12 #include <utility>
11 13
12 #include "base/command_line.h" 14 #include "base/command_line.h"
13 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
16 #include "base/metrics/sparse_histogram.h"
17 #include "base/numerics/safe_conversions.h"
14 #include "base/stl_util.h" 18 #include "base/stl_util.h"
15 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
17 #include "base/values.h" 21 #include "base/values.h"
18 #include "cc/base/switches.h" 22 #include "cc/base/switches.h"
19 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h" 23 #include "chrome/browser/bookmarks/enhanced_bookmarks_features.h"
20 #include "chrome/browser/flags_storage.h" 24 #include "chrome/browser/flags_storage.h"
21 #include "chrome/common/chrome_content_client.h" 25 #include "chrome/common/chrome_content_client.h"
22 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
23 #include "components/autofill/core/common/autofill_switches.h" 27 #include "components/autofill/core/common/autofill_switches.h"
24 #include "components/cloud_devices/common/cloud_devices_switches.h" 28 #include "components/cloud_devices/common/cloud_devices_switches.h"
25 #include "components/nacl/common/nacl_switches.h" 29 #include "components/nacl/common/nacl_switches.h"
26 #include "content/public/browser/user_metrics.h" 30 #include "content/public/browser/user_metrics.h"
27 #include "extensions/common/switches.h" 31 #include "extensions/common/switches.h"
28 #include "grit/chromium_strings.h" 32 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
30 #include "grit/google_chrome_strings.h" 34 #include "grit/google_chrome_strings.h"
31 #include "media/base/media_switches.h" 35 #include "media/base/media_switches.h"
36 #include "third_party/zlib/zlib.h"
32 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
33 #include "ui/base/ui_base_switches.h" 38 #include "ui/base/ui_base_switches.h"
34 #include "ui/display/display_switches.h" 39 #include "ui/display/display_switches.h"
35 #include "ui/events/event_switches.h" 40 #include "ui/events/event_switches.h"
36 #include "ui/gfx/switches.h" 41 #include "ui/gfx/switches.h"
37 #include "ui/gl/gl_switches.h" 42 #include "ui/gl/gl_switches.h"
38 #include "ui/keyboard/keyboard_switches.h" 43 #include "ui/keyboard/keyboard_switches.h"
39 #include "ui/native_theme/native_theme_switches.h" 44 #include "ui/native_theme/native_theme_switches.h"
40 #include "ui/views/views_switches.h" 45 #include "ui/views/views_switches.h"
41 46
(...skipping 12 matching lines...) Expand all
54 #endif 59 #endif
55 60
56 #if defined(ENABLE_APP_LIST) 61 #if defined(ENABLE_APP_LIST)
57 #include "ui/app_list/app_list_switches.h" 62 #include "ui/app_list/app_list_switches.h"
58 #endif 63 #endif
59 64
60 using base::UserMetricsAction; 65 using base::UserMetricsAction;
61 66
62 namespace about_flags { 67 namespace about_flags {
63 68
69 const uint32_t kBadSwitchFormatHistogramId = 0;
70
64 // Macros to simplify specifying the type. 71 // Macros to simplify specifying the type.
65 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ 72 #define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \
66 Experiment::SINGLE_VALUE, \ 73 Experiment::SINGLE_VALUE, \
67 command_line_switch, switch_value, NULL, NULL, NULL, 0 74 command_line_switch, switch_value, NULL, NULL, NULL, 0
68 #define SINGLE_VALUE_TYPE(command_line_switch) \ 75 #define SINGLE_VALUE_TYPE(command_line_switch) \
69 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "") 76 SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, "")
70 #define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \ 77 #define ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(enable_switch, enable_value, \
71 disable_switch, disable_value) \ 78 disable_switch, disable_value) \
72 Experiment::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \ 79 Experiment::ENABLE_DISABLE_VALUE, enable_switch, enable_value, \
73 disable_switch, disable_value, NULL, 3 80 disable_switch, disable_value, NULL, 3
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 }, 1516 },
1510 #endif 1517 #endif
1511 #if defined(OS_ANDROID) 1518 #if defined(OS_ANDROID)
1512 { 1519 {
1513 "enable-accessibility-tab-switcher", 1520 "enable-accessibility-tab-switcher",
1514 IDS_FLAGS_ENABLE_ACCESSIBILITY_TAB_SWITCHER_NAME, 1521 IDS_FLAGS_ENABLE_ACCESSIBILITY_TAB_SWITCHER_NAME,
1515 IDS_FLAGS_ENABLE_ACCESSIBILITY_TAB_SWITCHER_DESCRIPTION, 1522 IDS_FLAGS_ENABLE_ACCESSIBILITY_TAB_SWITCHER_DESCRIPTION,
1516 kOsAndroid, 1523 kOsAndroid,
1517 SINGLE_VALUE_TYPE(switches::kEnableAccessibilityTabSwitcher) 1524 SINGLE_VALUE_TYPE(switches::kEnableAccessibilityTabSwitcher)
1518 }, 1525 },
1519 {
1520 // TODO(dmazzoni): remove this flag when native android accessibility
1521 // ships in the stable channel. http://crbug.com/356775
1522 "enable-accessibility-script-injection",
1523 IDS_FLAGS_ENABLE_ACCESSIBILITY_SCRIPT_INJECTION_NAME,
1524 IDS_FLAGS_ENABLE_ACCESSIBILITY_SCRIPT_INJECTION_DESCRIPTION,
1525 kOsAndroid,
1526 // Java-only switch: ContentSwitches.ENABLE_ACCESSIBILITY_SCRIPT_INJECTION.
1527 SINGLE_VALUE_TYPE("enable-accessibility-script-injection")
1528 },
1529 #endif 1526 #endif
1530 { 1527 {
1531 "enable-one-copy", 1528 "enable-one-copy",
1532 IDS_FLAGS_ONE_COPY_NAME, 1529 IDS_FLAGS_ONE_COPY_NAME,
1533 IDS_FLAGS_ONE_COPY_DESCRIPTION, 1530 IDS_FLAGS_ONE_COPY_DESCRIPTION,
1534 kOsAll, 1531 kOsAll,
1535 SINGLE_VALUE_TYPE(switches::kEnableOneCopy) 1532 SINGLE_VALUE_TYPE(switches::kEnableOneCopy)
1536 }, 1533 },
1537 { 1534 {
1538 "enable-zero-copy", 1535 "enable-zero-copy",
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
2137 2134
2138 void ConvertFlagsToSwitches(FlagsStorage* flags_storage, 2135 void ConvertFlagsToSwitches(FlagsStorage* flags_storage,
2139 CommandLine* command_line, 2136 CommandLine* command_line,
2140 SentinelsMode sentinels) { 2137 SentinelsMode sentinels) {
2141 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage, 2138 FlagsState::GetInstance()->ConvertFlagsToSwitches(flags_storage,
2142 command_line, 2139 command_line,
2143 sentinels); 2140 sentinels);
2144 } 2141 }
2145 2142
2146 bool AreSwitchesIdenticalToCurrentCommandLine( 2143 bool AreSwitchesIdenticalToCurrentCommandLine(
2147 const CommandLine& new_cmdline, const CommandLine& active_cmdline) { 2144 const CommandLine& new_cmdline,
2145 const CommandLine& active_cmdline,
2146 std::set<CommandLine::StringType>* out_difference) {
2148 std::set<CommandLine::StringType> new_flags = 2147 std::set<CommandLine::StringType> new_flags =
2149 ExtractFlagsFromCommandLine(new_cmdline); 2148 ExtractFlagsFromCommandLine(new_cmdline);
2150 std::set<CommandLine::StringType> active_flags = 2149 std::set<CommandLine::StringType> active_flags =
2151 ExtractFlagsFromCommandLine(active_cmdline); 2150 ExtractFlagsFromCommandLine(active_cmdline);
2152 2151
2152 bool result = false;
2153 // Needed because std::equal doesn't check if the 2nd set is empty. 2153 // Needed because std::equal doesn't check if the 2nd set is empty.
2154 if (new_flags.size() != active_flags.size()) 2154 if (new_flags.size() == active_flags.size()) {
2155 return false; 2155 result =
2156 std::equal(new_flags.begin(), new_flags.end(), active_flags.begin());
2157 }
2156 2158
2157 return std::equal(new_flags.begin(), new_flags.end(), active_flags.begin()); 2159 if (out_difference && !result) {
2160 std::set_symmetric_difference(
2161 new_flags.begin(),
2162 new_flags.end(),
2163 active_flags.begin(),
2164 active_flags.end(),
2165 std::inserter(*out_difference, out_difference->begin()));
2166 }
2167
2168 return result;
2158 } 2169 }
2159 2170
2160 void GetFlagsExperimentsData(FlagsStorage* flags_storage, 2171 void GetFlagsExperimentsData(FlagsStorage* flags_storage,
2161 FlagAccess access, 2172 FlagAccess access,
2162 base::ListValue* supported_experiments, 2173 base::ListValue* supported_experiments,
2163 base::ListValue* unsupported_experiments) { 2174 base::ListValue* unsupported_experiments) {
2164 std::set<std::string> enabled_experiments; 2175 std::set<std::string> enabled_experiments;
2165 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments); 2176 GetSanitizedEnabledFlags(flags_storage, &enabled_experiments);
2166 2177
2167 int current_platform = GetCurrentPlatform(); 2178 int current_platform = GetCurrentPlatform();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 action += *it; 2266 action += *it;
2256 content::RecordComputedAction(action); 2267 content::RecordComputedAction(action);
2257 } 2268 }
2258 // Since flag metrics are recorded every startup, add a tick so that the 2269 // Since flag metrics are recorded every startup, add a tick so that the
2259 // stats can be made meaningful. 2270 // stats can be made meaningful.
2260 if (flags.size()) 2271 if (flags.size())
2261 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick")); 2272 content::RecordAction(UserMetricsAction("AboutFlags_StartupTick"));
2262 content::RecordAction(UserMetricsAction("StartupTick")); 2273 content::RecordAction(UserMetricsAction("StartupTick"));
2263 } 2274 }
2264 2275
2276 uint32_t GetSwitchUMAId(const std::string& switch_name) {
2277 return base::checked_cast<unsigned>(
Ilya Sherman 2014/08/08 03:49:45 nit: unsigned -> uint32_t
Alexander Alekseev 2014/08/09 01:30:01 Done.
2278 crc32(0,
2279 reinterpret_cast<const Bytef*>(switch_name.c_str()),
2280 switch_name.length()));
2281 }
2282
2283 void ReportCustomFlags(const std::string& uma_histogram_hame,
2284 const std::set<std::string>& command_line_difference) {
2285 for (std::set<std::string>::const_iterator it =
2286 command_line_difference.begin();
2287 it != command_line_difference.end();
2288 ++it) {
2289 int uma_id = about_flags::kBadSwitchFormatHistogramId;
2290 if (StartsWithASCII(*it, "--", true /* case_sensitive */)) {
2291 // Skip '--' before switch name.
2292 std::string switch_name(it->substr(2));
2293
2294 // Kill value, if any.
2295 const size_t value_pos = switch_name.find('=');
2296 if (value_pos != std::string::npos)
2297 switch_name.resize(value_pos);
2298
2299 uma_id = GetSwitchUMAId(switch_name);
2300 } else {
2301 NOTREACHED() << "ReportCustomFlags(): flag '" << *it
2302 << "' has incorrect format.";
2303 }
2304 VLOG(1) << "ReportCustomFlags(): histogram='" << uma_histogram_hame << "' '"
2305 << *it << "', uma_id=" << uma_id;
2306
2307 // Sparse histogram macro does not cache the histogram, so it's safe
2308 // to use macro with non-static histogram name here.
2309 UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_hame, uma_id);
2310 }
2311 }
2312
2265 ////////////////////////////////////////////////////////////////////////////// 2313 //////////////////////////////////////////////////////////////////////////////
2266 // FlagsState implementation. 2314 // FlagsState implementation.
2267 2315
2268 namespace { 2316 namespace {
2269 2317
2270 typedef std::map<std::string, std::pair<std::string, std::string> > 2318 typedef std::map<std::string, std::pair<std::string, std::string> >
2271 NameToSwitchAndValueMap; 2319 NameToSwitchAndValueMap;
2272 2320
2273 void SetFlagToSwitchMapping(const std::string& key, 2321 void SetFlagToSwitchMapping(const std::string& key,
2274 const std::string& switch_name, 2322 const std::string& switch_name,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 } 2502 }
2455 2503
2456 const Experiment* GetExperiments(size_t* count) { 2504 const Experiment* GetExperiments(size_t* count) {
2457 *count = num_experiments; 2505 *count = num_experiments;
2458 return experiments; 2506 return experiments;
2459 } 2507 }
2460 2508
2461 } // namespace testing 2509 } // namespace testing
2462 2510
2463 } // namespace about_flags 2511 } // namespace about_flags
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698