Create OmniboxMetricsProvider class.

BUG=374226
R=isherman@chromium.org

Review URL: https://codereview.chromium.org/293013002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271885 0039d316-1c4b-4281-b951-d872f2087c98
parent c5d9dc1f
...@@ -25,21 +25,15 @@ ...@@ -25,21 +25,15 @@
#include "base/third_party/nspr/prtime.h" #include "base/third_party/nspr/prtime.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/tracked_objects.h" #include "base/tracked_objects.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_provider.h"
#include "chrome/browser/autocomplete/autocomplete_result.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/google/google_util.h" #include "chrome/browser/google/google_util.h"
#include "chrome/browser/metrics/extension_metrics.h" #include "chrome/browser/metrics/extension_metrics.h"
#include "chrome/browser/omnibox/omnibox_log.h"
#include "chrome/browser/plugins/plugin_prefs.h" #include "chrome/browser/plugins/plugin_prefs.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_version_info.h" #include "chrome/common/chrome_version_info.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/google_update_settings.h"
#include "components/metrics/metrics_provider.h" #include "components/metrics/metrics_provider.h"
#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/metrics/proto/profiler_event.pb.h" #include "components/metrics/proto/profiler_event.pb.h"
#include "components/metrics/proto/system_profile.pb.h" #include "components/metrics/proto/system_profile.pb.h"
#include "components/nacl/common/nacl_process_type.h" #include "components/nacl/common/nacl_process_type.h"
...@@ -68,7 +62,6 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; ...@@ -68,7 +62,6 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
using content::GpuDataManager; using content::GpuDataManager;
using metrics::MetricsLogBase; using metrics::MetricsLogBase;
using metrics::OmniboxEventProto;
using metrics::ProfilerEventProto; using metrics::ProfilerEventProto;
using metrics::SystemProfileProto; using metrics::SystemProfileProto;
using tracked_objects::ProcessDataSnapshot; using tracked_objects::ProcessDataSnapshot;
...@@ -88,95 +81,6 @@ std::string GetMetricsEnabledDate(PrefService* pref) { ...@@ -88,95 +81,6 @@ std::string GetMetricsEnabledDate(PrefService* pref) {
return pref->GetString(prefs::kMetricsReportingEnabledTimestamp); return pref->GetString(prefs::kMetricsReportingEnabledTimestamp);
} }
OmniboxEventProto::InputType AsOmniboxEventInputType(
AutocompleteInput::Type type) {
switch (type) {
case AutocompleteInput::INVALID:
return OmniboxEventProto::INVALID;
case AutocompleteInput::UNKNOWN:
return OmniboxEventProto::UNKNOWN;
case AutocompleteInput::URL:
return OmniboxEventProto::URL;
case AutocompleteInput::QUERY:
return OmniboxEventProto::QUERY;
case AutocompleteInput::FORCED_QUERY:
return OmniboxEventProto::FORCED_QUERY;
default:
NOTREACHED();
return OmniboxEventProto::INVALID;
}
}
OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
AutocompleteMatch::Type type) {
switch (type) {
case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
case AutocompleteMatchType::HISTORY_URL:
return OmniboxEventProto::Suggestion::HISTORY_URL;
case AutocompleteMatchType::HISTORY_TITLE:
return OmniboxEventProto::Suggestion::HISTORY_TITLE;
case AutocompleteMatchType::HISTORY_BODY:
return OmniboxEventProto::Suggestion::HISTORY_BODY;
case AutocompleteMatchType::HISTORY_KEYWORD:
return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
case AutocompleteMatchType::NAVSUGGEST:
return OmniboxEventProto::Suggestion::NAVSUGGEST;
case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
case AutocompleteMatchType::SEARCH_HISTORY:
return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
case AutocompleteMatchType::SEARCH_SUGGEST:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_ENTITY;
case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_INFINITE;
case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PERSONALIZED;
case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PROFILE;
case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
case AutocompleteMatchType::EXTENSION_APP:
return OmniboxEventProto::Suggestion::EXTENSION_APP;
case AutocompleteMatchType::BOOKMARK_TITLE:
return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
case AutocompleteMatchType::NAVSUGGEST_PERSONALIZED:
return OmniboxEventProto::Suggestion::NAVSUGGEST_PERSONALIZED;
default:
NOTREACHED();
return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
}
}
OmniboxEventProto::PageClassification AsOmniboxEventPageClassification(
AutocompleteInput::PageClassification page_classification) {
switch (page_classification) {
case AutocompleteInput::INVALID_SPEC:
return OmniboxEventProto::INVALID_SPEC;
case AutocompleteInput::NTP:
return OmniboxEventProto::NTP;
case AutocompleteInput::BLANK:
return OmniboxEventProto::BLANK;
case AutocompleteInput::HOME_PAGE:
return OmniboxEventProto::HOME_PAGE;
case AutocompleteInput::OTHER:
return OmniboxEventProto::OTHER;
case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
return OmniboxEventProto::
SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
case AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS:
return OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
case AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS:
return OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS;
case AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
return OmniboxEventProto::
SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
}
return OmniboxEventProto::INVALID_SPEC;
}
ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType(
int process_type) { int process_type) {
switch (process_type) { switch (process_type) {
...@@ -867,71 +771,6 @@ void MetricsLog::RecordProfilerData( ...@@ -867,71 +771,6 @@ void MetricsLog::RecordProfilerData(
WriteProfilerData(process_data, process_type, profile); WriteProfilerData(process_data, process_type, profile);
} }
void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) {
DCHECK(!locked());
std::vector<base::string16> terms;
const int num_terms =
static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms));
OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
if (log.tab_id != -1) {
// If we know what tab the autocomplete URL was opened in, log it.
omnibox_event->set_tab_id(log.tab_id);
}
omnibox_event->set_typed_length(log.text.length());
omnibox_event->set_just_deleted_text(log.just_deleted_text);
omnibox_event->set_num_typed_terms(num_terms);
omnibox_event->set_selected_index(log.selected_index);
if (log.completed_length != base::string16::npos)
omnibox_event->set_completed_length(log.completed_length);
const base::TimeDelta default_time_delta =
base::TimeDelta::FromMilliseconds(-1);
if (log.elapsed_time_since_user_first_modified_omnibox !=
default_time_delta) {
// Only upload the typing duration if it is set/valid.
omnibox_event->set_typing_duration_ms(
log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
}
if (log.elapsed_time_since_last_change_to_default_match !=
default_time_delta) {
omnibox_event->set_duration_since_last_default_match_update_ms(
log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
}
omnibox_event->set_current_page_classification(
AsOmniboxEventPageClassification(log.current_page_classification));
omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
// We consider a paste-and-search/paste-and-go action to have a closed popup
// (as explained in omnibox_event.proto) even if it was not, because such
// actions ignore the contents of the popup so it doesn't matter that it was
// open.
const bool consider_popup_open = log.is_popup_open && !log.is_paste_and_go;
omnibox_event->set_is_popup_open(consider_popup_open);
omnibox_event->set_is_paste_and_go(log.is_paste_and_go);
if (consider_popup_open) {
omnibox_event->set_is_top_result_hidden_in_dropdown(
log.result.ShouldHideTopMatch());
}
for (AutocompleteResult::const_iterator i(log.result.begin());
i != log.result.end(); ++i) {
OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
suggestion->set_result_type(AsOmniboxEventResultType(i->type));
suggestion->set_relevance(i->relevance);
if (i->typed_count != -1)
suggestion->set_typed_count(i->typed_count);
suggestion->set_is_starred(i->starred);
}
for (ProvidersInfo::const_iterator i(log.providers_info.begin());
i != log.providers_info.end(); ++i) {
OmniboxEventProto::ProviderInfo* provider_info =
omnibox_event->add_provider_info();
provider_info->CopyFrom(*i);
}
}
void MetricsLog::WriteGoogleUpdateProto( void MetricsLog::WriteGoogleUpdateProto(
const GoogleUpdateMetrics& google_update_metrics) { const GoogleUpdateMetrics& google_update_metrics) {
#if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) #if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN)
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
class HashedExtensionMetrics; class HashedExtensionMetrics;
class MetricsNetworkObserver; class MetricsNetworkObserver;
struct OmniboxLog;
class PrefService; class PrefService;
class PrefRegistrySimple; class PrefRegistrySimple;
...@@ -104,10 +103,6 @@ class MetricsLog : public metrics::MetricsLogBase { ...@@ -104,10 +103,6 @@ class MetricsLog : public metrics::MetricsLogBase {
// if there was no saved environment in prefs or it could not be decoded. // if there was no saved environment in prefs or it could not be decoded.
bool LoadSavedEnvironmentFromPrefs(); bool LoadSavedEnvironmentFromPrefs();
// Records the input text, available choices, and selected entry when the
// user uses the Omnibox to open a URL.
void RecordOmniboxOpenedURL(const OmniboxLog& log);
// Records the passed profiled data, which should be a snapshot of the // Records the passed profiled data, which should be a snapshot of the
// browser's profiled performance during startup for a single process. // browser's profiled performance during startup for a single process.
void RecordProfilerData( void RecordProfilerData(
......
...@@ -188,11 +188,11 @@ ...@@ -188,11 +188,11 @@
#include "chrome/browser/metrics/compression_utils.h" #include "chrome/browser/metrics/compression_utils.h"
#include "chrome/browser/metrics/metrics_log.h" #include "chrome/browser/metrics/metrics_log.h"
#include "chrome/browser/metrics/metrics_state_manager.h" #include "chrome/browser/metrics/metrics_state_manager.h"
#include "chrome/browser/metrics/omnibox_metrics_provider.h"
#include "chrome/browser/metrics/time_ticks_experiment_win.h" #include "chrome/browser/metrics/time_ticks_experiment_win.h"
#include "chrome/browser/metrics/tracking_synchronizer.h" #include "chrome/browser/metrics/tracking_synchronizer.h"
#include "chrome/browser/net/http_pipelining_compatibility_client.h" #include "chrome/browser/net/http_pipelining_compatibility_client.h"
#include "chrome/browser/net/network_stats.h" #include "chrome/browser/net/network_stats.h"
#include "chrome/browser/omnibox/omnibox_log.h"
#include "chrome/browser/ui/browser_otr_state.h" #include "chrome/browser/ui/browser_otr_state.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -480,6 +480,10 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager, ...@@ -480,6 +480,10 @@ MetricsService::MetricsService(metrics::MetricsStateManager* state_manager,
DCHECK(state_manager_); DCHECK(state_manager_);
DCHECK(client_); DCHECK(client_);
// TODO(asvitkine): Move this out of MetricsService.
RegisterMetricsProvider(
scoped_ptr<metrics::MetricsProvider>(new OmniboxMetricsProvider));
BrowserChildProcessObserver::Add(this); BrowserChildProcessObserver::Add(this);
} }
...@@ -642,19 +646,14 @@ void MetricsService::Observe(int type, ...@@ -642,19 +646,14 @@ void MetricsService::Observe(int type,
DCHECK(log_manager_.current_log()); DCHECK(log_manager_.current_log());
DCHECK(IsSingleThreaded()); DCHECK(IsSingleThreaded());
// Check for notifications related to core stability metrics, or that are
// just triggers to end idle mode. Anything else should be added in the later
// switch statement, where they take effect only if general metrics should be
// logged.
bool handled = false;
switch (type) { switch (type) {
case chrome::NOTIFICATION_BROWSER_OPENED: case chrome::NOTIFICATION_BROWSER_OPENED:
case chrome::NOTIFICATION_BROWSER_CLOSED: case chrome::NOTIFICATION_BROWSER_CLOSED:
case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
case chrome::NOTIFICATION_TAB_PARENTED: case chrome::NOTIFICATION_TAB_PARENTED:
case chrome::NOTIFICATION_TAB_CLOSING: case chrome::NOTIFICATION_TAB_CLOSING:
case content::NOTIFICATION_LOAD_STOP: case content::NOTIFICATION_LOAD_STOP:
// These notifications are used only to break out of idle mode. // These notifications are used only to break out of idle mode.
handled = true;
break; break;
case content::NOTIFICATION_LOAD_START: { case content::NOTIFICATION_LOAD_START: {
...@@ -662,7 +661,6 @@ void MetricsService::Observe(int type, ...@@ -662,7 +661,6 @@ void MetricsService::Observe(int type,
content::Source<content::NavigationController>(source).ptr(); content::Source<content::NavigationController>(source).ptr();
content::WebContents* web_contents = controller->GetWebContents(); content::WebContents* web_contents = controller->GetWebContents();
LogLoadStarted(web_contents); LogLoadStarted(web_contents);
handled = true;
break; break;
} }
...@@ -675,39 +673,18 @@ void MetricsService::Observe(int type, ...@@ -675,39 +673,18 @@ void MetricsService::Observe(int type,
content::Source<content::RenderProcessHost>(source).ptr(); content::Source<content::RenderProcessHost>(source).ptr();
LogRendererCrash( LogRendererCrash(
host, process_details->status, process_details->exit_code); host, process_details->status, process_details->exit_code);
handled = true;
break; break;
} }
case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG: case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
LogRendererHang(); LogRendererHang();
handled = true;
break; break;
default: default:
// Everything else is handled after the early return check below. NOTREACHED();
break; break;
} }
// If it wasn't one of the stability-related notifications, and event
// logging isn't suppressed, handle it.
if (!handled && ShouldLogEvents()) {
switch (type) {
case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: {
MetricsLog* current_log =
static_cast<MetricsLog*>(log_manager_.current_log());
DCHECK(current_log);
current_log->RecordOmniboxOpenedURL(
*content::Details<OmniboxLog>(details).ptr());
break;
}
default:
NOTREACHED();
break;
}
}
HandleIdleSinceLastTransmission(false); HandleIdleSinceLastTransmission(false);
} }
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/metrics/omnibox_metrics_provider.h"
#include <vector>
#include "base/logging.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "chrome/browser/autocomplete/autocomplete_input.h"
#include "chrome/browser/autocomplete/autocomplete_match.h"
#include "chrome/browser/autocomplete/autocomplete_provider.h"
#include "chrome/browser/autocomplete/autocomplete_result.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/omnibox/omnibox_log.h"
#include "chrome/browser/ui/browser_otr_state.h"
#include "components/metrics/metrics_log_base.h"
#include "content/public/browser/notification_service.h"
using metrics::OmniboxEventProto;
namespace {
OmniboxEventProto::InputType AsOmniboxEventInputType(
AutocompleteInput::Type type) {
switch (type) {
case AutocompleteInput::INVALID:
return OmniboxEventProto::INVALID;
case AutocompleteInput::UNKNOWN:
return OmniboxEventProto::UNKNOWN;
case AutocompleteInput::URL:
return OmniboxEventProto::URL;
case AutocompleteInput::QUERY:
return OmniboxEventProto::QUERY;
case AutocompleteInput::FORCED_QUERY:
return OmniboxEventProto::FORCED_QUERY;
}
NOTREACHED();
return OmniboxEventProto::INVALID;
}
OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType(
AutocompleteMatch::Type type) {
switch (type) {
case AutocompleteMatchType::URL_WHAT_YOU_TYPED:
return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED;
case AutocompleteMatchType::HISTORY_URL:
return OmniboxEventProto::Suggestion::HISTORY_URL;
case AutocompleteMatchType::HISTORY_TITLE:
return OmniboxEventProto::Suggestion::HISTORY_TITLE;
case AutocompleteMatchType::HISTORY_BODY:
return OmniboxEventProto::Suggestion::HISTORY_BODY;
case AutocompleteMatchType::HISTORY_KEYWORD:
return OmniboxEventProto::Suggestion::HISTORY_KEYWORD;
case AutocompleteMatchType::NAVSUGGEST:
return OmniboxEventProto::Suggestion::NAVSUGGEST;
case AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED:
return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED;
case AutocompleteMatchType::SEARCH_HISTORY:
return OmniboxEventProto::Suggestion::SEARCH_HISTORY;
case AutocompleteMatchType::SEARCH_SUGGEST:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST;
case AutocompleteMatchType::SEARCH_SUGGEST_ENTITY:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_ENTITY;
case AutocompleteMatchType::SEARCH_SUGGEST_INFINITE:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_INFINITE;
case AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PERSONALIZED;
case AutocompleteMatchType::SEARCH_SUGGEST_PROFILE:
return OmniboxEventProto::Suggestion::SEARCH_SUGGEST_PROFILE;
case AutocompleteMatchType::SEARCH_OTHER_ENGINE:
return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE;
case AutocompleteMatchType::EXTENSION_APP:
return OmniboxEventProto::Suggestion::EXTENSION_APP;
case AutocompleteMatchType::BOOKMARK_TITLE:
return OmniboxEventProto::Suggestion::BOOKMARK_TITLE;
case AutocompleteMatchType::NAVSUGGEST_PERSONALIZED:
return OmniboxEventProto::Suggestion::NAVSUGGEST_PERSONALIZED;
case AutocompleteMatchType::CONTACT_DEPRECATED:
case AutocompleteMatchType::NUM_TYPES:
break;
}
NOTREACHED();
return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE;
}
OmniboxEventProto::PageClassification AsOmniboxEventPageClassification(
AutocompleteInput::PageClassification page_classification) {
switch (page_classification) {
case AutocompleteInput::INVALID_SPEC:
return OmniboxEventProto::INVALID_SPEC;
case AutocompleteInput::NTP:
return OmniboxEventProto::NTP;
case AutocompleteInput::BLANK:
return OmniboxEventProto::BLANK;
case AutocompleteInput::HOME_PAGE:
return OmniboxEventProto::HOME_PAGE;
case AutocompleteInput::OTHER:
return OmniboxEventProto::OTHER;
case AutocompleteInput::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT:
return OmniboxEventProto::
SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT;
case AutocompleteInput::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS:
return OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS;
case AutocompleteInput::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS:
return OmniboxEventProto::INSTANT_NTP_WITH_FAKEBOX_AS_STARTING_FOCUS;
case AutocompleteInput::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT:
return OmniboxEventProto::
SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT;
}
NOTREACHED();
return OmniboxEventProto::INVALID_SPEC;
}
} // namespace
OmniboxMetricsProvider::OmniboxMetricsProvider() {
}
OmniboxMetricsProvider::~OmniboxMetricsProvider() {
}
void OmniboxMetricsProvider::OnRecordingEnabled() {
registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
content::NotificationService::AllSources());
}
void OmniboxMetricsProvider::OnRecordingDisabled() {
registrar_.RemoveAll();
}
void OmniboxMetricsProvider::ProvideGeneralMetrics(
metrics::ChromeUserMetricsExtension* uma_proto) {
uma_proto->mutable_omnibox_event()->Swap(
omnibox_events_cache.mutable_omnibox_event());
}
void OmniboxMetricsProvider::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, type);
// We simply don't log events to UMA if there is a single incognito
// session visible. In the future, it may be worth revisiting this to
// still log events from non-incognito sessions.
if (!chrome::IsOffTheRecordSessionActive())
RecordOmniboxOpenedURL(*content::Details<OmniboxLog>(details).ptr());
}
void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) {
std::vector<base::string16> terms;
const int num_terms =
static_cast<int>(Tokenize(log.text, base::kWhitespaceUTF16, &terms));
OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event();
omnibox_event->set_time(metrics::MetricsLogBase::GetCurrentTime());
if (log.tab_id != -1) {
// If we know what tab the autocomplete URL was opened in, log it.
omnibox_event->set_tab_id(log.tab_id);
}
omnibox_event->set_typed_length(log.text.length());
omnibox_event->set_just_deleted_text(log.just_deleted_text);
omnibox_event->set_num_typed_terms(num_terms);
omnibox_event->set_selected_index(log.selected_index);
if (log.completed_length != base::string16::npos)
omnibox_event->set_completed_length(log.completed_length);
const base::TimeDelta default_time_delta =
base::TimeDelta::FromMilliseconds(-1);
if (log.elapsed_time_since_user_first_modified_omnibox !=
default_time_delta) {
// Only upload the typing duration if it is set/valid.
omnibox_event->set_typing_duration_ms(
log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds());
}
if (log.elapsed_time_since_last_change_to_default_match !=
default_time_delta) {
omnibox_event->set_duration_since_last_default_match_update_ms(
log.elapsed_time_since_last_change_to_default_match.InMilliseconds());
}
omnibox_event->set_current_page_classification(
AsOmniboxEventPageClassification(log.current_page_classification));
omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
// We consider a paste-and-search/paste-and-go action to have a closed popup
// (as explained in omnibox_event.proto) even if it was not, because such
// actions ignore the contents of the popup so it doesn't matter that it was
// open.
const bool consider_popup_open = log.is_popup_open && !log.is_paste_and_go;
omnibox_event->set_is_popup_open(consider_popup_open);
omnibox_event->set_is_paste_and_go(log.is_paste_and_go);
if (consider_popup_open) {
omnibox_event->set_is_top_result_hidden_in_dropdown(
log.result.ShouldHideTopMatch());
}
for (AutocompleteResult::const_iterator i(log.result.begin());
i != log.result.end(); ++i) {
OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
suggestion->set_provider(i->provider->AsOmniboxEventProviderType());
suggestion->set_result_type(AsOmniboxEventResultType(i->type));
suggestion->set_relevance(i->relevance);
if (i->typed_count != -1)
suggestion->set_typed_count(i->typed_count);
suggestion->set_is_starred(i->starred);
}
for (ProvidersInfo::const_iterator i(log.providers_info.begin());
i != log.providers_info.end(); ++i) {
OmniboxEventProto::ProviderInfo* provider_info =
omnibox_event->add_provider_info();
provider_info->CopyFrom(*i);
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_OMNIBOX_METRICS_PROVIDER_H_
#define CHROME_BROWSER_METRICS_OMNIBOX_METRICS_PROVIDER_H_
#include "base/basictypes.h"
#include "components/metrics/metrics_provider.h"
#include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
struct OmniboxLog;
// OmniboxMetricsProvider is responsible for filling out the |omnibox_event|
// section of the UMA proto.
class OmniboxMetricsProvider : public metrics::MetricsProvider,
public content::NotificationObserver {
public:
OmniboxMetricsProvider();
virtual ~OmniboxMetricsProvider();
// metrics::MetricsDataProvider:
virtual void OnRecordingEnabled() OVERRIDE;
virtual void OnRecordingDisabled() OVERRIDE;
virtual void ProvideGeneralMetrics(
metrics::ChromeUserMetricsExtension* uma_proto) OVERRIDE;
private:
// content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Records the input text, available choices, and selected entry when the
// user uses the Omnibox to open a URL.
void RecordOmniboxOpenedURL(const OmniboxLog& log);
// Registar for receiving Omnibox event notifications.
content::NotificationRegistrar registrar_;
// Saved cache of generated Omnibox event protos, to be copied into the UMA
// proto when ProvideGeneralMetrics() is called.
metrics::ChromeUserMetricsExtension omnibox_events_cache;
DISALLOW_COPY_AND_ASSIGN(OmniboxMetricsProvider);
};
#endif // CHROME_BROWSER_METRICS_OMNIBOX_METRICS_PROVIDER_H_
...@@ -1213,6 +1213,8 @@ ...@@ -1213,6 +1213,8 @@
'browser/metrics/metrics_services_manager.h', 'browser/metrics/metrics_services_manager.h',
'browser/metrics/metrics_state_manager.cc', 'browser/metrics/metrics_state_manager.cc',
'browser/metrics/metrics_state_manager.h', 'browser/metrics/metrics_state_manager.h',
'browser/metrics/omnibox_metrics_provider.cc',
'browser/metrics/omnibox_metrics_provider.h',
'browser/metrics/perf_provider_chromeos.cc', 'browser/metrics/perf_provider_chromeos.cc',
'browser/metrics/perf_provider_chromeos.h', 'browser/metrics/perf_provider_chromeos.h',
'browser/metrics/thread_watcher.cc', 'browser/metrics/thread_watcher.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment