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

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: 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",
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.
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:
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(nullptr, 191 new shell_integration::DefaultBrowserWorker(nullptr,
184 /*delete_observer=*/false)) 192 /*delete_observer=*/false))
185 ->StartSetAsDefault(); 193 ->StartSetAsDefault();
186 return true; 194 return true;
187 } 195 }
188 196
189 bool DefaultBrowserInfoBarDelegate::Cancel() {
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 // A shell_integration::DefaultWebClientObserver that handles the check to 197 // A shell_integration::DefaultWebClientObserver that handles the check to
202 // determine whether or not to show the default browser prompt. If Chrome is the 198 // determine whether or not to show the default browser prompt. If Chrome is the
203 // default browser, then the kCheckDefaultBrowser pref is reset. Otherwise, the 199 // default browser, then the kDefaultBrowserLastDismissed pref is reset.
204 // prompt is shown. 200 // Otherwise, the prompt is shown.
205 class CheckDefaultBrowserObserver 201 class CheckDefaultBrowserObserver
206 : public shell_integration::DefaultWebClientObserver { 202 : public shell_integration::DefaultWebClientObserver {
207 public: 203 public:
208 CheckDefaultBrowserObserver(const base::FilePath& profile_path, 204 CheckDefaultBrowserObserver(const base::FilePath& profile_path,
209 bool show_prompt); 205 bool show_prompt);
210 ~CheckDefaultBrowserObserver() override; 206 ~CheckDefaultBrowserObserver() override;
211 207
212 private: 208 private:
213 void SetDefaultWebClientUIState( 209 void SetDefaultWebClientUIState(
214 shell_integration::DefaultWebClientUIState state) override; 210 shell_integration::DefaultWebClientUIState state) override;
215 211
216 void ResetCheckDefaultBrowserPref(); 212 void ResetCheckDefaultBrowserPref();
217 void ShowPrompt(); 213 void ShowPrompt();
218 214
219 // The path to the profile for which the prompt is to be shown. 215 // The path to the profile for which the prompt is to be shown.
220 base::FilePath profile_path_; 216 base::FilePath profile_path_;
221 217
222 // True if the prompt is to be shown if Chrome is not the default browser. 218 // True if the prompt is to be shown if Chrome is not the default browser.
223 bool show_prompt_; 219 bool show_prompt_;
224 220
225 DISALLOW_COPY_AND_ASSIGN(CheckDefaultBrowserObserver); 221 DISALLOW_COPY_AND_ASSIGN(CheckDefaultBrowserObserver);
226 }; 222 };
227 223
228 CheckDefaultBrowserObserver::CheckDefaultBrowserObserver( 224 CheckDefaultBrowserObserver::CheckDefaultBrowserObserver(
229 const base::FilePath& profile_path, 225 const base::FilePath& profile_path,
230 bool show_prompt) 226 bool show_prompt)
231 : profile_path_(profile_path), show_prompt_(show_prompt) {} 227 : profile_path_(profile_path), show_prompt_(show_prompt) {}
232 228
233 CheckDefaultBrowserObserver::~CheckDefaultBrowserObserver() {} 229 CheckDefaultBrowserObserver::~CheckDefaultBrowserObserver() = default;
234 230
235 void CheckDefaultBrowserObserver::SetDefaultWebClientUIState( 231 void CheckDefaultBrowserObserver::SetDefaultWebClientUIState(
236 shell_integration::DefaultWebClientUIState state) { 232 shell_integration::DefaultWebClientUIState state) {
237 if (state == shell_integration::STATE_IS_DEFAULT) { 233 if (state == shell_integration::STATE_IS_DEFAULT) {
238 // Notify the user in the future if Chrome ceases to be the user's chosen 234 // Notify the user in the future if Chrome ceases to be the user's chosen
239 // default browser. 235 // default browser.
240 ResetCheckDefaultBrowserPref(); 236 ResetCheckDefaultBrowserPref();
241 } else if (show_prompt_ && state == shell_integration::STATE_NOT_DEFAULT && 237 } else if (show_prompt_ && state == shell_integration::STATE_NOT_DEFAULT &&
242 shell_integration::CanSetAsDefaultBrowser() != 238 shell_integration::CanSetAsDefaultBrowser() !=
243 shell_integration::SET_DEFAULT_NOT_ALLOWED) { 239 shell_integration::SET_DEFAULT_NOT_ALLOWED) {
244 ShowPrompt(); 240 ShowPrompt();
245 } 241 }
246 } 242 }
247 243
248 void CheckDefaultBrowserObserver::ResetCheckDefaultBrowserPref() { 244 void CheckDefaultBrowserObserver::ResetCheckDefaultBrowserPref() {
249 Profile* profile = 245 Profile* profile =
250 g_browser_process->profile_manager()->GetProfileByPath(profile_path_); 246 g_browser_process->profile_manager()->GetProfileByPath(profile_path_);
251 if (profile) 247 if (profile)
252 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); 248 chrome::ResetDefaultBrowserPrompt(profile);
253 } 249 }
254 250
255 void CheckDefaultBrowserObserver::ShowPrompt() { 251 void CheckDefaultBrowserObserver::ShowPrompt() {
256 Browser* browser = chrome::FindLastActive(); 252 Browser* browser = chrome::FindLastActive();
257 if (!browser) 253 if (!browser)
258 return; // Reached during ui tests. 254 return; // Reached during ui tests.
259 255
260 // In ChromeBot tests, there might be a race. This line appears to get 256 // In ChromeBot tests, there might be a race. This line appears to get
261 // called during shutdown and |tab| can be NULL. 257 // called during shutdown and |tab| can be NULL.
262 content::WebContents* web_contents = 258 content::WebContents* web_contents =
263 browser->tab_strip_model()->GetActiveWebContents(); 259 browser->tab_strip_model()->GetActiveWebContents();
264 if (!web_contents) 260 if (!web_contents)
265 return; 261 return;
266 262
267 DefaultBrowserInfoBarDelegate::Create( 263 DefaultBrowserInfoBarDelegate::Create(
268 InfoBarService::FromWebContents(web_contents), 264 InfoBarService::FromWebContents(web_contents), browser->profile());
269 Profile::FromBrowserContext(web_contents->GetBrowserContext()) 265 }
270 ->GetPrefs()); 266
267 // Returns true if the default browser prompt should be shown if Chrome is not
268 // the user's default browser.
269 bool ShouldShowDefaultBrowserPrompt(Profile* profile) {
270 // Do not prompt if the prompt period has yet to pass since the user
271 // previously dismissed the infobar.
272 int64_t last_dismissed_value =
273 profile->GetPrefs()->GetInt64(prefs::kDefaultBrowserLastDismissed);
274 if (last_dismissed_value) {
275 if (!base::FeatureList::IsEnabled(kInfobarRefreshFeature))
276 return false; // The refresh feature is not enabled.
277 int period_days = 0;
278 base::StringToInt(variations::GetVariationParamValue(
279 "DefaultBrowserInfobarRefresh", "PeriodDays"),
280 &period_days);
281 if (period_days <= 0 || period_days == std::numeric_limits<int>::max())
282 return false; // Failed to parse a reasonable period.
283 base::Time show_on_or_after =
284 base::Time::FromInternalValue(last_dismissed_value) +
285 base::TimeDelta::FromDays(period_days);
286 if (base::Time::Now() < show_on_or_after)
287 return false;
288 }
289
290 // Do not show the prompt if the "suppress_default_browser_prompt_for_version"
291 // master preference is set to the current version.
292 const std::string disable_version_string =
rkaplow 2016/03/07 16:10:40 don't think this is a big deal but should this che
grt (UTC plus 2) 2016/03/07 18:41:10 moved check above the above check. :-) thanks!
293 g_browser_process->local_state()->GetString(
294 prefs::kBrowserSuppressDefaultBrowserPrompt);
295 const Version disable_version(disable_version_string);
296 DCHECK(disable_version_string.empty() || disable_version.IsValid());
297 if (disable_version.IsValid() &&
298 disable_version == Version(version_info::GetVersionNumber())) {
299 return false;
300 }
301
302 return true;
271 } 303 }
272 304
273 } // namespace 305 } // namespace
274 306
275 namespace chrome { 307 namespace chrome {
276 308
277 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) { 309 void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) {
278 registry->RegisterStringPref( 310 registry->RegisterStringPref(
279 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string()); 311 prefs::kBrowserSuppressDefaultBrowserPrompt, std::string());
280 } 312 }
281 313
282 void ShowDefaultBrowserPrompt(Profile* profile) { 314 void ShowDefaultBrowserPrompt(Profile* profile) {
283 // Do not check if Chrome is the default browser if there is a policy in 315 // Do not check if Chrome is the default browser if there is a policy in
284 // control of this setting. 316 // control of this setting.
285 if (g_browser_process->local_state()->IsManagedPreference( 317 if (g_browser_process->local_state()->IsManagedPreference(
286 prefs::kDefaultBrowserSettingEnabled)) { 318 prefs::kDefaultBrowserSettingEnabled)) {
287 // Handling of the browser.default_browser_setting_enabled policy setting is 319 // Handling of the browser.default_browser_setting_enabled policy setting is
288 // taken care of in BrowserProcessImpl. 320 // taken care of in BrowserProcessImpl.
289 return; 321 return;
290 } 322 }
291 323
292 PrefService* prefs = profile->GetPrefs(); 324 PrefService* prefs = profile->GetPrefs();
293 // Reset preferences if kResetCheckDefaultBrowser is true. 325 // Reset preferences if kResetCheckDefaultBrowser is true.
294 if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) { 326 if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) {
295 prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false); 327 prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false);
296 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); 328 ResetDefaultBrowserPrompt(profile);
297 }
298
299 // Check if Chrome is the default browser but do not prompt if:
300 // - The user said "don't ask me again" on the infobar earlier.
301 // - The "suppress_default_browser_prompt_for_version" master preference is
302 // set to the current version.
303 bool show_prompt = prefs->GetBoolean(prefs::kCheckDefaultBrowser);
304 if (show_prompt) {
305 const std::string disable_version_string =
306 g_browser_process->local_state()->GetString(
307 prefs::kBrowserSuppressDefaultBrowserPrompt);
308 const Version disable_version(disable_version_string);
309 DCHECK(disable_version_string.empty() || disable_version.IsValid());
310 if (disable_version.IsValid() &&
311 disable_version == Version(version_info::GetVersionNumber())) {
312 show_prompt = false;
313 }
314 } 329 }
315 330
316 scoped_refptr<shell_integration::DefaultBrowserWorker>( 331 scoped_refptr<shell_integration::DefaultBrowserWorker>(
317 new shell_integration::DefaultBrowserWorker( 332 new shell_integration::DefaultBrowserWorker(
318 new CheckDefaultBrowserObserver(profile->GetPath(), show_prompt), 333 new CheckDefaultBrowserObserver(
334 profile->GetPath(), ShouldShowDefaultBrowserPrompt(profile)),
319 /*delete_observer=*/true)) 335 /*delete_observer=*/true))
320 ->StartCheckIsDefault(); 336 ->StartCheckIsDefault();
321 } 337 }
322 338
339 void MarkDefaultBrowserPromptAsDismissed(Profile* profile) {
340 DCHECK(profile);
341 profile->GetPrefs()->SetInt64(prefs::kDefaultBrowserLastDismissed,
342 base::Time::Now().ToInternalValue());
343 }
344
345 void ResetDefaultBrowserPrompt(Profile* profile) {
346 DCHECK(profile);
347 profile->GetPrefs()->ClearPref(prefs::kDefaultBrowserLastDismissed);
348 }
349
323 #if !defined(OS_WIN) 350 #if !defined(OS_WIN)
324 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { 351 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) {
325 return false; 352 return false;
326 } 353 }
327 #endif 354 #endif
328 355
329 } // namespace chrome 356 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/startup/default_browser_prompt.h ('k') | chrome/browser/ui/webui/options/browser_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698