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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/browser/autocomplete/autocomplete_input.h" | 12 #include "chrome/browser/autocomplete/autocomplete_input.h" |
13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
14 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 14 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
15 #include "chrome/browser/autocomplete/autocomplete_result.h" | 15 #include "chrome/browser/autocomplete/autocomplete_result.h" |
16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
17 #include "chrome/browser/omnibox/omnibox_log.h" | 17 #include "chrome/browser/omnibox/omnibox_log.h" |
18 #include "chrome/browser/ui/browser_otr_state.h" | 18 #include "chrome/browser/ui/browser_otr_state.h" |
19 #include "components/metrics/metrics_log.h" | 19 #include "components/metrics/metrics_log.h" |
| 20 #include "components/metrics/proto/omnibox_event.pb.h" |
| 21 #include "components/metrics/proto/omnibox_input_type.pb.h" |
20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
21 | 23 |
22 using metrics::OmniboxEventProto; | 24 using metrics::OmniboxEventProto; |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 OmniboxEventProto::InputType AsOmniboxEventInputType( | |
27 AutocompleteInput::Type type) { | |
28 switch (type) { | |
29 case AutocompleteInput::INVALID: | |
30 return OmniboxEventProto::INVALID; | |
31 case AutocompleteInput::UNKNOWN: | |
32 return OmniboxEventProto::UNKNOWN; | |
33 case AutocompleteInput::URL: | |
34 return OmniboxEventProto::URL; | |
35 case AutocompleteInput::QUERY: | |
36 return OmniboxEventProto::QUERY; | |
37 case AutocompleteInput::FORCED_QUERY: | |
38 return OmniboxEventProto::FORCED_QUERY; | |
39 } | |
40 NOTREACHED(); | |
41 return OmniboxEventProto::INVALID; | |
42 } | |
43 | |
44 OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( | 28 OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( |
45 AutocompleteMatch::Type type) { | 29 AutocompleteMatch::Type type) { |
46 switch (type) { | 30 switch (type) { |
47 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: | 31 case AutocompleteMatchType::URL_WHAT_YOU_TYPED: |
48 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED; | 32 return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED; |
49 case AutocompleteMatchType::HISTORY_URL: | 33 case AutocompleteMatchType::HISTORY_URL: |
50 return OmniboxEventProto::Suggestion::HISTORY_URL; | 34 return OmniboxEventProto::Suggestion::HISTORY_URL; |
51 case AutocompleteMatchType::HISTORY_TITLE: | 35 case AutocompleteMatchType::HISTORY_TITLE: |
52 return OmniboxEventProto::Suggestion::HISTORY_TITLE; | 36 return OmniboxEventProto::Suggestion::HISTORY_TITLE; |
53 case AutocompleteMatchType::HISTORY_BODY: | 37 case AutocompleteMatchType::HISTORY_BODY: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 omnibox_event->set_typing_duration_ms( | 159 omnibox_event->set_typing_duration_ms( |
176 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); | 160 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
177 } | 161 } |
178 if (log.elapsed_time_since_last_change_to_default_match != | 162 if (log.elapsed_time_since_last_change_to_default_match != |
179 default_time_delta) { | 163 default_time_delta) { |
180 omnibox_event->set_duration_since_last_default_match_update_ms( | 164 omnibox_event->set_duration_since_last_default_match_update_ms( |
181 log.elapsed_time_since_last_change_to_default_match.InMilliseconds()); | 165 log.elapsed_time_since_last_change_to_default_match.InMilliseconds()); |
182 } | 166 } |
183 omnibox_event->set_current_page_classification( | 167 omnibox_event->set_current_page_classification( |
184 AsOmniboxEventPageClassification(log.current_page_classification)); | 168 AsOmniboxEventPageClassification(log.current_page_classification)); |
185 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type)); | 169 omnibox_event->set_input_type(log.input_type); |
186 // We consider a paste-and-search/paste-and-go action to have a closed popup | 170 // We consider a paste-and-search/paste-and-go action to have a closed popup |
187 // (as explained in omnibox_event.proto) even if it was not, because such | 171 // (as explained in omnibox_event.proto) even if it was not, because such |
188 // actions ignore the contents of the popup so it doesn't matter that it was | 172 // actions ignore the contents of the popup so it doesn't matter that it was |
189 // open. | 173 // open. |
190 const bool consider_popup_open = log.is_popup_open && !log.is_paste_and_go; | 174 const bool consider_popup_open = log.is_popup_open && !log.is_paste_and_go; |
191 omnibox_event->set_is_popup_open(consider_popup_open); | 175 omnibox_event->set_is_popup_open(consider_popup_open); |
192 omnibox_event->set_is_paste_and_go(log.is_paste_and_go); | 176 omnibox_event->set_is_paste_and_go(log.is_paste_and_go); |
193 if (consider_popup_open) { | 177 if (consider_popup_open) { |
194 omnibox_event->set_is_top_result_hidden_in_dropdown( | 178 omnibox_event->set_is_top_result_hidden_in_dropdown( |
195 log.result.ShouldHideTopMatch()); | 179 log.result.ShouldHideTopMatch()); |
196 } | 180 } |
197 | 181 |
198 for (AutocompleteResult::const_iterator i(log.result.begin()); | 182 for (AutocompleteResult::const_iterator i(log.result.begin()); |
199 i != log.result.end(); ++i) { | 183 i != log.result.end(); ++i) { |
200 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); | 184 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); |
201 suggestion->set_provider(i->provider->AsOmniboxEventProviderType()); | 185 suggestion->set_provider(i->provider->AsOmniboxEventProviderType()); |
202 suggestion->set_result_type(AsOmniboxEventResultType(i->type)); | 186 suggestion->set_result_type(AsOmniboxEventResultType(i->type)); |
203 suggestion->set_relevance(i->relevance); | 187 suggestion->set_relevance(i->relevance); |
204 if (i->typed_count != -1) | 188 if (i->typed_count != -1) |
205 suggestion->set_typed_count(i->typed_count); | 189 suggestion->set_typed_count(i->typed_count); |
206 suggestion->set_is_starred(i->starred); | 190 suggestion->set_is_starred(i->starred); |
207 } | 191 } |
208 for (ProvidersInfo::const_iterator i(log.providers_info.begin()); | 192 for (ProvidersInfo::const_iterator i(log.providers_info.begin()); |
209 i != log.providers_info.end(); ++i) { | 193 i != log.providers_info.end(); ++i) { |
210 OmniboxEventProto::ProviderInfo* provider_info = | 194 OmniboxEventProto::ProviderInfo* provider_info = |
211 omnibox_event->add_provider_info(); | 195 omnibox_event->add_provider_info(); |
212 provider_info->CopyFrom(*i); | 196 provider_info->CopyFrom(*i); |
213 } | 197 } |
214 } | 198 } |
OLD | NEW |