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

Side by Side Diff: chrome/browser/rlz/chrome_rlz_tracker_delegate.cc

Issue 1243733002: Remove iOS specific code from ChromeRLZTrackerDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@rlz-tracker-delegate
Patch Set: Fix overzealous #include removal Created 5 years, 5 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
« no previous file with comments | « chrome/browser/rlz/chrome_rlz_tracker_delegate.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/rlz/chrome_rlz_tracker_delegate.h" 5 #include "chrome/browser/rlz/chrome_rlz_tracker_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h"
8 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/google/google_brand.h" 12 #include "chrome/browser/google/google_brand.h"
13 #include "chrome/browser/prefs/session_startup_pref.h"
12 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h" 15 #include "chrome/browser/search_engines/template_url_service_factory.h"
16 #include "chrome/browser/ui/startup/startup_browser_creator.h"
14 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
16 #include "components/google/core/browser/google_util.h" 19 #include "components/google/core/browser/google_util.h"
17 #include "components/omnibox/browser/omnibox_log.h" 20 #include "components/omnibox/browser/omnibox_log.h"
18 #include "components/search_engines/template_url.h" 21 #include "components/search_engines/template_url.h"
19 #include "components/search_engines/template_url_service.h" 22 #include "components/search_engines/template_url_service.h"
20 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/navigation_controller.h" 24 #include "content/public/browser/navigation_controller.h"
22 #include "content/public/browser/navigation_details.h" 25 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/navigation_entry.h" 26 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
25 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
27 30
28 #if defined(OS_WIN) 31 #if defined(OS_WIN)
29 #include "chrome/installer/util/google_update_settings.h" 32 #include "chrome/installer/util/google_update_settings.h"
30 #endif 33 #endif
31 34
32 #if !defined(OS_IOS)
33 #include "chrome/browser/prefs/session_startup_pref.h"
34 #include "chrome/browser/ui/startup/startup_browser_creator.h"
35 #endif
36
37 ChromeRLZTrackerDelegate::ChromeRLZTrackerDelegate() { 35 ChromeRLZTrackerDelegate::ChromeRLZTrackerDelegate() {
38 } 36 }
39 37
40 ChromeRLZTrackerDelegate::~ChromeRLZTrackerDelegate() { 38 ChromeRLZTrackerDelegate::~ChromeRLZTrackerDelegate() {
41 } 39 }
42 40
43 // static 41 // static
44 bool ChromeRLZTrackerDelegate::IsGoogleDefaultSearch(Profile* profile) { 42 bool ChromeRLZTrackerDelegate::IsGoogleDefaultSearch(Profile* profile) {
45 bool is_google_default_search = false; 43 bool is_google_default_search = false;
46 TemplateURLService* template_url_service = 44 TemplateURLService* template_url_service =
47 TemplateURLServiceFactory::GetForProfile(profile); 45 TemplateURLServiceFactory::GetForProfile(profile);
48 if (template_url_service) { 46 if (template_url_service) {
49 const TemplateURL* url_template = 47 const TemplateURL* url_template =
50 template_url_service->GetDefaultSearchProvider(); 48 template_url_service->GetDefaultSearchProvider();
51 is_google_default_search = url_template && 49 is_google_default_search = url_template &&
52 url_template->url_ref().HasGoogleBaseURLs( 50 url_template->url_ref().HasGoogleBaseURLs(
53 template_url_service->search_terms_data()); 51 template_url_service->search_terms_data());
54 } 52 }
55 return is_google_default_search; 53 return is_google_default_search;
56 } 54 }
57 55
58 // static 56 // static
59 bool ChromeRLZTrackerDelegate::IsGoogleHomepage(Profile* profile) { 57 bool ChromeRLZTrackerDelegate::IsGoogleHomepage(Profile* profile) {
60 return google_util::IsGoogleHomePageUrl( 58 return google_util::IsGoogleHomePageUrl(
61 GURL(profile->GetPrefs()->GetString(prefs::kHomePage))); 59 GURL(profile->GetPrefs()->GetString(prefs::kHomePage)));
62 } 60 }
63 61
64 // static 62 // static
65 bool ChromeRLZTrackerDelegate::IsGoogleInStartpages(Profile* profile) { 63 bool ChromeRLZTrackerDelegate::IsGoogleInStartpages(Profile* profile) {
66 #if !defined(OS_IOS)
67 bool is_google_in_startpages = false; 64 bool is_google_in_startpages = false;
68 SessionStartupPref session_startup_prefs = 65 SessionStartupPref session_startup_prefs =
69 StartupBrowserCreator::GetSessionStartupPref( 66 StartupBrowserCreator::GetSessionStartupPref(
70 *base::CommandLine::ForCurrentProcess(), profile); 67 *base::CommandLine::ForCurrentProcess(), profile);
71 if (session_startup_prefs.type == SessionStartupPref::URLS) { 68 if (session_startup_prefs.type == SessionStartupPref::URLS) {
72 is_google_in_startpages = 69 is_google_in_startpages =
73 std::count_if(session_startup_prefs.urls.begin(), 70 std::count_if(session_startup_prefs.urls.begin(),
74 session_startup_prefs.urls.end(), 71 session_startup_prefs.urls.end(),
75 google_util::IsGoogleHomePageUrl) > 0; 72 google_util::IsGoogleHomePageUrl) > 0;
76 } 73 }
77 return is_google_in_startpages; 74 return is_google_in_startpages;
78 #else
79 // iOS does not have a notion of startpages.
80 return false;
81 #endif
82 } 75 }
83 76
84 void ChromeRLZTrackerDelegate::Cleanup() { 77 void ChromeRLZTrackerDelegate::Cleanup() {
85 registrar_.RemoveAll(); 78 registrar_.RemoveAll();
86 on_omnibox_search_callback_.Reset(); 79 on_omnibox_search_callback_.Reset();
87 on_homepage_search_callback_.Reset(); 80 on_homepage_search_callback_.Reset();
88 } 81 }
89 82
90 bool ChromeRLZTrackerDelegate::IsOnUIThread() { 83 bool ChromeRLZTrackerDelegate::IsOnUIThread() {
91 return content::BrowserThread::CurrentlyOn(content::BrowserThread::UI); 84 return content::BrowserThread::CurrentlyOn(content::BrowserThread::UI);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 void ChromeRLZTrackerDelegate::SetOmniboxSearchCallback( 142 void ChromeRLZTrackerDelegate::SetOmniboxSearchCallback(
150 const base::Closure& callback) { 143 const base::Closure& callback) {
151 DCHECK(!callback.is_null()); 144 DCHECK(!callback.is_null());
152 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 145 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
153 content::NotificationService::AllSources()); 146 content::NotificationService::AllSources());
154 on_omnibox_search_callback_ = callback; 147 on_omnibox_search_callback_ = callback;
155 } 148 }
156 149
157 void ChromeRLZTrackerDelegate::SetHomepageSearchCallback( 150 void ChromeRLZTrackerDelegate::SetHomepageSearchCallback(
158 const base::Closure& callback) { 151 const base::Closure& callback) {
159 #if !defined(OS_IOS)
160 DCHECK(!callback.is_null()); 152 DCHECK(!callback.is_null());
161 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 153 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
162 content::NotificationService::AllSources()); 154 content::NotificationService::AllSources());
163 on_homepage_search_callback_ = callback; 155 on_homepage_search_callback_ = callback;
164 #endif
165 } 156 }
166 157
167 void ChromeRLZTrackerDelegate::Observe( 158 void ChromeRLZTrackerDelegate::Observe(
168 int type, 159 int type,
169 const content::NotificationSource& source, 160 const content::NotificationSource& source,
170 const content::NotificationDetails& details) { 161 const content::NotificationDetails& details) {
171 using std::swap; 162 using std::swap;
172 base::Closure callback_to_run; 163 base::Closure callback_to_run;
173 switch (type) { 164 switch (type) {
174 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: 165 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
175 // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than 166 // In M-36, we made NOTIFICATION_OMNIBOX_OPENED_URL fire more often than
176 // it did previously. The RLZ folks want RLZ's "first search" detection 167 // it did previously. The RLZ folks want RLZ's "first search" detection
177 // to remain as unaffected as possible by this change. This test is 168 // to remain as unaffected as possible by this change. This test is
178 // there to keep the old behavior. 169 // there to keep the old behavior.
179 if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open) 170 if (!content::Details<OmniboxLog>(details).ptr()->is_popup_open)
180 break; 171 break;
181 registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, 172 registrar_.Remove(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
182 content::NotificationService::AllSources()); 173 content::NotificationService::AllSources());
183 swap(callback_to_run, on_omnibox_search_callback_); 174 swap(callback_to_run, on_omnibox_search_callback_);
184 break; 175 break;
185 176
186 #if !defined(OS_IOS)
187 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { 177 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: {
188 // Firstly check if it is a Google search. 178 // Firstly check if it is a Google search.
189 content::LoadCommittedDetails* load_details = 179 content::LoadCommittedDetails* load_details =
190 content::Details<content::LoadCommittedDetails>(details).ptr(); 180 content::Details<content::LoadCommittedDetails>(details).ptr();
191 if (load_details == nullptr) 181 if (load_details == nullptr)
192 break; 182 break;
193 183
194 content::NavigationEntry* entry = load_details->entry; 184 content::NavigationEntry* entry = load_details->entry;
195 if (entry == nullptr) 185 if (entry == nullptr)
196 break; 186 break;
(...skipping 20 matching lines...) Expand all
217 if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) && 207 if (google_util::IsGoogleHomePageUrl(previous_entry->GetURL()) &&
218 ((previous_entry->GetTransitionType() & 208 ((previous_entry->GetTransitionType() &
219 ui::PAGE_TRANSITION_HOME_PAGE) != 0)) { 209 ui::PAGE_TRANSITION_HOME_PAGE) != 0)) {
220 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 210 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
221 content::NotificationService::AllSources()); 211 content::NotificationService::AllSources());
222 swap(callback_to_run, on_homepage_search_callback_); 212 swap(callback_to_run, on_homepage_search_callback_);
223 } 213 }
224 } 214 }
225 break; 215 break;
226 } 216 }
227 #endif // !defined(OS_IOS)
228 217
229 default: 218 default:
230 NOTREACHED(); 219 NOTREACHED();
231 break; 220 break;
232 } 221 }
233 222
234 if (!callback_to_run.is_null()) 223 if (!callback_to_run.is_null())
235 callback_to_run.Run(); 224 callback_to_run.Run();
236 } 225 }
OLDNEW
« no previous file with comments | « chrome/browser/rlz/chrome_rlz_tracker_delegate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698