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 // A prefix shared by multiple groups that kicks off the generic set-as-default | |
gab
2016/01/12 01:26:46
nit: I guess for consistency s/set-as-default/Asyn
Patrick Monette
2016/01/12 01:29:33
Done.
| |
60 // experiment. | |
61 const char kAsyncSetAsDefaultExperimentEnabledGroupPrefix[] = "Enabled"; | |
62 // One of the group names for the AsyncSetAsDefault experiment. Unlike other | |
63 // "Enabled" groups, this group doesn't reset the current default browser choice | |
64 // in the registry. | |
65 const char kAsyncSetAsDefaultExperimentEnabledNoRegistryGroupName[] = | |
66 "EnabledNoRegistry"; | |
67 | |
59 const char kEnableAsyncSetAsDefault[] = "enable-async-set-as-default"; | 68 const char kEnableAsyncSetAsDefault[] = "enable-async-set-as-default"; |
60 const char kDisableAsyncSetAsDefault[] = "disable-async-set-as-default"; | 69 const char kDisableAsyncSetAsDefault[] = "disable-async-set-as-default"; |
61 | 70 |
62 // Helper function for ShellIntegration::GetAppId to generates profile id | 71 // Helper function for ShellIntegration::GetAppId to generates profile id |
63 // from profile path. "profile_id" is composed of sanitized basenames of | 72 // from profile path. "profile_id" is composed of sanitized basenames of |
64 // user data dir and profile dir joined by a ".". | 73 // user data dir and profile dir joined by a ".". |
65 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { | 74 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
66 // Return empty string if profile_path is empty | 75 // Return empty string if profile_path is empty |
67 if (profile_path.empty()) | 76 if (profile_path.empty()) |
68 return base::string16(); | 77 return base::string16(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 } | 281 } |
273 } | 282 } |
274 | 283 |
275 // Returns true if the AsyncSetAsDefault field trial is activated. | 284 // Returns true if the AsyncSetAsDefault field trial is activated. |
276 bool IsAsyncSetAsDefaultEnabled() { | 285 bool IsAsyncSetAsDefaultEnabled() { |
277 using base::CommandLine; | 286 using base::CommandLine; |
278 | 287 |
279 // Note: It's important to query the field trial state first, to ensure that | 288 // Note: It's important to query the field trial state first, to ensure that |
280 // UMA reports the correct group. | 289 // UMA reports the correct group. |
281 const std::string group_name = | 290 const std::string group_name = |
282 base::FieldTrialList::FindFullName("AsyncSetAsDefault"); | 291 base::FieldTrialList::FindFullName(kAsyncSetAsDefaultExperimentName); |
283 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault)) | 292 if (CommandLine::ForCurrentProcess()->HasSwitch(kDisableAsyncSetAsDefault)) |
284 return false; | 293 return false; |
285 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault)) | 294 if (CommandLine::ForCurrentProcess()->HasSwitch(kEnableAsyncSetAsDefault)) |
286 return true; | 295 return true; |
287 | 296 |
288 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | 297 return base::StartsWith(group_name, |
298 kAsyncSetAsDefaultExperimentEnabledGroupPrefix, | |
299 base::CompareCase::SENSITIVE); | |
300 } | |
301 | |
302 // Returns true if the default browser choice should be reset for the current | |
303 // user. | |
304 bool ShouldResetDefaultBrowser() { | |
305 return !base::StartsWith( | |
306 base::FieldTrialList::FindFullName(kAsyncSetAsDefaultExperimentName), | |
307 kAsyncSetAsDefaultExperimentEnabledNoRegistryGroupName, | |
308 base::CompareCase::SENSITIVE); | |
289 } | 309 } |
290 | 310 |
291 bool RegisterBrowser() { | 311 bool RegisterBrowser() { |
292 base::FilePath chrome_exe; | 312 base::FilePath chrome_exe; |
293 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 313 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
294 NOTREACHED() << "Error getting app exe path"; | 314 NOTREACHED() << "Error getting app exe path"; |
295 return false; | 315 return false; |
296 } | 316 } |
297 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 317 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
298 | 318 |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 733 |
714 // static | 734 // static |
715 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() { | 735 bool ShellIntegration::DefaultBrowserWorker::SetAsDefaultBrowserAsynchronous() { |
716 DCHECK(IsSetAsDefaultAsynchronous()); | 736 DCHECK(IsSetAsDefaultAsynchronous()); |
717 | 737 |
718 // Registers chrome.exe as a browser on Windows to make sure it will be shown | 738 // 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. | 739 // in the "How would you like to open this?" prompt. |
720 if (!RegisterBrowser()) | 740 if (!RegisterBrowser()) |
721 return false; | 741 return false; |
722 | 742 |
723 ResetDefaultBrowser(); | 743 if (ShouldResetDefaultBrowser()) |
744 ResetDefaultBrowser(); | |
724 | 745 |
725 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); | 746 base::CommandLine cmdline(base::FilePath(L"openwith.exe")); |
726 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); | 747 cmdline.AppendArgNative(StartupBrowserCreator::GetDefaultBrowserUrl()); |
727 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); | 748 return base::LaunchProcess(cmdline, base::LaunchOptions()).IsValid(); |
728 } | 749 } |
OLD | NEW |