Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: chrome/browser/ui/search_engines/search_engine_tab_helper.cc

Issue 1410823003: Add UMA for window.external.AddSearchProvider (Chrome side). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mpearson review Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/search_engines/search_engine_tab_helper.h" 5 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
6 6
7 #include "base/metrics/histogram_macros.h"
7 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/search_engines/template_url_fetcher_factory.h" 10 #include "chrome/browser/search_engines/template_url_fetcher_factory.h"
10 #include "chrome/browser/search_engines/template_url_service_factory.h" 11 #include "chrome/browser/search_engines/template_url_service_factory.h"
12 #include "chrome/browser/ui/search_engines/edit_search_engine_controller.h"
11 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" 13 #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
12 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
13 #include "chrome/common/render_messages.h" 15 #include "chrome/common/render_messages.h"
14 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
15 #include "components/search_engines/template_url.h" 17 #include "components/search_engines/template_url.h"
16 #include "components/search_engines/template_url_fetcher.h" 18 #include "components/search_engines/template_url_fetcher.h"
17 #include "components/search_engines/template_url_service.h" 19 #include "components/search_engines/template_url_service.h"
18 #include "content/public/browser/favicon_status.h" 20 #include "content/public/browser/favicon_status.h"
19 #include "content/public/browser/navigation_controller.h" 21 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 116 }
115 117
116 void SearchEngineTabHelper::OnPageHasOSDD( 118 void SearchEngineTabHelper::OnPageHasOSDD(
117 const GURL& page_url, 119 const GURL& page_url,
118 const GURL& osdd_url, 120 const GURL& osdd_url,
119 const search_provider::OSDDType& msg_provider_type) { 121 const search_provider::OSDDType& msg_provider_type) {
120 // Checks to see if we should generate a keyword based on the OSDD, and if 122 // Checks to see if we should generate a keyword based on the OSDD, and if
121 // necessary uses TemplateURLFetcher to download the OSDD and create a 123 // necessary uses TemplateURLFetcher to download the OSDD and create a
122 // keyword. 124 // keyword.
123 125
126 TemplateURLFetcher::ProviderType provider_type =
127 (msg_provider_type == search_provider::AUTODETECTED_PROVIDER)
128 ? TemplateURLFetcher::AUTODETECTED_PROVIDER
129 : TemplateURLFetcher::EXPLICIT_PROVIDER;
130
131 if (provider_type == TemplateURLFetcher::EXPLICIT_PROVIDER) {
132 UMA_HISTOGRAM_ENUMERATION(
133 "Search.AddSearchProvider",
134 EditSearchEngineController::ADD_SEARCH_PROVIDER_CALLED,
135 EditSearchEngineController::NUM_EDIT_SEARCH_ENGINE_ACTIONS);
136 }
137
124 // Make sure that the page is the current page and other basic checks. 138 // Make sure that the page is the current page and other basic checks.
125 // When |page_url| has file: scheme, this method doesn't work because of 139 // When |page_url| has file: scheme, this method doesn't work because of
126 // http://b/issue?id=863583. For that reason, this doesn't check and allow 140 // http://b/issue?id=863583. For that reason, this doesn't check and allow
127 // urls referring to osdd urls with same schemes. 141 // urls referring to osdd urls with same schemes.
128 if (!osdd_url.is_valid() || !osdd_url.SchemeIsHTTPOrHTTPS()) 142 if (!osdd_url.is_valid() || !osdd_url.SchemeIsHTTPOrHTTPS())
129 return; 143 return;
130 144
131 Profile* profile = 145 Profile* profile =
132 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 146 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
133 if (page_url != web_contents()->GetLastCommittedURL() || 147 if (page_url != web_contents()->GetLastCommittedURL() ||
134 !TemplateURLFetcherFactory::GetForProfile(profile) || 148 !TemplateURLFetcherFactory::GetForProfile(profile) ||
135 profile->IsOffTheRecord()) 149 profile->IsOffTheRecord())
136 return; 150 return;
137 151
138 TemplateURLFetcher::ProviderType provider_type =
139 (msg_provider_type == search_provider::AUTODETECTED_PROVIDER) ?
140 TemplateURLFetcher::AUTODETECTED_PROVIDER :
141 TemplateURLFetcher::EXPLICIT_PROVIDER;
142
143 // If the current page is a form submit, find the last page that was not a 152 // If the current page is a form submit, find the last page that was not a
144 // form submit and use its url to generate the keyword from. 153 // form submit and use its url to generate the keyword from.
145 const NavigationController& controller = web_contents()->GetController(); 154 const NavigationController& controller = web_contents()->GetController();
146 const NavigationEntry* entry = controller.GetLastCommittedEntry(); 155 const NavigationEntry* entry = controller.GetLastCommittedEntry();
147 for (int index = controller.GetLastCommittedEntryIndex(); 156 for (int index = controller.GetLastCommittedEntryIndex();
148 (index > 0) && IsFormSubmit(entry); 157 (index > 0) && IsFormSubmit(entry);
149 entry = controller.GetEntryAtIndex(index)) 158 entry = controller.GetEntryAtIndex(index))
150 --index; 159 --index;
151 if (!entry || IsFormSubmit(entry)) 160 if (!entry || IsFormSubmit(entry))
152 return; 161 return;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // the favicon url wasn't obtained before the load started. This assumes the 247 // the favicon url wasn't obtained before the load started. This assumes the
239 // latter. 248 // latter.
240 // TODO(sky): Need a way to set the favicon that doesn't involve generating 249 // TODO(sky): Need a way to set the favicon that doesn't involve generating
241 // its url. 250 // its url.
242 data.favicon_url = current_favicon.is_valid() ? 251 data.favicon_url = current_favicon.is_valid() ?
243 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url); 252 current_favicon : TemplateURL::GenerateFaviconURL(params.referrer.url);
244 data.safe_for_autoreplace = true; 253 data.safe_for_autoreplace = true;
245 data.input_encodings.push_back(params.searchable_form_encoding); 254 data.input_encodings.push_back(params.searchable_form_encoding);
246 url_service->Add(new TemplateURL(data)); 255 url_service->Add(new TemplateURL(data));
247 } 256 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search_engines/edit_search_engine_controller.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698