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/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "chrome/browser/ui/browser_otr_state.h" | |
15 #include "components/metrics/metrics_log.h" | 14 #include "components/metrics/metrics_log.h" |
16 #include "components/metrics/proto/omnibox_event.pb.h" | 15 #include "components/metrics/proto/omnibox_event.pb.h" |
17 #include "components/metrics/proto/omnibox_input_type.pb.h" | 16 #include "components/metrics/proto/omnibox_input_type.pb.h" |
18 #include "components/omnibox/browser/autocomplete_match.h" | 17 #include "components/omnibox/browser/autocomplete_match.h" |
19 #include "components/omnibox/browser/autocomplete_provider.h" | 18 #include "components/omnibox/browser/autocomplete_provider.h" |
20 #include "components/omnibox/browser/autocomplete_result.h" | 19 #include "components/omnibox/browser/autocomplete_result.h" |
21 #include "components/omnibox/browser/omnibox_log.h" | 20 #include "components/omnibox/browser/omnibox_log.h" |
22 | 21 |
23 using metrics::OmniboxEventProto; | 22 using metrics::OmniboxEventProto; |
24 | 23 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 case AutocompleteMatchType::CONTACT_DEPRECATED: | 65 case AutocompleteMatchType::CONTACT_DEPRECATED: |
67 case AutocompleteMatchType::NUM_TYPES: | 66 case AutocompleteMatchType::NUM_TYPES: |
68 break; | 67 break; |
69 } | 68 } |
70 NOTREACHED(); | 69 NOTREACHED(); |
71 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; | 70 return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; |
72 } | 71 } |
73 | 72 |
74 } // namespace | 73 } // namespace |
75 | 74 |
76 OmniboxMetricsProvider::OmniboxMetricsProvider() { | 75 OmniboxMetricsProvider::OmniboxMetricsProvider( |
77 } | 76 const base::Callback<bool(void)>& is_off_the_record_callback) |
| 77 : is_off_the_record_callback_(is_off_the_record_callback) {} |
78 | 78 |
79 OmniboxMetricsProvider::~OmniboxMetricsProvider() { | 79 OmniboxMetricsProvider::~OmniboxMetricsProvider() { |
80 } | 80 } |
81 | 81 |
82 void OmniboxMetricsProvider::OnRecordingEnabled() { | 82 void OmniboxMetricsProvider::OnRecordingEnabled() { |
83 subscription_ = OmniboxEventGlobalTracker::GetInstance()->RegisterCallback( | 83 subscription_ = OmniboxEventGlobalTracker::GetInstance()->RegisterCallback( |
84 base::Bind(&OmniboxMetricsProvider::OnURLOpenedFromOmnibox, | 84 base::Bind(&OmniboxMetricsProvider::OnURLOpenedFromOmnibox, |
85 base::Unretained(this))); | 85 base::Unretained(this))); |
86 } | 86 } |
87 | 87 |
88 void OmniboxMetricsProvider::OnRecordingDisabled() { | 88 void OmniboxMetricsProvider::OnRecordingDisabled() { |
89 subscription_.reset(); | 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::OnURLOpenedFromOmnibox(OmniboxLog* log) { | 98 void OmniboxMetricsProvider::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
99 // We simply don't log events to UMA if there is a single incognito | 99 // Do not log events to UMA if the embedder reports that the user is in an |
100 // session visible. In the future, it may be worth revisiting this to | 100 // off-the-record context. |
101 // still log events from non-incognito sessions. | 101 if (!is_off_the_record_callback_.Run()) |
102 if (!chrome::IsOffTheRecordSessionActive()) | |
103 RecordOmniboxOpenedURL(*log); | 102 RecordOmniboxOpenedURL(*log); |
104 } | 103 } |
105 | 104 |
106 void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) { | 105 void OmniboxMetricsProvider::RecordOmniboxOpenedURL(const OmniboxLog& log) { |
107 std::vector<base::StringPiece16> terms = base::SplitStringPiece( | 106 std::vector<base::StringPiece16> terms = base::SplitStringPiece( |
108 log.text, base::kWhitespaceUTF16, | 107 log.text, base::kWhitespaceUTF16, |
109 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 108 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
110 | 109 |
111 OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event(); | 110 OmniboxEventProto* omnibox_event = omnibox_events_cache.add_omnibox_event(); |
112 omnibox_event->set_time(metrics::MetricsLog::GetCurrentTime()); | 111 omnibox_event->set_time(metrics::MetricsLog::GetCurrentTime()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (i->typed_count != -1) | 151 if (i->typed_count != -1) |
153 suggestion->set_typed_count(i->typed_count); | 152 suggestion->set_typed_count(i->typed_count); |
154 } | 153 } |
155 for (ProvidersInfo::const_iterator i(log.providers_info.begin()); | 154 for (ProvidersInfo::const_iterator i(log.providers_info.begin()); |
156 i != log.providers_info.end(); ++i) { | 155 i != log.providers_info.end(); ++i) { |
157 OmniboxEventProto::ProviderInfo* provider_info = | 156 OmniboxEventProto::ProviderInfo* provider_info = |
158 omnibox_event->add_provider_info(); | 157 omnibox_event->add_provider_info(); |
159 provider_info->CopyFrom(*i); | 158 provider_info->CopyFrom(*i); |
160 } | 159 } |
161 } | 160 } |
OLD | NEW |