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

Side by Side Diff: chrome/browser/ui/startup/default_browser_prompt.cc

Issue 1182513007: Reset browser.check_default_browser to true when Chrome is the user's default browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: msw comments; fix thread bounce Created 5 years, 6 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 | « no previous file | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/startup/default_browser_prompt.h" 5 #include "chrome/browser/ui/startup/default_browser_prompt.h"
6 6
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/version.h" 12 #include "base/version.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/first_run/first_run.h" 14 #include "chrome/browser/first_run/first_run.h"
15 #include "chrome/browser/infobars/infobar_service.h" 15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/shell_integration.h" 18 #include "chrome/browser/shell_integration.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/chrome_version_info.h" 22 #include "chrome/common/chrome_version_info.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/grit/chromium_strings.h" 24 #include "chrome/grit/chromium_strings.h"
24 #include "chrome/grit/generated_resources.h" 25 #include "chrome/grit/generated_resources.h"
25 #include "chrome/installer/util/master_preferences.h" 26 #include "chrome/installer/util/master_preferences.h"
26 #include "chrome/installer/util/master_preferences_constants.h" 27 #include "chrome/installer/util/master_preferences_constants.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 return; 188 return;
188 189
189 DefaultBrowserInfoBarDelegate::Create( 190 DefaultBrowserInfoBarDelegate::Create(
190 InfoBarService::FromWebContents(web_contents), 191 InfoBarService::FromWebContents(web_contents),
191 Profile::FromBrowserContext( 192 Profile::FromBrowserContext(
192 web_contents->GetBrowserContext())->GetPrefs(), 193 web_contents->GetBrowserContext())->GetPrefs(),
193 (ShellIntegration::CanSetAsDefaultBrowser() == 194 (ShellIntegration::CanSetAsDefaultBrowser() ==
194 ShellIntegration::SET_DEFAULT_INTERACTIVE)); 195 ShellIntegration::SET_DEFAULT_INTERACTIVE));
195 } 196 }
196 197
197 void CheckDefaultBrowserCallback(chrome::HostDesktopType desktop_type) { 198 void ResetCheckDefaultBrowserPrefOnUIThread() {
msw 2015/06/16 20:29:49 nit: maybe DCHECK_CURRENTLY_ON(BrowserThread::UI);
grt (UTC plus 2) 2015/06/16 21:04:09 Done.
198 if (ShellIntegration::GetDefaultBrowser() == ShellIntegration::NOT_DEFAULT) { 199 PrefService* prefs = ProfileManager::GetLastUsedProfile()->GetPrefs();
200 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true);
201 }
202
203 void CheckDefaultBrowserOnFileThread(bool show_prompt,
msw 2015/06/16 20:29:49 nit: maybe DCHECK_CURRENTLY_ON(BrowserThread::FILE
grt (UTC plus 2) 2015/06/16 21:04:09 Done.
204 chrome::HostDesktopType desktop_type) {
205 ShellIntegration::DefaultWebClientState state =
206 ShellIntegration::GetDefaultBrowser();
207 if (state == ShellIntegration::IS_DEFAULT) {
208 // Notify the user in the future if Chrome ceases to be the user's chosen
209 // default browser.
210 content::BrowserThread::PostTask(
211 content::BrowserThread::UI, FROM_HERE,
212 base::Bind(&ResetCheckDefaultBrowserPrefOnUIThread));
213 } else if (show_prompt && state == ShellIntegration::NOT_DEFAULT) {
199 ShellIntegration::DefaultWebClientSetPermission default_change_mode = 214 ShellIntegration::DefaultWebClientSetPermission default_change_mode =
200 ShellIntegration::CanSetAsDefaultBrowser(); 215 ShellIntegration::CanSetAsDefaultBrowser();
201 216
202 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) { 217 if (default_change_mode != ShellIntegration::SET_DEFAULT_NOT_ALLOWED) {
203 content::BrowserThread::PostTask( 218 content::BrowserThread::PostTask(
204 content::BrowserThread::UI, FROM_HERE, 219 content::BrowserThread::UI, FROM_HERE,
205 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type)); 220 base::Bind(&NotifyNotDefaultBrowserCallback, desktop_type));
206 } 221 }
207 } 222 }
208 } 223 }
209 224
210 } // namespace 225 } // namespace
211 226
212 namespace chrome { 227 namespace chrome {
213 228
214 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) { 229 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) {
215 registry->RegisterStringPref( 230 registry->RegisterStringPref(
216 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string()); 231 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string());
217 } 232 }
218 233
219 void ShowDefaultBrowserPrompt(Profile* profile, HostDesktopType desktop_type) { 234 void ShowDefaultBrowserPrompt(Profile* profile, HostDesktopType desktop_type) {
220 // We do not check if we are the default browser if: 235 // We do not check if we are the default browser if:
236 // - There is a policy in control of this setting.
237 // We check if we are the default browser but do not prompt if:
221 // - The user said "don't ask me again" on the infobar earlier. 238 // - The user said "don't ask me again" on the infobar earlier.
222 // - There is a policy in control of this setting.
223 // - The "suppress_default_browser_prompt_for_version" master preference is 239 // - The "suppress_default_browser_prompt_for_version" master preference is
224 // set to the current version. 240 // set to the current version.
225 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser)) 241 bool show_prompt =
226 return; 242 profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser);
227 243
228 if (g_browser_process->local_state()->IsManagedPreference( 244 if (g_browser_process->local_state()->IsManagedPreference(
229 prefs::kDefaultBrowserSettingEnabled)) { 245 prefs::kDefaultBrowserSettingEnabled)) {
230 if (g_browser_process->local_state()->GetBoolean( 246 if (g_browser_process->local_state()->GetBoolean(
231 prefs::kDefaultBrowserSettingEnabled)) { 247 prefs::kDefaultBrowserSettingEnabled)) {
232 content::BrowserThread::PostTask( 248 content::BrowserThread::PostTask(
233 content::BrowserThread::FILE, FROM_HERE, 249 content::BrowserThread::FILE, FROM_HERE,
234 base::Bind( 250 base::Bind(
235 base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); 251 base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser)));
236 } else { 252 } else {
237 // TODO(pastarmovj): We can't really do anything meaningful here yet but 253 // TODO(pastarmovj): We can't really do anything meaningful here yet but
238 // just prevent showing the infobar. 254 // just prevent showing the infobar.
239 } 255 }
240 return; 256 return;
241 } 257 }
242 258
243 const std::string disable_version_string = 259 if (show_prompt) {
244 g_browser_process->local_state()->GetString( 260 const std::string disable_version_string =
245 prefs::kBrowserSuppressDefaultBrowserPrompt); 261 g_browser_process->local_state()->GetString(
246 const Version disable_version(disable_version_string); 262 prefs::kBrowserSuppressDefaultBrowserPrompt);
247 DCHECK(disable_version_string.empty() || disable_version.IsValid()); 263 const Version disable_version(disable_version_string);
248 if (disable_version.IsValid()) { 264 DCHECK(disable_version_string.empty() || disable_version.IsValid());
249 const chrome::VersionInfo version_info; 265 if (disable_version.IsValid()) {
250 if (disable_version.Equals(Version(version_info.Version()))) 266 const chrome::VersionInfo version_info;
251 return; 267 if (disable_version.Equals(Version(version_info.Version())))
268 show_prompt = false;
269 }
252 } 270 }
253 271
254 content::BrowserThread::PostTask( 272 content::BrowserThread::PostTask(
255 content::BrowserThread::FILE, FROM_HERE, 273 content::BrowserThread::FILE, FROM_HERE,
256 base::Bind(&CheckDefaultBrowserCallback, desktop_type)); 274 base::Bind(&CheckDefaultBrowserOnFileThread, show_prompt, desktop_type));
257 } 275 }
258 276
259 #if !defined(OS_WIN) 277 #if !defined(OS_WIN)
260 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { 278 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
261 return false; 279 return false;
262 } 280 }
263 #endif 281 #endif
264 282
265 } // namespace chrome 283 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698