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

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

Issue 1748773002: Simplify the default browser infobar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync to position 379825 Created 4 years, 9 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/startup/default_browser_prompt.h" 5 #include "chrome/browser/ui/startup/default_browser_prompt.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/feature_list.h"
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
13 #include "base/metrics/user_metrics_action.h" 14 #include "base/metrics/user_metrics_action.h"
14 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h"
15 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "base/time/time.h"
16 #include "base/version.h" 19 #include "base/version.h"
17 #include "build/build_config.h" 20 #include "build/build_config.h"
18 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
20 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
22 #include "chrome/browser/ui/browser.h" 25 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 27 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/pref_names.h" 28 #include "chrome/common/pref_names.h"
26 #include "chrome/grit/chromium_strings.h" 29 #include "chrome/grit/chromium_strings.h"
27 #include "chrome/grit/generated_resources.h" 30 #include "chrome/grit/generated_resources.h"
28 #include "components/infobars/core/confirm_infobar_delegate.h" 31 #include "components/infobars/core/confirm_infobar_delegate.h"
29 #include "components/infobars/core/infobar.h" 32 #include "components/infobars/core/infobar.h"
30 #include "components/prefs/pref_registry_simple.h" 33 #include "components/prefs/pref_registry_simple.h"
31 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "components/variations/variations_associated_data.h"
32 #include "components/version_info/version_info.h" 36 #include "components/version_info/version_info.h"
33 #include "content/public/browser/navigation_details.h" 37 #include "content/public/browser/navigation_details.h"
34 #include "content/public/browser/user_metrics.h" 38 #include "content/public/browser/user_metrics.h"
35 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
36 #include "grit/theme_resources.h" 40 #include "grit/theme_resources.h"
37 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
38 #include "ui/gfx/vector_icons_public.h" 42 #include "ui/gfx/vector_icons_public.h"
39 43
40 namespace { 44 namespace {
41 45
46 const base::Feature kInfobarRefreshFeature{"InfobarRefresh",
msw 2016/03/08 18:01:02 nit: add a comment here? what does infobar refresh
grt (UTC plus 2) 2016/03/11 16:04:31 Done.
47 base::FEATURE_DISABLED_BY_DEFAULT};
48
42 // The delegate for the infobar shown when Chrome is not the default browser. 49 // The delegate for the infobar shown when Chrome is not the default browser.
50 // Ownership of the delegate is given to the infobar itself, the lifetime of
51 // which is bound to the containing WebContents.
43 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { 52 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
44 public: 53 public:
45 // Creates a default browser infobar and delegate and adds the infobar to 54 // Creates a default browser infobar and delegate and adds the infobar to
46 // |infobar_service|. 55 // |infobar_service|.
47 static void Create(InfoBarService* infobar_service, PrefService* prefs); 56 static void Create(InfoBarService* infobar_service, Profile* profile);
48 57
49 private: 58 private:
50 // Possible user interactions with the default browser info bar. 59 // Possible user interactions with the default browser info bar.
51 // Do not modify the ordering as it is important for UMA. 60 // Do not modify the ordering as it is important for UMA.
52 enum InfoBarUserInteraction { 61 enum InfoBarUserInteraction {
53 // The user clicked the "Set as default" button. 62 // The user clicked the "Set as default" button.
54 START_SET_AS_DEFAULT, 63 START_SET_AS_DEFAULT = 0,
55 // The user doesn't want to be reminded again. 64 // Value 1 is deprecated; do not re-use.
msw 2016/03/08 18:01:02 nit: leave context with a comment (eg. "Value 1 (D
grt (UTC plus 2) 2016/03/11 16:04:31 Done.
56 DONT_ASK_AGAIN,
57 // The user did not interact with the info bar. 65 // The user did not interact with the info bar.
58 IGNORE_INFO_BAR, 66 IGNORE_INFO_BAR = 2,
59 NUM_INFO_BAR_USER_INTERACTION_TYPES 67 NUM_INFO_BAR_USER_INTERACTION_TYPES
60 }; 68 };
61 69
62 explicit DefaultBrowserInfoBarDelegate(PrefService* prefs); 70 explicit DefaultBrowserInfoBarDelegate(Profile* profile);
63 ~DefaultBrowserInfoBarDelegate() override; 71 ~DefaultBrowserInfoBarDelegate() override;
64 72
65 void AllowExpiry() { should_expire_ = true; } 73 void AllowExpiry() { should_expire_ = true; }
66 74
75 // InfoBarDelegate:
msw 2016/03/08 18:01:02 I'm not sure why you pulled out some of the InfoBa
grt (UTC plus 2) 2016/03/11 16:04:31 Ah, an oversight. I thought I'd gone through each
76 Type GetInfoBarType() const override;
77 bool ShouldExpire(const NavigationDetails& details) const override;
78 void InfoBarDismissed() override;
79
67 // ConfirmInfoBarDelegate: 80 // ConfirmInfoBarDelegate:
68 Type GetInfoBarType() const override;
69 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; 81 infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
70 int GetIconId() const override; 82 int GetIconId() const override;
71 gfx::VectorIconId GetVectorIconId() const override; 83 gfx::VectorIconId GetVectorIconId() const override;
72 bool ShouldExpire(const NavigationDetails& details) const override;
73 base::string16 GetMessageText() const override; 84 base::string16 GetMessageText() const override;
85 int GetButtons() const override;
74 base::string16 GetButtonLabel(InfoBarButton button) const override; 86 base::string16 GetButtonLabel(InfoBarButton button) const override;
75 bool OKButtonTriggersUACPrompt() const override; 87 bool OKButtonTriggersUACPrompt() const override;
76 bool Accept() override; 88 bool Accept() override;
77 bool Cancel() override;
78 89
79 // The prefs to use. 90 // The WebContents's corresponding profile.
80 PrefService* prefs_; 91 Profile* profile_;
81
82 // Whether the user clicked one of the buttons.
83 bool action_taken_;
84 92
85 // Whether the info-bar should be dismissed on the next navigation. 93 // Whether the info-bar should be dismissed on the next navigation.
86 bool should_expire_; 94 bool should_expire_ = false;
87 95
88 // Used to delay the expiration of the info-bar. 96 // Used to delay the expiration of the info-bar.
89 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; 97 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_;
90 98
91 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); 99 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate);
92 }; 100 };
93 101
94 // static 102 // static
95 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, 103 void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service,
96 PrefService* prefs) { 104 Profile* profile) {
97 infobar_service->AddInfoBar( 105 infobar_service->AddInfoBar(
98 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( 106 infobar_service->CreateConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
99 new DefaultBrowserInfoBarDelegate(prefs)))); 107 new DefaultBrowserInfoBarDelegate(profile))));
100 } 108 }
101 109
102 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(PrefService* prefs) 110 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile)
103 : ConfirmInfoBarDelegate(), 111 : ConfirmInfoBarDelegate(), profile_(profile), weak_factory_(this) {
104 prefs_(prefs),
105 action_taken_(false),
106 should_expire_(false),
107 weak_factory_(this) {
108 // We want the info-bar to stick-around for few seconds and then be hidden 112 // We want the info-bar to stick-around for few seconds and then be hidden
109 // on the next navigation after that. 113 // on the next navigation after that.
110 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 114 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
111 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, 115 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry,
112 weak_factory_.GetWeakPtr()), 116 weak_factory_.GetWeakPtr()),
113 base::TimeDelta::FromSeconds(8)); 117 base::TimeDelta::FromSeconds(8));
114 } 118 }
115 119
116 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { 120 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() = default;
117 if (!action_taken_)
118 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
119 InfoBarUserInteraction::IGNORE_INFO_BAR,
120 NUM_INFO_BAR_USER_INTERACTION_TYPES);
121 }
122 121
123 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType() 122 infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType()
124 const { 123 const {
125 #if defined(OS_WIN) 124 #if defined(OS_WIN)
126 return WARNING_TYPE; 125 return WARNING_TYPE;
127 #else 126 #else
128 return PAGE_ACTION_TYPE; 127 return PAGE_ACTION_TYPE;
129 #endif 128 #endif
130 } 129 }
131 130
131 bool DefaultBrowserInfoBarDelegate::ShouldExpire(
132 const NavigationDetails& details) const {
133 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details);
134 }
135
136 void DefaultBrowserInfoBarDelegate::InfoBarDismissed() {
137 chrome::MarkDefaultBrowserPromptAsDismissed(profile_);
138 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
139 IGNORE_INFO_BAR,
140 NUM_INFO_BAR_USER_INTERACTION_TYPES);
141 }
142
132 infobars::InfoBarDelegate::InfoBarIdentifier 143 infobars::InfoBarDelegate::InfoBarIdentifier
133 DefaultBrowserInfoBarDelegate::GetIdentifier() const { 144 DefaultBrowserInfoBarDelegate::GetIdentifier() const {
134 return DEFAULT_BROWSER_INFOBAR_DELEGATE; 145 return DEFAULT_BROWSER_INFOBAR_DELEGATE;
135 } 146 }
136 147
137 int DefaultBrowserInfoBarDelegate::GetIconId() const { 148 int DefaultBrowserInfoBarDelegate::GetIconId() const {
138 return IDR_PRODUCT_LOGO_32; 149 return IDR_PRODUCT_LOGO_32;
139 } 150 }
140 151
141 gfx::VectorIconId DefaultBrowserInfoBarDelegate::GetVectorIconId() const { 152 gfx::VectorIconId DefaultBrowserInfoBarDelegate::GetVectorIconId() const {
142 #if defined(OS_MACOSX) || defined(OS_ANDROID) 153 #if defined(OS_MACOSX) || defined(OS_ANDROID)
143 return gfx::VectorIconId::VECTOR_ICON_NONE; 154 return gfx::VectorIconId::VECTOR_ICON_NONE;
144 #else 155 #else
145 return gfx::VectorIconId::CHROME_PRODUCT; 156 return gfx::VectorIconId::CHROME_PRODUCT;
146 #endif 157 #endif
147 } 158 }
148 159
149 bool DefaultBrowserInfoBarDelegate::ShouldExpire(
150 const NavigationDetails& details) const {
151 return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details);
152 }
153
154 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { 160 base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const {
155 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); 161 return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT);
156 } 162 }
157 163
164 int DefaultBrowserInfoBarDelegate::GetButtons() const {
165 return BUTTON_OK;
166 }
167
158 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( 168 base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel(
159 InfoBarButton button) const { 169 InfoBarButton button) const {
160 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? 170 DCHECK_EQ(BUTTON_OK, button);
161 IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL : 171 return l10n_util::GetStringUTF16(IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL);
162 IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL);
163 } 172 }
164 173
165 // Setting an app as the default browser doesn't require elevation directly, but 174 // Setting an app as the default browser doesn't require elevation directly, but
166 // it does require registering it as the protocol handler for "http", so if 175 // it does require registering it as the protocol handler for "http", so if
167 // protocol registration in general requires elevation, this does as well. 176 // protocol registration in general requires elevation, this does as well.
168 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const { 177 bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const {
169 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient(); 178 return shell_integration::IsElevationNeededForSettingDefaultProtocolClient();
170 } 179 }
171 180
172 bool DefaultBrowserInfoBarDelegate::Accept() { 181 bool DefaultBrowserInfoBarDelegate::Accept() {
173 action_taken_ = true;
174 content::RecordAction( 182 content::RecordAction(
175 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); 183 base::UserMetricsAction("DefaultBrowserInfoBar_Accept"));
176 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", 184 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
177 InfoBarUserInteraction::START_SET_AS_DEFAULT, 185 START_SET_AS_DEFAULT,
178 NUM_INFO_BAR_USER_INTERACTION_TYPES); 186 NUM_INFO_BAR_USER_INTERACTION_TYPES);
179 // The worker pointer is reference counted. While it is running, the 187 // The worker pointer is reference counted. While it is running, the
180 // message loops of the FILE and UI thread will hold references to it 188 // message loops of the FILE and UI thread will hold references to it
181 // and it will be automatically freed once all its tasks have finished. 189 // and it will be automatically freed once all its tasks have finished.
182 scoped_refptr<shell_integration::DefaultBrowserWorker>( 190 scoped_refptr<shell_integration::DefaultBrowserWorker>(
183 new shell_integration::DefaultBrowserWorker( 191 new shell_integration::DefaultBrowserWorker(
184 shell_integration::DefaultWebClientWorkerCallback())) 192 shell_integration::DefaultWebClientWorkerCallback()))
185 ->StartSetAsDefault(); 193 ->StartSetAsDefault();
186 return true; 194 return true;
187 } 195 }
188 196
189 bool DefaultBrowserInfoBarDelegate::Cancel() {
msw 2016/03/08 18:01:02 I think it's a little odd that we don't offer 'No,
grt (UTC plus 2) 2016/03/11 16:04:31 I discussed this with LaForge, who tells me that t
190 action_taken_ = true;
191 content::RecordAction(
192 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain"));
193 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
194 InfoBarUserInteraction::DONT_ASK_AGAIN,
195 NUM_INFO_BAR_USER_INTERACTION_TYPES);
196 // User clicked "Don't ask me again", remember that.
197 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false);
198 return true;
199 }
200
201 void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) { 197 void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) {
202 Profile* profile = 198 Profile* profile =
203 g_browser_process->profile_manager()->GetProfileByPath(profile_path); 199 g_browser_process->profile_manager()->GetProfileByPath(profile_path);
204 if (profile) 200 if (profile)
205 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); 201 chrome::ResetDefaultBrowserPrompt(profile);
206 } 202 }
207 203
208 void ShowPrompt() { 204 void ShowPrompt() {
209 Browser* browser = chrome::FindLastActive(); 205 Browser* browser = chrome::FindLastActive();
210 if (!browser) 206 if (!browser)
211 return; // Reached during ui tests. 207 return; // Reached during ui tests.
212 208
213 // In ChromeBot tests, there might be a race. This line appears to get 209 // In ChromeBot tests, there might be a race. This line appears to get
214 // called during shutdown and |tab| can be NULL. 210 // called during shutdown and |tab| can be NULL.
215 content::WebContents* web_contents = 211 content::WebContents* web_contents =
216 browser->tab_strip_model()->GetActiveWebContents(); 212 browser->tab_strip_model()->GetActiveWebContents();
217 if (!web_contents) 213 if (!web_contents)
218 return; 214 return;
219 215
220 DefaultBrowserInfoBarDelegate::Create( 216 DefaultBrowserInfoBarDelegate::Create(
221 InfoBarService::FromWebContents(web_contents), 217 InfoBarService::FromWebContents(web_contents), browser->profile());
222 Profile::FromBrowserContext(web_contents->GetBrowserContext()) 218 }
223 ->GetPrefs()); 219
220 // Returns true if the default browser prompt should be shown if Chrome is not
221 // the user's default browser.
222 bool ShouldShowDefaultBrowserPrompt(Profile* profile) {
223 // Do not show the prompt if the "suppress_default_browser_prompt_for_version"
224 // master preference is set to the current version.
225 const std::string disable_version_string =
226 g_browser_process->local_state()->GetString(
227 prefs::kBrowserSuppressDefaultBrowserPrompt);
228 const Version disable_version(disable_version_string);
229 DCHECK(disable_version_string.empty() || disable_version.IsValid());
230 if (disable_version.IsValid() &&
231 disable_version == Version(version_info::GetVersionNumber())) {
232 return false;
233 }
234
235 // Do not show if the prompt period has yet to pass since the user previously
236 // dismissed the infobar.
237 int64_t last_dismissed_value =
238 profile->GetPrefs()->GetInt64(prefs::kDefaultBrowserLastDismissed);
239 if (last_dismissed_value) {
240 if (!base::FeatureList::IsEnabled(kInfobarRefreshFeature))
241 return false; // The refresh feature is not enabled.
242 int period_days = 0;
243 base::StringToInt(variations::GetVariationParamValue(
244 "DefaultBrowserInfobarRefresh", "PeriodDays"),
msw 2016/03/08 18:01:02 Are these usually string literals scattered in cod
grt (UTC plus 2) 2016/03/11 16:04:31 I see both patterns used in the code. My inclinati
msw 2016/03/14 17:21:18 Acknowledged. It's fine as-is.
245 &period_days);
246 if (period_days <= 0 || period_days == std::numeric_limits<int>::max())
247 return false; // Failed to parse a reasonable period.
248 base::Time show_on_or_after =
249 base::Time::FromInternalValue(last_dismissed_value) +
250 base::TimeDelta::FromDays(period_days);
251 if (base::Time::Now() < show_on_or_after)
252 return false;
253 }
254
255 return true;
224 } 256 }
225 257
226 void OnCheckIsDefaultBrowserFinished( 258 void OnCheckIsDefaultBrowserFinished(
227 const base::FilePath& profile_path, 259 const base::FilePath& profile_path,
228 bool show_prompt, 260 bool show_prompt,
229 shell_integration::DefaultWebClientUIState state) { 261 shell_integration::DefaultWebClientUIState state) {
230 if (state == shell_integration::STATE_IS_DEFAULT) { 262 if (state == shell_integration::STATE_IS_DEFAULT) {
231 // Notify the user in the future if Chrome ceases to be the user's chosen 263 // Notify the user in the future if Chrome ceases to be the user's chosen
232 // default browser. 264 // default browser.
233 ResetCheckDefaultBrowserPref(profile_path); 265 ResetCheckDefaultBrowserPref(profile_path);
(...skipping 20 matching lines...) Expand all
254 prefs::kDefaultBrowserSettingEnabled)) { 286 prefs::kDefaultBrowserSettingEnabled)) {
255 // Handling of the browser.default_browser_setting_enabled policy setting is 287 // Handling of the browser.default_browser_setting_enabled policy setting is
256 // taken care of in BrowserProcessImpl. 288 // taken care of in BrowserProcessImpl.
257 return; 289 return;
258 } 290 }
259 291
260 PrefService* prefs = profile->GetPrefs(); 292 PrefService* prefs = profile->GetPrefs();
261 // Reset preferences if kResetCheckDefaultBrowser is true. 293 // Reset preferences if kResetCheckDefaultBrowser is true.
262 if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) { 294 if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) {
263 prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false); 295 prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false);
264 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); 296 ResetDefaultBrowserPrompt(profile);
265 }
266
267 // Check if Chrome is the default browser but do not prompt if:
268 // - The user said "don't ask me again" on the infobar earlier.
269 // - The "suppress_default_browser_prompt_for_version" master preference is
270 // set to the current version.
271 bool show_prompt = prefs->GetBoolean(prefs::kCheckDefaultBrowser);
272 if (show_prompt) {
273 const std::string disable_version_string =
274 g_browser_process->local_state()->GetString(
275 prefs::kBrowserSuppressDefaultBrowserPrompt);
276 const Version disable_version(disable_version_string);
277 DCHECK(disable_version_string.empty() || disable_version.IsValid());
278 if (disable_version.IsValid() &&
279 disable_version == Version(version_info::GetVersionNumber())) {
280 show_prompt = false;
281 }
282 } 297 }
283 298
284 scoped_refptr<shell_integration::DefaultBrowserWorker>( 299 scoped_refptr<shell_integration::DefaultBrowserWorker>(
285 new shell_integration::DefaultBrowserWorker(base::Bind( 300 new shell_integration::DefaultBrowserWorker(
286 &OnCheckIsDefaultBrowserFinished, profile->GetPath(), show_prompt))) 301 base::Bind(&OnCheckIsDefaultBrowserFinished, profile->GetPath(),
302 ShouldShowDefaultBrowserPrompt(profile))))
287 ->StartCheckIsDefault(); 303 ->StartCheckIsDefault();
288 } 304 }
289 305
306 void MarkDefaultBrowserPromptAsDismissed(Profile* profile) {
307 DCHECK(profile);
msw 2016/03/08 18:01:02 nit: dcheck before dereference isn't really needed
grt (UTC plus 2) 2016/03/11 16:04:31 Done.
308 profile->GetPrefs()->SetInt64(prefs::kDefaultBrowserLastDismissed,
309 base::Time::Now().ToInternalValue());
310 }
311
312 void ResetDefaultBrowserPrompt(Profile* profile) {
313 DCHECK(profile);
314 profile->GetPrefs()->ClearPref(prefs::kDefaultBrowserLastDismissed);
315 }
316
290 #if !defined(OS_WIN) 317 #if !defined(OS_WIN)
291 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { 318 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
292 return false; 319 return false;
293 } 320 }
294 #endif 321 #endif
295 322
296 } // namespace chrome 323 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698