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/chromium_strings.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 is_pinned_to_taskbar) { | |
434 // Clean up the utility process. | |
435 delete client; | |
436 | |
437 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar", is_pinned_to_taskbar); | |
438 } | |
439 | |
440 // Called when a connection error happen with the shell handler process. A call | |
441 // to this function is mutially exclusive with a call to | |
442 // OnIsPinnedToTaskbarResult(). | |
443 void OnShellHandlerConnectionError( | |
444 content::UtilityProcessMojoClient<mojom::ShellHandler>* client) { | |
445 // Clean up the utility process. | |
446 delete client; | |
447 | |
448 UMA_HISTOGRAM_COUNTS("Windows.ShellHandlerProcessError", 1); | |
grt (UTC plus 2)
2016/06/22 13:58:50
is it always the case that Chrome will either reco
Patrick Monette
2016/06/23 22:58:52
I can easily imagine that we'll add an histogram w
| |
449 } | |
450 | |
451 void RecordIsPinnedToTaskbarHistogramOnIOThread() { | |
452 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | |
453 | |
454 // The code to check if Chrome is pinned to the taskbar is crashy so it is | |
455 // executed on a utility process. | |
grt (UTC plus 2)
2016/06/22 13:58:50
nit: on -> in
Patrick Monette
2016/06/23 22:58:52
Done.
| |
456 content::UtilityProcessMojoClient<mojom::ShellHandler>* client = | |
457 new content::UtilityProcessMojoClient<mojom::ShellHandler>( | |
458 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME)); | |
459 | |
460 client->set_error_callback( | |
461 base::Bind(&OnShellHandlerConnectionError, client)); | |
462 client->set_disable_sandbox(); | |
463 client->Start(); | |
464 | |
465 client->service()->IsPinnedToTaskbar( | |
466 base::Bind(&OnIsPinnedToTaskbarResult, client)); | |
467 } | |
468 | |
424 } // namespace | 469 } // namespace |
425 | 470 |
426 bool SetAsDefaultBrowser() { | 471 bool SetAsDefaultBrowser() { |
427 base::FilePath chrome_exe; | 472 base::FilePath chrome_exe; |
428 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 473 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
429 LOG(ERROR) << "Error getting app exe path"; | 474 LOG(ERROR) << "Error getting app exe path"; |
430 return false; | 475 return false; |
431 } | 476 } |
432 | 477 |
433 // From UI currently we only allow setting default browser for current user. | 478 // 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 | 697 // 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 | 698 // run-time Chrome icon is merged with the taskbar shortcut), but this is not |
654 // urgent and shouldn't delay Chrome startup. | 699 // urgent and shouldn't delay Chrome startup. |
655 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; | 700 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; |
656 BrowserThread::PostDelayedTask( | 701 BrowserThread::PostDelayedTask( |
657 BrowserThread::FILE, FROM_HERE, | 702 BrowserThread::FILE, FROM_HERE, |
658 base::Bind(&MigrateTaskbarPinsCallback), | 703 base::Bind(&MigrateTaskbarPinsCallback), |
659 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); | 704 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); |
660 } | 705 } |
661 | 706 |
707 void RecordIsPinnedToTaskbarHistogram() { | |
708 content::BrowserThread::PostTask( | |
709 content::BrowserThread::IO, FROM_HERE, | |
710 base::Bind(&RecordIsPinnedToTaskbarHistogramOnIOThread)); | |
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 |