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/shell_integration.h" | 5 #include "chrome/browser/shell_integration.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlwapi.h> | 8 #include <shlwapi.h> |
| 9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
| 10 #include <propkey.h> // Needs to come after shobjidl.h. | 10 #include <propkey.h> // Needs to come after shobjidl.h. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 #include "components/variations/variations_associated_data.h" | 49 #include "components/variations/variations_associated_data.h" |
| 50 #include "content/public/browser/browser_thread.h" | 50 #include "content/public/browser/browser_thread.h" |
| 51 | 51 |
| 52 using content::BrowserThread; | 52 using content::BrowserThread; |
| 53 | 53 |
| 54 namespace { | 54 namespace { |
| 55 | 55 |
| 56 const wchar_t kAppListAppNameSuffix[] = L"AppList"; | 56 const wchar_t kAppListAppNameSuffix[] = L"AppList"; |
| 57 | 57 |
| 58 const char kAsyncSetAsDefaultExperimentName[] = "AsyncSetAsDefault"; | 58 const char kAsyncSetAsDefaultExperimentName[] = "AsyncSetAsDefault"; |
| 59 // One of the group name for the AsynSetAsDefault experiment. This group disable | |
| 60 // the default browser choice reset for the async flow. The other enabled group | |
| 61 // is "EnabledFull" where the default browser choice is reset. | |
|
gab
2016/01/12 01:09:04
// One of the group names for the AsyncSetAsDefaul
Patrick Monette
2016/01/12 01:22:03
I like it.
| |
| 62 const char kEnabledNoRegistryGroupName[] = "EnabledNoRegistry"; | |
|
gab
2016/01/12 01:09:04
kAsyncSetAsDefaultExperimentEnabledNoRegistryGroup
gab
2016/01/12 01:09:04
Also add
// A prefix shared by multiple groups t
Patrick Monette
2016/01/12 01:22:03
Done.
| |
| 59 const char kEnableAsyncSetAsDefault[] = "enable-async-set-as-default"; | 63 const char kEnableAsyncSetAsDefault[] = "enable-async-set-as-default"; |
| 60 const char kDisableAsyncSetAsDefault[] = "disable-async-set-as-default"; | 64 const char kDisableAsyncSetAsDefault[] = "disable-async-set-as-default"; |
| 61 | 65 |
| 62 // Helper function for ShellIntegration::GetAppId to generates profile id | 66 // Helper function for ShellIntegration::GetAppId to generates profile id |
| 63 // from profile path. "profile_id" is composed of sanitized basenames of | 67 // from profile path. "profile_id" is composed of sanitized basenames of |
| 64 // user data dir and profile dir joined by a ".". | 68 // user data dir and profile dir joined by a ".". |
| 65 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { | 69 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
| 66 // Return empty string if profile_path is empty | 70 // Return empty string if profile_path is empty |
| 67 if (profile_path.empty()) | 71 if (profile_path.empty()) |
| 68 return base::string16(); | 72 return base::string16(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 } | 276 } |
| 273 } | 277 } |
| 274 | 278 |
| 275 // Returns true if the AsyncSetAsDefault field trial is activated. | 279 // Returns true if the AsyncSetAsDefault field trial is activated. |
| 276 bool IsAsyncSetAsDefaultEnabled() { | 280 bool IsAsyncSetAsDefaultEnabled() { |
| 277 using base::CommandLine; | 281 using base::CommandLine; |
| 278 | 282 |
| 279 // Note: It's important to query the field trial state first, to ensure that | 283 // Note: It's important to query the field trial state first, to ensure that |
| 280 // UMA reports the correct group. | 284 // UMA reports the correct group. |
| 281 const std::string group_name = | 285 const std::string group_name = |
| 282 base::FieldTrialList::FindFullName("AsyncSetAsDefault"); | 286 base::FieldTrialList::FindFullName(kAsyncSetAsDefaultExperimentName); |
| 283 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault)) | 287 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault)) |
| 284 return false; | 288 return false; |
| 285 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault)) | 289 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault)) |
| 286 return true; | 290 return true; |
| 287 | 291 |
| 288 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | 292 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); |
| 289 } | 293 } |
| 290 | 294 |
| 291 bool RegisterBrowser() { | 295 bool RegisterBrowser() { |
| 292 base::FilePath chrome_exe; | 296 base::FilePath chrome_exe; |
| 293 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 297 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 294 NOTREACHED() << "Error getting app exe path"; | 298 NOTREACHED() << "Error getting app exe path"; |
| 295 return false; | 299 return false; |
| 296 } | 300 } |
| 297 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 301 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 298 | 302 |
| 299 return ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), | 303 return ShellUtil::RegisterChromeBrowser(dist, chrome_exe, base::string16(), |
| 300 true); | 304 true); |
| 301 } | 305 } |
| 302 | 306 |
| 307 // Returns true if the default browser choice should be reset for the current | |
| 308 // user. | |
| 309 bool ShouldResetDefaultBrowser() { | |
|
gab
2016/01/12 01:09:04
Put this below IsAsyncSetAsDefaultEnabled() to kee
Patrick Monette
2016/01/12 01:22:03
Done.
| |
| 310 return !base::StartsWith( | |
| 311 base::FieldTrialList::FindFullName(kAsyncSetAsDefaultExperimentName), | |
| 312 kEnabledNoRegistryGroupName, base::CompareCase::SENSITIVE); | |
| 313 } | |
| 314 | |
| 303 } // namespace | 315 } // namespace |
| 304 | 316 |
| 305 // static | 317 // static |
| 306 bool ShellIntegration::IsSetAsDefaultAsynchronous() { | 318 bool ShellIntegration::IsSetAsDefaultAsynchronous() { |
| 307 return base::win::GetVersion() >= base::win::VERSION_WIN10 && | 319 return base::win::GetVersion() >= base::win::VERSION_WIN10 && |
| 308 IsAsyncSetAsDefaultEnabled(); | 320 IsAsyncSetAsDefaultEnabled(); |
| 309 } | 321 } |
| 310 | 322 |
| 311 bool ShellIntegration::SetAsDefaultBrowser() { | 323 bool ShellIntegration::SetAsDefaultBrowser() { |
| 312 base::FilePath chrome_exe; | 324 base::FilePath chrome_exe; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 | 725 |
| 714 // static | 726 // static |
| 715 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() { | 727 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() { |
| 716 DCHECK(IsSetAsDefaultAsynchronous()); | 728 DCHECK(IsSetAsDefaultAsynchronous()); |
| 717 | 729 |
| 718 // Registers chrome.exe as a browser on Windows to make sure it will be shown | 730 // Registers chrome.exe as a browser on Windows to make sure it will be shown |
| 719 // in the "How would you like to open this?" prompt. | 731 // in the "How would you like to open this?" prompt. |
| 720 if (!RegisterBrowser()) | 732 if (!RegisterBrowser()) |
| 721 return false; | 733 return false; |
| 722 | 734 |
| 723 ResetDefaultBrowser(); | 735 if (ShouldResetDefaultBrowser()) |
| 736 ResetDefaultBrowser(); | |
| 724 | 737 |
| 725 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); | 738 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); |
| 726 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); | 739 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); |
| 727 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); | 740 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); |
| 728 } | 741 } |
| OLD | NEW |