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_win.h" | 5 #include "chrome/browser/shell_integration_win.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 25 matching lines...) Expand all Loading... | |
| 36 #include "base/win/scoped_propvariant.h" | 36 #include "base/win/scoped_propvariant.h" |
| 37 #include "base/win/shortcut.h" | 37 #include "base/win/shortcut.h" |
| 38 #include "base/win/windows_version.h" | 38 #include "base/win/windows_version.h" |
| 39 #include "chrome/browser/policy/policy_path_parser.h" | 39 #include "chrome/browser/policy/policy_path_parser.h" |
| 40 #include "chrome/browser/shell_integration.h" | 40 #include "chrome/browser/shell_integration.h" |
| 41 #include "chrome/browser/web_applications/web_app.h" | 41 #include "chrome/browser/web_applications/web_app.h" |
| 42 #include "chrome/browser/win/settings_app_monitor.h" | 42 #include "chrome/browser/win/settings_app_monitor.h" |
| 43 #include "chrome/common/chrome_constants.h" | 43 #include "chrome/common/chrome_constants.h" |
| 44 #include "chrome/common/chrome_paths_internal.h" | 44 #include "chrome/common/chrome_paths_internal.h" |
| 45 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
| 46 #include "chrome/common/shell_handler_win.mojom.h" | |
| 47 #include "chrome/grit/generated_resources.h" | |
| 46 #include "chrome/installer/setup/setup_util.h" | 48 #include "chrome/installer/setup/setup_util.h" |
| 47 #include "chrome/installer/util/browser_distribution.h" | 49 #include "chrome/installer/util/browser_distribution.h" |
| 48 #include "chrome/installer/util/create_reg_key_work_item.h" | 50 #include "chrome/installer/util/create_reg_key_work_item.h" |
| 49 #include "chrome/installer/util/install_util.h" | 51 #include "chrome/installer/util/install_util.h" |
| 50 #include "chrome/installer/util/scoped_user_protocol_entry.h" | 52 #include "chrome/installer/util/scoped_user_protocol_entry.h" |
| 51 #include "chrome/installer/util/set_reg_value_work_item.h" | 53 #include "chrome/installer/util/set_reg_value_work_item.h" |
| 52 #include "chrome/installer/util/shell_util.h" | 54 #include "chrome/installer/util/shell_util.h" |
| 53 #include "chrome/installer/util/util_constants.h" | 55 #include "chrome/installer/util/util_constants.h" |
| 54 #include "chrome/installer/util/work_item.h" | 56 #include "chrome/installer/util/work_item.h" |
| 55 #include "chrome/installer/util/work_item_list.h" | 57 #include "chrome/installer/util/work_item_list.h" |
| 56 #include "components/variations/variations_associated_data.h" | 58 #include "components/variations/variations_associated_data.h" |
| 57 #include "content/public/browser/browser_thread.h" | 59 #include "content/public/browser/browser_thread.h" |
| 60 #include "content/public/browser/utility_process_mojo_client.h" | |
| 61 #include "ui/base/l10n/l10n_util.h" | |
| 58 | 62 |
| 59 using content::BrowserThread; | 63 using content::BrowserThread; |
| 60 | 64 |
| 61 namespace shell_integration { | 65 namespace shell_integration { |
| 62 | 66 |
| 63 namespace { | 67 namespace { |
| 64 | 68 |
| 65 // Helper function for GetAppId to generates profile id | 69 // Helper function for GetAppId to generates profile id |
| 66 // from profile path. "profile_id" is composed of sanitized basenames of | 70 // from profile path. "profile_id" is composed of sanitized basenames of |
| 67 // user data dir and profile dir joined by a ".". | 71 // user data dir and profile dir joined by a ".". |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 // Weak ptrs are used to bind this class to the callbacks of the timer and the | 418 // Weak ptrs are used to bind this class to the callbacks of the timer and the |
| 415 // registry watcher. This makes it possible to self-delete after one of the | 419 // registry watcher. This makes it possible to self-delete after one of the |
| 416 // callbacks is executed to cancel the remaining ones. | 420 // callbacks is executed to cancel the remaining ones. |
| 417 base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_; | 421 base::WeakPtrFactory<OpenSystemSettingsHelper> weak_ptr_factory_; |
| 418 | 422 |
| 419 DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper); | 423 DISALLOW_COPY_AND_ASSIGN(OpenSystemSettingsHelper); |
| 420 }; | 424 }; |
| 421 | 425 |
| 422 OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr; | 426 OpenSystemSettingsHelper* OpenSystemSettingsHelper::instance_ = nullptr; |
| 423 | 427 |
| 428 // Record the UMA histogram when a response is received. The callback that binds | |
| 429 // to this function holds a reference to the ShellHandlerClient to keep it alive | |
| 430 // until invokation. | |
| 431 void OnIsPinnedToTaskbarResult( | |
| 432 content::UtilityProcessMojoClient<mojom::ShellHandler>* client, | |
| 433 bool succeeded, | |
| 434 bool is_pinned_to_taskbar) { | |
| 435 // Clean up the utility process. | |
| 436 delete client; | |
| 437 | |
| 438 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar.ProcessError", false); | |
| 439 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar.Succeeded", succeeded); | |
|
Alexei Svitkine (slow)
2016/06/29 14:37:44
I don't see why you need multiple histograms. Just
Patrick Monette
2016/06/29 18:28:42
Done. The process error is still separate because
| |
| 440 | |
| 441 if (succeeded) | |
| 442 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar", is_pinned_to_taskbar); | |
| 443 } | |
| 444 | |
| 445 // Called when a connection error happen with the shell handler process. A call | |
| 446 // to this function is mutially exclusive with a call to | |
| 447 // OnIsPinnedToTaskbarResult(). | |
| 448 void OnShellHandlerConnectionError( | |
| 449 content::UtilityProcessMojoClient<mojom::ShellHandler>* client) { | |
| 450 // Clean up the utility process. | |
| 451 delete client; | |
|
Alexei Svitkine (slow)
2016/06/29 14:37:44
Can the param be a scoped_ptr so you don't need to
Patrick Monette
2016/06/29 18:28:42
It needs to be 2 callbacks. In the general case, a
| |
| 452 | |
| 453 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar.ProcessError", true); | |
|
Alexei Svitkine (slow)
2016/06/29 14:37:44
A UMA macro expands to a lot of code. Please make
Patrick Monette
2016/06/29 18:28:42
Done.
| |
| 454 } | |
| 455 | |
| 424 } // namespace | 456 } // namespace |
| 425 | 457 |
| 426 bool SetAsDefaultBrowser() { | 458 bool SetAsDefaultBrowser() { |
| 427 base::FilePath chrome_exe; | 459 base::FilePath chrome_exe; |
| 428 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 460 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
| 429 LOG(ERROR) << "Error getting app exe path"; | 461 LOG(ERROR) << "Error getting app exe path"; |
| 430 return false; | 462 return false; |
| 431 } | 463 } |
| 432 | 464 |
| 433 // From UI currently we only allow setting default browser for current user. | 465 // From UI currently we only allow setting default browser for current user. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 // This needs to happen eventually (e.g. so that the appid is fixed and the | 684 // This needs to happen eventually (e.g. so that the appid is fixed and the |
| 653 // run-time Chrome icon is merged with the taskbar shortcut), but this is not | 685 // run-time Chrome icon is merged with the taskbar shortcut), but this is not |
| 654 // urgent and shouldn't delay Chrome startup. | 686 // urgent and shouldn't delay Chrome startup. |
| 655 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; | 687 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; |
| 656 BrowserThread::PostDelayedTask( | 688 BrowserThread::PostDelayedTask( |
| 657 BrowserThread::FILE, FROM_HERE, | 689 BrowserThread::FILE, FROM_HERE, |
| 658 base::Bind(&MigrateTaskbarPinsCallback), | 690 base::Bind(&MigrateTaskbarPinsCallback), |
| 659 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); | 691 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); |
| 660 } | 692 } |
| 661 | 693 |
| 694 void RecordIsPinnedToTaskbarHistogram() { | |
| 695 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
| 696 | |
| 697 // The code to check if Chrome is pinned to the taskbar brings in shell | |
| 698 // extensions which can hinder stability so it is executed in a utility | |
| 699 // process. | |
| 700 content::UtilityProcessMojoClient<mojom::ShellHandler>* client = | |
| 701 new content::UtilityProcessMojoClient<mojom::ShellHandler>( | |
| 702 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)); | |
| 703 | |
| 704 client->set_error_callback( | |
| 705 base::Bind(&OnShellHandlerConnectionError, client)); | |
| 706 client->set_disable_sandbox(); | |
| 707 client->Start(); | |
| 708 | |
| 709 client->service()->IsPinnedToTaskbar( | |
| 710 base::Bind(&OnIsPinnedToTaskbarResult, client)); | |
| 711 } | |
| 712 | |
| 662 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, | 713 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
| 663 const base::FilePath& path) { | 714 const base::FilePath& path) { |
| 664 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); | 715 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); |
| 665 | 716 |
| 666 // Enumerate all pinned shortcuts in the given path directly. | 717 // Enumerate all pinned shortcuts in the given path directly. |
| 667 base::FileEnumerator shortcuts_enum( | 718 base::FileEnumerator shortcuts_enum( |
| 668 path, false, // not recursive | 719 path, false, // not recursive |
| 669 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | 720 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
| 670 | 721 |
| 671 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe); | 722 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 if (base::PathExists(shortcut)) | 842 if (base::PathExists(shortcut)) |
| 792 return shortcut; | 843 return shortcut; |
| 793 } | 844 } |
| 794 | 845 |
| 795 return base::FilePath(); | 846 return base::FilePath(); |
| 796 } | 847 } |
| 797 | 848 |
| 798 } // namespace win | 849 } // namespace win |
| 799 | 850 |
| 800 } // namespace shell_integration | 851 } // namespace shell_integration |
| OLD | NEW |