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/omnibox_metrics_provider.h" | 5 #include "chrome/browser/metrics/omnibox_metrics_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/browser/ui/browser_otr_state.h" | 14 #include "chrome/browser/ui/browser_otr_state.h" |
15 #include "components/metrics/metrics_log.h" | 15 #include "components/metrics/metrics_log.h" |
16 #include "components/metrics/proto/omnibox_event.pb.h" | 16 #include "components/metrics/proto/omnibox_event.pb.h" |
17 #include "components/metrics/proto/omnibox_input_type.pb.h" | 17 #include "components/metrics/proto/omnibox_input_type.pb.h" |
18 #include "components/omnibox/browser/autocomplete_match.h" | 18 #include "components/omnibox/browser/autocomplete_match.h" |
19 #include "components/omnibox/browser/autocomplete_provider.h" | 19 #include "components/omnibox/browser/autocomplete_provider.h" |
20 #include "components/omnibox/browser/autocomplete_result.h" | 20 #include "components/omnibox/browser/autocomplete_result.h" |
21 #include "components/omnibox/browser/omnibox_log.h" | 21 #include "components/omnibox/browser/omnibox_log.h" |
22 #include "content/public/browser/notification_service.h" | |
23 | 22 |
24 using metrics::OmniboxEventProto; | 23 using metrics::OmniboxEventProto; |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( | 27 OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( |
29 AutocompleteMatch::Type type) { | 28 AutocompleteMatch::Type type) { |
30 switch (type) { | 29 switch (type) { |
31 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: | 30 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: |
32 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED; | 31 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 73 |
75 } // namespace | 74 } // namespace |
76 | 75 |
77 OmniboxMetricsProvider::OmniboxMetricsProvider() { | 76 OmniboxMetricsProvider::OmniboxMetricsProvider() { |
78 } | 77 } |
79 | 78 |
80 OmniboxMetricsProvider::~OmniboxMetricsProvider() { | 79 OmniboxMetricsProvider::~OmniboxMetricsProvider() { |
81 } | 80 } |
82 | 81 |
83 void OmniboxMetricsProvider::OnRecordingEnabled() { | 82 void OmniboxMetricsProvider::OnRecordingEnabled() { |
84 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 83 subscription_ = OmniboxEventGlobalTracker::GetInstance()->RegisterCallback( |
85 content::NotificationService::AllSources()); | 84 base::Bind(&OmniboxMetricsProvider::OnURLOpenedFromOmnibox, |
| 85 base::Unretained(this))); |
86 } | 86 } |
87 | 87 |
88 void OmniboxMetricsProvider::OnRecordingDisabled() { | 88 void OmniboxMetricsProvider::OnRecordingDisabled() { |
89 registrar_.RemoveAll(); | 89 subscription_.reset(); |
90 } | 90 } |
91 | 91 |
92 void OmniboxMetricsProvider::ProvideGeneralMetrics( | 92 void OmniboxMetricsProvider::ProvideGeneralMetrics( |
93 metrics::ChromeUserMetricsExtension* uma_proto) { | 93 metrics::ChromeUserMetricsExtension* uma_proto) { |
94 uma_proto->mutable_omnibox_event()->Swap( | 94 uma_proto->mutable_omnibox_event()->Swap( |
95 omnibox_events_cache.mutable_omnibox_event()); | 95 omnibox_events_cache.mutable_omnibox_event()); |
96 } | 96 } |
97 | 97 |
98 void OmniboxMetricsProvider::Observe( | 98 void OmniboxMetricsProvider::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
99 int type, | |
100 const content::NotificationSource& source, | |
101 const content::NotificationDetails& details) { | |
102 DCHECK_EQ(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, type); | |
103 | |
104 // We simply don't log events to UMA if there is a single incognito | 99 // We simply don't log events to UMA if there is a single incognito |
105 // session visible. In the future, it may be worth revisiting this to | 100 // session visible. In the future, it may be worth revisiting this to |
106 // still log events from non-incognito sessions. | 101 // still log events from non-incognito sessions. |
107 if (!chrome::IsOffTheRecordSessionActive()) | 102 if (!chrome::IsOffTheRecordSessionActive()) |
108 RecordOmniboxOpenedURL(*content::Details<OmniboxLog>(details).ptr()); | 103 RecordOmniboxOpenedURL(*log); |
109 } | 104 } |
110 | 105 |
111 void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) { | 106 void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) { |
112 std::vector<base::StringPiece16> terms = base::SplitStringPiece( | 107 std::vector<base::StringPiece16> terms = base::SplitStringPiece( |
113 log.text, base::kWhitespaceUTF16, | 108 log.text, base::kWhitespaceUTF16, |
114 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 109 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
115 | 110 |
116 OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event(); | 111 OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event(); |
117 omnibox_event->set_time(metrics::MetricsLog::GetCurrentTime()); | 112 omnibox_event->set_time(metrics::MetricsLog::GetCurrentTime()); |
118 if (log.tab_id != -1) { | 113 if (log.tab_id != -1) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 if (i->typed_count != -1) | 152 if (i->typed_count != -1) |
158 suggestion->set_typed_count(i->typed_count); | 153 suggestion->set_typed_count(i->typed_count); |
159 } | 154 } |
160 for (ProvidersInfo::const_iterator i(log.providers_info.begin()); | 155 for (ProvidersInfo::const_iterator i(log.providers_info.begin()); |
161 i != log.providers_info.end(); ++i) { | 156 i != log.providers_info.end(); ++i) { |
162 OmniboxEventProto::ProviderInfo* provider_info = | 157 OmniboxEventProto::ProviderInfo* provider_info = |
163 omnibox_event->add_provider_info(); | 158 omnibox_event->add_provider_info(); |
164 provider_info->CopyFrom(*i); | 159 provider_info->CopyFrom(*i); |
165 } | 160 } |
166 } | 161 } |
OLD | NEW |