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 13 matching lines...) Expand all Loading... | |
24 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
25 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
26 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
27 #include "base/metrics/histogram_macros.h" | 27 #include "base/metrics/histogram_macros.h" |
28 #include "base/metrics/user_metrics.h" | 28 #include "base/metrics/user_metrics.h" |
29 #include "base/metrics/user_metrics_action.h" | 29 #include "base/metrics/user_metrics_action.h" |
30 #include "base/path_service.h" | 30 #include "base/path_service.h" |
31 #include "base/strings/string_util.h" | 31 #include "base/strings/string_util.h" |
32 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
33 #include "base/strings/utf_string_conversions.h" | 33 #include "base/strings/utf_string_conversions.h" |
34 #include "base/task_scheduler/post_task.h" | |
34 #include "base/time/time.h" | 35 #include "base/time/time.h" |
35 #include "base/timer/timer.h" | 36 #include "base/timer/timer.h" |
36 #include "base/win/registry.h" | 37 #include "base/win/registry.h" |
37 #include "base/win/scoped_comptr.h" | 38 #include "base/win/scoped_comptr.h" |
38 #include "base/win/scoped_propvariant.h" | 39 #include "base/win/scoped_propvariant.h" |
39 #include "base/win/shortcut.h" | 40 #include "base/win/shortcut.h" |
40 #include "base/win/windows_version.h" | 41 #include "base/win/windows_version.h" |
41 #include "chrome/browser/policy/policy_path_parser.h" | 42 #include "chrome/browser/policy/policy_path_parser.h" |
42 #include "chrome/browser/shell_integration.h" | 43 #include "chrome/browser/shell_integration.h" |
43 #include "chrome/browser/web_applications/web_app.h" | 44 #include "chrome/browser/web_applications/web_app.h" |
44 #include "chrome/browser/win/settings_app_monitor.h" | 45 #include "chrome/browser/win/settings_app_monitor.h" |
45 #include "chrome/common/chrome_constants.h" | 46 #include "chrome/common/chrome_constants.h" |
46 #include "chrome/common/chrome_paths_internal.h" | 47 #include "chrome/common/chrome_paths_internal.h" |
47 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
48 #include "chrome/common/shell_handler_win.mojom.h" | 49 #include "chrome/common/shell_handler_win.mojom.h" |
49 #include "chrome/grit/generated_resources.h" | 50 #include "chrome/grit/generated_resources.h" |
50 #include "chrome/install_static/install_util.h" | 51 #include "chrome/install_static/install_util.h" |
51 #include "chrome/installer/util/browser_distribution.h" | 52 #include "chrome/installer/util/browser_distribution.h" |
52 #include "chrome/installer/util/install_util.h" | 53 #include "chrome/installer/util/install_util.h" |
53 #include "chrome/installer/util/scoped_user_protocol_entry.h" | 54 #include "chrome/installer/util/scoped_user_protocol_entry.h" |
54 #include "chrome/installer/util/shell_util.h" | 55 #include "chrome/installer/util/shell_util.h" |
55 #include "components/variations/variations_associated_data.h" | 56 #include "components/variations/variations_associated_data.h" |
56 #include "content/public/browser/browser_thread.h" | |
57 #include "content/public/browser/utility_process_mojo_client.h" | 57 #include "content/public/browser/utility_process_mojo_client.h" |
58 #include "ui/base/l10n/l10n_util.h" | 58 #include "ui/base/l10n/l10n_util.h" |
59 | 59 |
60 using content::BrowserThread; | |
61 | |
62 namespace shell_integration { | 60 namespace shell_integration { |
63 | 61 |
64 namespace { | 62 namespace { |
65 | 63 |
66 // Helper function for GetAppId to generates profile id | 64 // Helper function for GetAppId to generates profile id |
67 // from profile path. "profile_id" is composed of sanitized basenames of | 65 // from profile path. "profile_id" is composed of sanitized basenames of |
68 // user data dir and profile dir joined by a ".". | 66 // user data dir and profile dir joined by a ".". |
69 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { | 67 base::string16 GetProfileIdFromPath(const base::FilePath& profile_path) { |
70 // Return empty string if profile_path is empty | 68 // Return empty string if profile_path is empty |
71 if (profile_path.empty()) | 69 if (profile_path.empty()) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 app_name = GetAppListAppName(); | 140 app_name = GetAppListAppName(); |
143 } else { | 141 } else { |
144 app_name = ShellUtil::GetBrowserModelId(is_per_user_install); | 142 app_name = ShellUtil::GetBrowserModelId(is_per_user_install); |
145 } | 143 } |
146 DCHECK(!app_name.empty()); | 144 DCHECK(!app_name.empty()); |
147 | 145 |
148 return win::GetAppModelIdForProfile(app_name, profile_path); | 146 return win::GetAppModelIdForProfile(app_name, profile_path); |
149 } | 147 } |
150 | 148 |
151 void MigrateTaskbarPinsCallback() { | 149 void MigrateTaskbarPinsCallback() { |
152 // This should run on the file thread. | 150 base::ThreadRestrictions::AssertIOAllowed(); |
153 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
154 | 151 |
155 // Get full path of chrome. | 152 // Get full path of chrome. |
156 base::FilePath chrome_exe; | 153 base::FilePath chrome_exe; |
157 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) | 154 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) |
158 return; | 155 return; |
159 | 156 |
160 base::FilePath pins_path; | 157 base::FilePath pins_path; |
161 if (!PathService::Get(base::DIR_TASKBAR_PINS, &pins_path)) { | 158 if (!PathService::Get(base::DIR_TASKBAR_PINS, &pins_path)) { |
162 NOTREACHED(); | 159 NOTREACHED(); |
163 return; | 160 return; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 // This helper class manages both the timer and the registry watchers and makes | 317 // This helper class manages both the timer and the registry watchers and makes |
321 // sure the callback for the end of the settings interaction is only run once. | 318 // sure the callback for the end of the settings interaction is only run once. |
322 // This class also manages its own lifetime. | 319 // This class also manages its own lifetime. |
323 class OpenSystemSettingsHelper { | 320 class OpenSystemSettingsHelper { |
324 public: | 321 public: |
325 // Begin the monitoring and will call |on_finished_callback| when done. | 322 // Begin the monitoring and will call |on_finished_callback| when done. |
326 // Takes in a null-terminated array of |protocols| whose registry keys must be | 323 // Takes in a null-terminated array of |protocols| whose registry keys must be |
327 // watched. The array must contain at least one element. | 324 // watched. The array must contain at least one element. |
328 static void Begin(const wchar_t* const protocols[], | 325 static void Begin(const wchar_t* const protocols[], |
329 const base::Closure& on_finished_callback) { | 326 const base::Closure& on_finished_callback) { |
330 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
Lei Zhang
2017/05/19 23:23:13
Looks like you wrote this code. If you are ok with
Patrick Monette
2017/05/26 01:50:12
Your comment made me realize that there is actuall
| |
331 | |
332 delete instance_; | 327 delete instance_; |
333 instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback); | 328 instance_ = new OpenSystemSettingsHelper(protocols, on_finished_callback); |
334 } | 329 } |
335 | 330 |
336 private: | 331 private: |
337 // The reason the settings interaction concluded. Do not modify the ordering | 332 // The reason the settings interaction concluded. Do not modify the ordering |
338 // because it is used for UMA. | 333 // because it is used for UMA. |
339 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; | 334 enum ConcludeReason { REGISTRY_WATCHER, TIMEOUT, NUM_CONCLUDE_REASON_TYPES }; |
340 | 335 |
341 OpenSystemSettingsHelper(const wchar_t* const protocols[], | 336 OpenSystemSettingsHelper(const wchar_t* const protocols[], |
(...skipping 19 matching lines...) Expand all Loading... | |
361 FROM_HERE, base::TimeDelta::FromMinutes(2), | 356 FROM_HERE, base::TimeDelta::FromMinutes(2), |
362 base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction, | 357 base::Bind(&OpenSystemSettingsHelper::ConcludeInteraction, |
363 weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT)); | 358 weak_ptr_factory_.GetWeakPtr(), ConcludeReason::TIMEOUT)); |
364 } | 359 } |
365 | 360 |
366 // Called when a change is detected on one of the registry keys being watched. | 361 // Called when a change is detected on one of the registry keys being watched. |
367 // Note: All types of modification to the registry key will trigger this | 362 // Note: All types of modification to the registry key will trigger this |
368 // function even if the value change is the only one that matters. This | 363 // function even if the value change is the only one that matters. This |
369 // is good enough for now. | 364 // is good enough for now. |
370 void OnRegistryKeyChanged() { | 365 void OnRegistryKeyChanged() { |
371 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
372 | |
373 // Make sure all the registry watchers have fired. | 366 // Make sure all the registry watchers have fired. |
374 if (--registry_watcher_count_ == 0) { | 367 if (--registry_watcher_count_ == 0) { |
375 UMA_HISTOGRAM_MEDIUM_TIMES( | 368 UMA_HISTOGRAM_MEDIUM_TIMES( |
376 "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration", | 369 "DefaultBrowser.SettingsInteraction.RegistryWatcherDuration", |
377 base::TimeTicks::Now() - start_time_); | 370 base::TimeTicks::Now() - start_time_); |
378 | 371 |
379 ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER); | 372 ConcludeInteraction(ConcludeReason::REGISTRY_WATCHER); |
380 } | 373 } |
381 } | 374 } |
382 | 375 |
383 // Ends the monitoring with the system settings. Will call | 376 // Ends the monitoring with the system settings. Will call |
384 // |on_finished_callback_| and then dispose of this class instance to make | 377 // |on_finished_callback_| and then dispose of this class instance to make |
385 // sure the callback won't get called subsequently. | 378 // sure the callback won't get called subsequently. |
386 void ConcludeInteraction(ConcludeReason conclude_reason) { | 379 void ConcludeInteraction(ConcludeReason conclude_reason) { |
387 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
388 | |
389 UMA_HISTOGRAM_ENUMERATION( | 380 UMA_HISTOGRAM_ENUMERATION( |
390 "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason, | 381 "DefaultBrowser.SettingsInteraction.ConcludeReason", conclude_reason, |
391 NUM_CONCLUDE_REASON_TYPES); | 382 NUM_CONCLUDE_REASON_TYPES); |
392 on_finished_callback_.Run(); | 383 on_finished_callback_.Run(); |
393 delete instance_; | 384 delete instance_; |
394 instance_ = nullptr; | 385 instance_ = nullptr; |
395 } | 386 } |
396 | 387 |
397 // Helper function to create a registry watcher for a given |key_path|. Do | 388 // Helper function to create a registry watcher for a given |key_path|. Do |
398 // nothing on initialization failure. | 389 // nothing on initialization failure. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 LOG(ERROR) << "Failed to launch the set-default-browser Windows UI."; | 626 LOG(ERROR) << "Failed to launch the set-default-browser Windows UI."; |
636 return false; | 627 return false; |
637 } | 628 } |
638 | 629 |
639 VLOG(1) << "Set-default-browser Windows UI completed."; | 630 VLOG(1) << "Set-default-browser Windows UI completed."; |
640 return true; | 631 return true; |
641 } | 632 } |
642 | 633 |
643 void SetAsDefaultBrowserUsingSystemSettings( | 634 void SetAsDefaultBrowserUsingSystemSettings( |
644 const base::Closure& on_finished_callback) { | 635 const base::Closure& on_finished_callback) { |
645 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
646 | |
647 base::FilePath chrome_exe; | 636 base::FilePath chrome_exe; |
648 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 637 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
649 NOTREACHED() << "Error getting app exe path"; | 638 NOTREACHED() << "Error getting app exe path"; |
650 on_finished_callback.Run(); | 639 on_finished_callback.Run(); |
651 return; | 640 return; |
652 } | 641 } |
653 | 642 |
654 // Create an action recorder that will open the settings app once it has | 643 // Create an action recorder that will open the settings app once it has |
655 // initialized. | 644 // initialized. |
656 std::unique_ptr<DefaultBrowserActionRecorder> recorder( | 645 std::unique_ptr<DefaultBrowserActionRecorder> recorder( |
(...skipping 26 matching lines...) Expand all Loading... | |
683 return false; | 672 return false; |
684 } | 673 } |
685 | 674 |
686 VLOG(1) << "Set-default-client Windows UI completed."; | 675 VLOG(1) << "Set-default-client Windows UI completed."; |
687 return true; | 676 return true; |
688 } | 677 } |
689 | 678 |
690 void SetAsDefaultProtocolClientUsingSystemSettings( | 679 void SetAsDefaultProtocolClientUsingSystemSettings( |
691 const std::string& protocol, | 680 const std::string& protocol, |
692 const base::Closure& on_finished_callback) { | 681 const base::Closure& on_finished_callback) { |
693 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 682 base::ThreadRestrictions::AssertIOAllowed(); |
694 | 683 |
695 base::FilePath chrome_exe; | 684 base::FilePath chrome_exe; |
696 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | 685 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { |
697 NOTREACHED() << "Error getting app exe path"; | 686 NOTREACHED() << "Error getting app exe path"; |
698 on_finished_callback.Run(); | 687 on_finished_callback.Run(); |
699 return; | 688 return; |
700 } | 689 } |
701 | 690 |
702 // The helper manages its own lifetime. | 691 // The helper manages its own lifetime. |
703 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); | 692 base::string16 wprotocol(base::UTF8ToUTF16(protocol)); |
(...skipping 19 matching lines...) Expand all Loading... | |
723 const base::FilePath& profile_path) { | 712 const base::FilePath& profile_path) { |
724 return GetAppModelIdForProfile( | 713 return GetAppModelIdForProfile( |
725 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()), | 714 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()), |
726 profile_path); | 715 profile_path); |
727 } | 716 } |
728 | 717 |
729 void MigrateTaskbarPins() { | 718 void MigrateTaskbarPins() { |
730 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 719 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
731 return; | 720 return; |
732 | 721 |
733 // This needs to happen eventually (e.g. so that the appid is fixed and the | 722 // This needs to happen (e.g. so that the appid is fixed and the |
734 // run-time Chrome icon is merged with the taskbar shortcut), but this is not | 723 // run-time Chrome icon is merged with the taskbar shortcut), but it is not an |
735 // urgent and shouldn't delay Chrome startup. | 724 // urgent task. |
736 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; | 725 base::PostTaskWithTraits(FROM_HERE, |
737 BrowserThread::PostDelayedTask( | 726 {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
738 BrowserThread::FILE, FROM_HERE, | 727 base::Bind(&MigrateTaskbarPinsCallback)); |
739 base::Bind(&MigrateTaskbarPinsCallback), | |
740 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); | |
741 } | 728 } |
742 | 729 |
743 void GetIsPinnedToTaskbarState( | 730 void GetIsPinnedToTaskbarState( |
744 const ConnectionErrorCallback& on_error_callback, | 731 const ConnectionErrorCallback& on_error_callback, |
745 const IsPinnedToTaskbarCallback& result_callback) { | 732 const IsPinnedToTaskbarCallback& result_callback) { |
746 IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback); | 733 IsPinnedToTaskbarHelper::GetState(on_error_callback, result_callback); |
747 } | 734 } |
748 | 735 |
749 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, | 736 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, |
750 const base::FilePath& path) { | 737 const base::FilePath& path) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
849 base::win::SHORTCUT_UPDATE_EXISTING)) { | 836 base::win::SHORTCUT_UPDATE_EXISTING)) { |
850 ++shortcuts_migrated; | 837 ++shortcuts_migrated; |
851 } | 838 } |
852 } | 839 } |
853 return shortcuts_migrated; | 840 return shortcuts_migrated; |
854 } | 841 } |
855 | 842 |
856 } // namespace win | 843 } // namespace win |
857 | 844 |
858 } // namespace shell_integration | 845 } // namespace shell_integration |
OLD | NEW |