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.Succeeded", succeeded); | |
439 | |
440 if (succeeded) | |
441 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar", is_pinned_to_taskbar); | |
442 } | |
443 | |
444 // Called when a connection error happen with the shell handler process. A call | |
445 // to this function is mutially exclusive with a call to | |
446 // OnIsPinnedToTaskbarResult(). | |
447 void OnShellHandlerConnectionError( | |
448 content::UtilityProcessMojoClient<mojom::ShellHandler>* client) { | |
449 // Clean up the utility process. | |
450 delete client; | |
451 | |
452 UMA_HISTOGRAM_COUNTS("Windows.ShellHandlerProcessError", 1); | |
gab
2016/06/28 20:59:18
I think UMA_HISTOGRAM_BOOLEAN with enum="BooleanHi
Patrick Monette
2016/06/28 23:22:24
Done.
| |
453 } | |
454 | |
455 void RecordIsPinnedToTaskbarHistogramOnIOThread() { | |
456 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
457 | |
458 // The code to check if Chrome is pinned to the taskbar is crashy so it is | |
gab
2016/06/28 20:59:18
s/is crashy/brings in shell extensions which can h
Patrick Monette
2016/06/28 23:22:24
Done.
| |
459 // executed in a utility process. | |
460 content::UtilityProcessMojoClient<mojom::ShellHandler>* client = | |
461 new content::UtilityProcessMojoClient<mojom::ShellHandler>( | |
462 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)); | |
463 | |
464 client->set_error_callback( | |
465 base::Bind(&OnShellHandlerConnectionError, client)); | |
466 client->set_disable_sandbox(); | |
467 client->Start(); | |
468 | |
469 client->service()->IsPinnedToTaskbar( | |
470 base::Bind(&OnIsPinnedToTaskbarResult, client)); | |
471 } | |
472 | |
424 } // namespace | 473 } // namespace |
425 | 474 |
426 bool SetAsDefaultBrowser() { | 475 bool SetAsDefaultBrowser() { |
427 base::FilePath chrome_exe; | 476 base::FilePath chrome_exe; |
428 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 477 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
429 LOG(ERROR) << "Error getting app exe path"; | 478 LOG(ERROR) << "Error getting app exe path"; |
430 return false; | 479 return false; |
431 } | 480 } |
432 | 481 |
433 // From UI currently we only allow setting default browser for current user. | 482 // 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 | 701 // 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 | 702 // run-time Chrome icon is merged with the taskbar shortcut), but this is not |
654 // urgent and shouldn't delay Chrome startup. | 703 // urgent and shouldn't delay Chrome startup. |
655 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; | 704 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; |
656 BrowserThread::PostDelayedTask( | 705 BrowserThread::PostDelayedTask( |
657 BrowserThread::FILE, FROM_HERE, | 706 BrowserThread::FILE, FROM_HERE, |
658 base::Bind(&MigrateTaskbarPinsCallback), | 707 base::Bind(&MigrateTaskbarPinsCallback), |
659 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); | 708 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); |
660 } | 709 } |
661 | 710 |
711 void RecordIsPinnedToTaskbarHistogram() { | |
712 content::BrowserThread::PostTask( | |
713 content::BrowserThread::IO, FROM_HERE, | |
714 base::Bind(&RecordIsPinnedToTaskbarHistogramOnIOThread)); | |
715 } | |
716 | |
662 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, | 717 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
663 const base::FilePath& path) { | 718 const base::FilePath& path) { |
664 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); | 719 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); |
665 | 720 |
666 // Enumerate all pinned shortcuts in the given path directly. | 721 // Enumerate all pinned shortcuts in the given path directly. |
667 base::FileEnumerator shortcuts_enum( | 722 base::FileEnumerator shortcuts_enum( |
668 path, false, // not recursive | 723 path, false, // not recursive |
669 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | 724 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); |
670 | 725 |
671 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe); | 726 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)) | 846 if (base::PathExists(shortcut)) |
792 return shortcut; | 847 return shortcut; |
793 } | 848 } |
794 | 849 |
795 return base::FilePath(); | 850 return base::FilePath(); |
796 } | 851 } |
797 | 852 |
798 } // namespace win | 853 } // namespace win |
799 | 854 |
800 } // namespace shell_integration | 855 } // namespace shell_integration |
OLD | NEW |