Index: chrome/browser/about_flags.cc |
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc |
index 7577556a0b3e3a97ca013d70cf3a88c938e8c25c..426442dcf8ea7534a109a5347a4a3d5acf122241 100644 |
--- a/chrome/browser/about_flags.cc |
+++ b/chrome/browser/about_flags.cc |
@@ -4,6 +4,8 @@ |
#include "chrome/browser/about_flags.h" |
+#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.
|
+ |
#include <iterator> |
#include <map> |
#include <set> |
@@ -11,6 +13,8 @@ |
#include "base/command_line.h" |
#include "base/memory/singleton.h" |
+#include "base/metrics/sparse_histogram.h" |
+#include "base/numerics/safe_conversions.h" |
#include "base/stl_util.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/utf_string_conversions.h" |
@@ -29,6 +33,7 @@ |
#include "grit/generated_resources.h" |
#include "grit/google_chrome_strings.h" |
#include "media/base/media_switches.h" |
+#include "third_party/zlib/zlib.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/ui_base_switches.h" |
#include "ui/display/display_switches.h" |
@@ -61,6 +66,8 @@ using base::UserMetricsAction; |
namespace about_flags { |
+const uint32_t kBadSwitchFormatHistogramId = 0; |
+ |
// Macros to simplify specifying the type. |
#define SINGLE_VALUE_TYPE_AND_VALUE(command_line_switch, switch_value) \ |
Experiment::SINGLE_VALUE, \ |
@@ -1516,16 +1523,6 @@ const Experiment kExperiments[] = { |
kOsAndroid, |
SINGLE_VALUE_TYPE(switches::kEnableAccessibilityTabSwitcher) |
}, |
- { |
- // TODO(dmazzoni): remove this flag when native android accessibility |
- // ships in the stable channel. http://crbug.com/356775 |
- "enable-accessibility-script-injection", |
- IDS_FLAGS_ENABLE_ACCESSIBILITY_SCRIPT_INJECTION_NAME, |
- IDS_FLAGS_ENABLE_ACCESSIBILITY_SCRIPT_INJECTION_DESCRIPTION, |
- kOsAndroid, |
- // Java-only switch: ContentSwitches.ENABLE_ACCESSIBILITY_SCRIPT_INJECTION. |
- SINGLE_VALUE_TYPE("enable-accessibility-script-injection") |
- }, |
#endif |
{ |
"enable-one-copy", |
@@ -2144,17 +2141,31 @@ void ConvertFlagsToSwitches(FlagsStorage* flags_storage, |
} |
bool AreSwitchesIdenticalToCurrentCommandLine( |
- const CommandLine& new_cmdline, const CommandLine& active_cmdline) { |
+ const CommandLine& new_cmdline, |
+ const CommandLine& active_cmdline, |
+ std::set<CommandLine::StringType>* out_difference) { |
std::set<CommandLine::StringType> new_flags = |
ExtractFlagsFromCommandLine(new_cmdline); |
std::set<CommandLine::StringType> active_flags = |
ExtractFlagsFromCommandLine(active_cmdline); |
+ bool result = false; |
// Needed because std::equal doesn't check if the 2nd set is empty. |
- if (new_flags.size() != active_flags.size()) |
- return false; |
+ if (new_flags.size() == active_flags.size()) { |
+ result = |
+ std::equal(new_flags.begin(), new_flags.end(), active_flags.begin()); |
+ } |
+ |
+ if (out_difference && !result) { |
+ std::set_symmetric_difference( |
+ new_flags.begin(), |
+ new_flags.end(), |
+ active_flags.begin(), |
+ active_flags.end(), |
+ std::inserter(*out_difference, out_difference->begin())); |
+ } |
- return std::equal(new_flags.begin(), new_flags.end(), active_flags.begin()); |
+ return result; |
} |
void GetFlagsExperimentsData(FlagsStorage* flags_storage, |
@@ -2262,6 +2273,43 @@ void RecordUMAStatistics(FlagsStorage* flags_storage) { |
content::RecordAction(UserMetricsAction("StartupTick")); |
} |
+uint32_t GetSwitchUMAId(const std::string& switch_name) { |
+ 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.
|
+ crc32(0, |
+ reinterpret_cast<const Bytef*>(switch_name.c_str()), |
+ switch_name.length())); |
+} |
+ |
+void ReportCustomFlags(const std::string& uma_histogram_hame, |
+ const std::set<std::string>& command_line_difference) { |
+ for (std::set<std::string>::const_iterator it = |
+ command_line_difference.begin(); |
+ it != command_line_difference.end(); |
+ ++it) { |
+ int uma_id = about_flags::kBadSwitchFormatHistogramId; |
+ if (StartsWithASCII(*it, "--", true /* case_sensitive */)) { |
+ // Skip '--' before switch name. |
+ std::string switch_name(it->substr(2)); |
+ |
+ // Kill value, if any. |
+ const size_t value_pos = switch_name.find('='); |
+ if (value_pos != std::string::npos) |
+ switch_name.resize(value_pos); |
+ |
+ uma_id = GetSwitchUMAId(switch_name); |
+ } else { |
+ NOTREACHED() << "ReportCustomFlags(): flag '" << *it |
+ << "' has incorrect format."; |
+ } |
+ VLOG(1) << "ReportCustomFlags(): histogram='" << uma_histogram_hame << "' '" |
+ << *it << "', uma_id=" << uma_id; |
+ |
+ // Sparse histogram macro does not cache the histogram, so it's safe |
+ // to use macro with non-static histogram name here. |
+ UMA_HISTOGRAM_SPARSE_SLOWLY(uma_histogram_hame, uma_id); |
+ } |
+} |
+ |
////////////////////////////////////////////////////////////////////////////// |
// FlagsState implementation. |