Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/shell_integration_win.cc

Issue 2079233004: Add the Windows.IsPinnedToTaskbar metric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Constexpr TimeDelta Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/shell_integration_win.h ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 void RecordPinnedToTaskbarProcessError(bool error) {
429 UMA_HISTOGRAM_BOOLEAN("Windows.IsPinnedToTaskbar.ProcessError", error);
430 }
431
432 // Record the UMA histogram when a response is received. The callback that binds
433 // to this function holds a reference to the ShellHandlerClient to keep it alive
434 // until invokation.
435 void OnIsPinnedToTaskbarResult(
436 content::UtilityProcessMojoClient<mojom::ShellHandler>* client,
437 bool succeeded,
438 bool is_pinned_to_taskbar) {
439 // Clean up the utility process.
440 delete client;
441
442 RecordPinnedToTaskbarProcessError(false);
443
444 enum Result { NOT_PINNED, PINNED, FAILURE, NUM_RESULTS };
445
446 Result result = FAILURE;
447 if (succeeded)
448 result = is_pinned_to_taskbar ? PINNED : NOT_PINNED;
449 UMA_HISTOGRAM_ENUMERATION("Windows.IsPinnedToTaskbar", result, NUM_RESULTS);
450 }
451
452 // Called when a connection error happen with the shell handler process. A call
453 // to this function is mutially exclusive with a call to
454 // OnIsPinnedToTaskbarResult().
455 void OnShellHandlerConnectionError(
456 content::UtilityProcessMojoClient<mojom::ShellHandler>* client) {
457 // Clean up the utility process.
458 delete client;
459
460 RecordPinnedToTaskbarProcessError(true);
461 }
462
424 } // namespace 463 } // namespace
425 464
426 bool SetAsDefaultBrowser() { 465 bool SetAsDefaultBrowser() {
427 base::FilePath chrome_exe; 466 base::FilePath chrome_exe;
428 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 467 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
429 LOG(ERROR) << "Error getting app exe path"; 468 LOG(ERROR) << "Error getting app exe path";
430 return false; 469 return false;
431 } 470 }
432 471
433 // From UI currently we only allow setting default browser for current user. 472 // From UI currently we only allow setting default browser for current user.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 // This needs to happen eventually (e.g. so that the appid is fixed and the 691 // 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 692 // run-time Chrome icon is merged with the taskbar shortcut), but this is not
654 // urgent and shouldn't delay Chrome startup. 693 // urgent and shouldn't delay Chrome startup.
655 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15; 694 static const int64_t kMigrateTaskbarPinsDelaySeconds = 15;
656 BrowserThread::PostDelayedTask( 695 BrowserThread::PostDelayedTask(
657 BrowserThread::FILE, FROM_HERE, 696 BrowserThread::FILE, FROM_HERE,
658 base::Bind(&MigrateTaskbarPinsCallback), 697 base::Bind(&MigrateTaskbarPinsCallback),
659 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds)); 698 base::TimeDelta::FromSeconds(kMigrateTaskbarPinsDelaySeconds));
660 } 699 }
661 700
701 void RecordIsPinnedToTaskbarHistogram() {
702 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
703
704 // The code to check if Chrome is pinned to the taskbar brings in shell
705 // extensions which can hinder stability so it is executed in a utility
706 // process.
707 content::UtilityProcessMojoClient<mojom::ShellHandler>* client =
708 new content::UtilityProcessMojoClient<mojom::ShellHandler>(
709 l10n_util::GetStringUTF16(IDS_UTILITY_PROCESS_SHELL_HANDLER_NAME));
710
711 client->set_error_callback(
712 base::Bind(&OnShellHandlerConnectionError, client));
713 client->set_disable_sandbox();
714 client->Start();
715
716 client->service()->IsPinnedToTaskbar(
717 base::Bind(&OnIsPinnedToTaskbarResult, client));
718 }
719
662 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, 720 int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe,
663 const base::FilePath& path) { 721 const base::FilePath& path) {
664 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7); 722 DCHECK(base::win::GetVersion() >= base::win::VERSION_WIN7);
665 723
666 // Enumerate all pinned shortcuts in the given path directly. 724 // Enumerate all pinned shortcuts in the given path directly.
667 base::FileEnumerator shortcuts_enum( 725 base::FileEnumerator shortcuts_enum(
668 path, false, // not recursive 726 path, false, // not recursive
669 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); 727 base::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk"));
670 728
671 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe); 729 bool is_per_user_install = InstallUtil::IsPerUserInstall(chrome_exe);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if (base::PathExists(shortcut)) 849 if (base::PathExists(shortcut))
792 return shortcut; 850 return shortcut;
793 } 851 }
794 852
795 return base::FilePath(); 853 return base::FilePath();
796 } 854 }
797 855
798 } // namespace win 856 } // namespace win
799 857
800 } // namespace shell_integration 858 } // namespace shell_integration
OLDNEW
« no previous file with comments | « chrome/browser/shell_integration_win.h ('k') | chrome/chrome_common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698