Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 } | 170 } |
| 171 | 171 |
| 172 bool DefaultBrowserInfoBarDelegate::Accept() { | 172 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 173 action_taken_ = true; | 173 action_taken_ = true; |
| 174 content::RecordAction( | 174 content::RecordAction( |
| 175 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); | 175 base::UserMetricsAction("DefaultBrowserInfoBar_Accept")); |
| 176 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 176 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 177 InfoBarUserInteraction::START_SET_AS_DEFAULT, | 177 InfoBarUserInteraction::START_SET_AS_DEFAULT, |
| 178 NUM_INFO_BAR_USER_INTERACTION_TYPES); | 178 NUM_INFO_BAR_USER_INTERACTION_TYPES); |
| 179 scoped_refptr<shell_integration::DefaultBrowserWorker>( | 179 scoped_refptr<shell_integration::DefaultBrowserWorker>( |
| 180 new shell_integration::DefaultBrowserWorker(nullptr)) | 180 new shell_integration::DefaultBrowserWorker(nullptr, |
| 181 /*delete_observer=*/false)) | |
|
Nico
2016/02/10 17:33:58
ditto
Patrick Monette
2016/02/10 20:44:42
Done.
| |
| 181 ->StartSetAsDefault(); | 182 ->StartSetAsDefault(); |
| 182 return true; | 183 return true; |
| 183 } | 184 } |
| 184 | 185 |
| 185 bool DefaultBrowserInfoBarDelegate::Cancel() { | 186 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 186 action_taken_ = true; | 187 action_taken_ = true; |
| 187 content::RecordAction( | 188 content::RecordAction( |
| 188 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain")); | 189 base::UserMetricsAction("DefaultBrowserInfoBar_DontAskAgain")); |
| 189 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", | 190 UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction", |
| 190 InfoBarUserInteraction::DONT_ASK_AGAIN, | 191 InfoBarUserInteraction::DONT_ASK_AGAIN, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 202 : public shell_integration::DefaultWebClientObserver { | 203 : public shell_integration::DefaultWebClientObserver { |
| 203 public: | 204 public: |
| 204 CheckDefaultBrowserObserver(const base::FilePath& profile_path, | 205 CheckDefaultBrowserObserver(const base::FilePath& profile_path, |
| 205 bool show_prompt, | 206 bool show_prompt, |
| 206 chrome::HostDesktopType desktop_type); | 207 chrome::HostDesktopType desktop_type); |
| 207 ~CheckDefaultBrowserObserver() override; | 208 ~CheckDefaultBrowserObserver() override; |
| 208 | 209 |
| 209 private: | 210 private: |
| 210 void SetDefaultWebClientUIState( | 211 void SetDefaultWebClientUIState( |
| 211 shell_integration::DefaultWebClientUIState state) override; | 212 shell_integration::DefaultWebClientUIState state) override; |
| 212 bool IsOwnedByWorker() override; | |
| 213 | 213 |
| 214 void ResetCheckDefaultBrowserPref(); | 214 void ResetCheckDefaultBrowserPref(); |
| 215 void ShowPrompt(); | 215 void ShowPrompt(); |
| 216 | 216 |
| 217 // The path to the profile for which the prompt is to be shown. | 217 // The path to the profile for which the prompt is to be shown. |
| 218 base::FilePath profile_path_; | 218 base::FilePath profile_path_; |
| 219 | 219 |
| 220 // True if the prompt is to be shown if Chrome is not the default browser. | 220 // True if the prompt is to be shown if Chrome is not the default browser. |
| 221 bool show_prompt_; | 221 bool show_prompt_; |
| 222 chrome::HostDesktopType desktop_type_; | 222 chrome::HostDesktopType desktop_type_; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 240 // Notify the user in the future if Chrome ceases to be the user's chosen | 240 // Notify the user in the future if Chrome ceases to be the user's chosen |
| 241 // default browser. | 241 // default browser. |
| 242 ResetCheckDefaultBrowserPref(); | 242 ResetCheckDefaultBrowserPref(); |
| 243 } else if (show_prompt_ && state == shell_integration::STATE_NOT_DEFAULT && | 243 } else if (show_prompt_ && state == shell_integration::STATE_NOT_DEFAULT && |
| 244 shell_integration::CanSetAsDefaultBrowser() != | 244 shell_integration::CanSetAsDefaultBrowser() != |
| 245 shell_integration::SET_DEFAULT_NOT_ALLOWED) { | 245 shell_integration::SET_DEFAULT_NOT_ALLOWED) { |
| 246 ShowPrompt(); | 246 ShowPrompt(); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 bool CheckDefaultBrowserObserver::IsOwnedByWorker() { | |
| 251 // Instruct the DefaultBrowserWorker to delete this instance when it is done. | |
| 252 return true; | |
| 253 } | |
| 254 | |
| 255 void CheckDefaultBrowserObserver::ResetCheckDefaultBrowserPref() { | 250 void CheckDefaultBrowserObserver::ResetCheckDefaultBrowserPref() { |
| 256 Profile* profile = | 251 Profile* profile = |
| 257 g_browser_process->profile_manager()->GetProfileByPath(profile_path_); | 252 g_browser_process->profile_manager()->GetProfileByPath(profile_path_); |
| 258 if (profile) | 253 if (profile) |
| 259 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); | 254 profile->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); |
| 260 } | 255 } |
| 261 | 256 |
| 262 void CheckDefaultBrowserObserver::ShowPrompt() { | 257 void CheckDefaultBrowserObserver::ShowPrompt() { |
| 263 Browser* browser = chrome::FindLastActive(); | 258 Browser* browser = chrome::FindLastActive(); |
| 264 if (!browser) | 259 if (!browser) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 DCHECK(disable_version_string.empty() || disable_version.IsValid()); | 311 DCHECK(disable_version_string.empty() || disable_version.IsValid()); |
| 317 if (disable_version.IsValid() && | 312 if (disable_version.IsValid() && |
| 318 disable_version == Version(version_info::GetVersionNumber())) { | 313 disable_version == Version(version_info::GetVersionNumber())) { |
| 319 show_prompt = false; | 314 show_prompt = false; |
| 320 } | 315 } |
| 321 } | 316 } |
| 322 | 317 |
| 323 scoped_refptr<shell_integration::DefaultBrowserWorker>( | 318 scoped_refptr<shell_integration::DefaultBrowserWorker>( |
| 324 new shell_integration::DefaultBrowserWorker( | 319 new shell_integration::DefaultBrowserWorker( |
| 325 new CheckDefaultBrowserObserver(profile->GetPath(), show_prompt, | 320 new CheckDefaultBrowserObserver(profile->GetPath(), show_prompt, |
| 326 desktop_type))) | 321 desktop_type), |
| 322 /*delete_observer=*/true)) | |
| 327 ->StartCheckIsDefault(); | 323 ->StartCheckIsDefault(); |
| 328 } | 324 } |
| 329 | 325 |
| 330 #if !defined(OS_WIN) | 326 #if !defined(OS_WIN) |
| 331 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { | 327 bool ShowFirstRunDefaultBrowserPrompt(Profile* profile) { |
| 332 return false; | 328 return false; |
| 333 } | 329 } |
| 334 #endif | 330 #endif |
| 335 | 331 |
| 336 } // namespace chrome | 332 } // namespace chrome |
| OLD | NEW |