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