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