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

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

Issue 2077583003: Report user actions for interactions with the Windows Settings app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 6 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 | « no previous file | chrome/browser/win/OWNERS » ('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.
11 #include <stddef.h> 11 #include <stddef.h>
12 #include <stdint.h> 12 #include <stdint.h>
13 13
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/callback.h" 17 #include "base/callback.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/files/file_enumerator.h" 19 #include "base/files/file_enumerator.h"
20 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/memory/ptr_util.h" 22 #include "base/memory/ptr_util.h"
23 #include "base/memory/weak_ptr.h" 23 #include "base/memory/weak_ptr.h"
24 #include "base/message_loop/message_loop.h" 24 #include "base/message_loop/message_loop.h"
25 #include "base/metrics/histogram_macros.h" 25 #include "base/metrics/histogram_macros.h"
26 #include "base/metrics/user_metrics.h"
27 #include "base/metrics/user_metrics_action.h"
26 #include "base/path_service.h" 28 #include "base/path_service.h"
27 #include "base/strings/string_util.h" 29 #include "base/strings/string_util.h"
28 #include "base/strings/stringprintf.h" 30 #include "base/strings/stringprintf.h"
29 #include "base/strings/utf_string_conversions.h" 31 #include "base/strings/utf_string_conversions.h"
30 #include "base/time/time.h" 32 #include "base/time/time.h"
31 #include "base/timer/timer.h" 33 #include "base/timer/timer.h"
32 #include "base/win/registry.h" 34 #include "base/win/registry.h"
33 #include "base/win/scoped_comptr.h" 35 #include "base/win/scoped_comptr.h"
34 #include "base/win/scoped_propvariant.h" 36 #include "base/win/scoped_propvariant.h"
35 #include "base/win/shortcut.h" 37 #include "base/win/shortcut.h"
36 #include "base/win/windows_version.h" 38 #include "base/win/windows_version.h"
37 #include "chrome/browser/policy/policy_path_parser.h" 39 #include "chrome/browser/policy/policy_path_parser.h"
38 #include "chrome/browser/shell_integration.h" 40 #include "chrome/browser/shell_integration.h"
39 #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"
40 #include "chrome/common/chrome_constants.h" 43 #include "chrome/common/chrome_constants.h"
41 #include "chrome/common/chrome_paths_internal.h" 44 #include "chrome/common/chrome_paths_internal.h"
42 #include "chrome/common/chrome_switches.h" 45 #include "chrome/common/chrome_switches.h"
43 #include "chrome/installer/setup/setup_util.h" 46 #include "chrome/installer/setup/setup_util.h"
44 #include "chrome/installer/util/browser_distribution.h" 47 #include "chrome/installer/util/browser_distribution.h"
45 #include "chrome/installer/util/create_reg_key_work_item.h" 48 #include "chrome/installer/util/create_reg_key_work_item.h"
46 #include "chrome/installer/util/install_util.h" 49 #include "chrome/installer/util/install_util.h"
47 #include "chrome/installer/util/scoped_user_protocol_entry.h" 50 #include "chrome/installer/util/scoped_user_protocol_entry.h"
48 #include "chrome/installer/util/set_reg_value_work_item.h" 51 #include "chrome/installer/util/set_reg_value_work_item.h"
49 #include "chrome/installer/util/shell_util.h" 52 #include "chrome/installer/util/shell_util.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 case ShellUtil::NOT_DEFAULT: 220 case ShellUtil::NOT_DEFAULT:
218 return DefaultWebClientState::NOT_DEFAULT; 221 return DefaultWebClientState::NOT_DEFAULT;
219 case ShellUtil::IS_DEFAULT: 222 case ShellUtil::IS_DEFAULT:
220 return DefaultWebClientState::IS_DEFAULT; 223 return DefaultWebClientState::IS_DEFAULT;
221 default: 224 default:
222 DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state); 225 DCHECK_EQ(ShellUtil::UNKNOWN_DEFAULT, default_state);
223 return DefaultWebClientState::UNKNOWN_DEFAULT; 226 return DefaultWebClientState::UNKNOWN_DEFAULT;
224 } 227 }
225 } 228 }
226 229
230 // A recorder of user actions in the Windows Settings app.
231 class DefaultBrowserActionRecorder : public win::SettingsAppMonitor::Delegate {
232 public:
233 // Creates the recorder and the monitor that drives it. |continuation| will be
234 // run once the monitor's initialization completes (regardless of success or
235 // failure).
236 explicit DefaultBrowserActionRecorder(base::Closure continuation)
237 : continuation_(std::move(continuation)), settings_app_monitor_(this) {}
238
239 private:
240 // win::SettingsAppMonitor::Delegate:
241 void OnInitialized(HRESULT result) override {
242 UMA_HISTOGRAM_BOOLEAN("SettingsAppMonitor.InitializationResult",
243 SUCCEEDED(result));
244 if (SUCCEEDED(result)) {
245 base::RecordAction(
246 base::UserMetricsAction("SettingsAppMonitor.Initialized"));
247 }
248 continuation_.Run();
249 continuation_ = base::Closure();
250 }
251
252 void OnAppFocused() override {
253 base::RecordAction(
254 base::UserMetricsAction("SettingsAppMonitor.AppFocused"));
255 }
256
257 void OnChooserInvoked() override {
258 base::RecordAction(
259 base::UserMetricsAction("SettingsAppMonitor.ChooserInvoked"));
260 }
261
262 void OnBrowserChosen(const base::string16& browser_name) override {
263 if (browser_name ==
264 BrowserDistribution::GetDistribution()->GetDisplayName()) {
265 base::RecordAction(
266 base::UserMetricsAction("SettingsAppMonitor.ChromeBrowserChosen"));
267 } else {
268 base::RecordAction(
269 base::UserMetricsAction("SettingsAppMonitor.OtherBrowserChosen"));
270 }
271 }
272
273 // A closure to be run once initialization completes.
274 base::Closure continuation_;
275
276 // Monitors user interaction with the Windows Settings app for the sake of
277 // reporting user actions.
278 win::SettingsAppMonitor settings_app_monitor_;
279
280 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserActionRecorder);
281 };
282
283 // A function bound up in a callback with a DefaultBrowserActionRecorder and
284 // a closure to keep the former alive until the time comes to run the latter.
285 void OnSettingsAppFinished(
286 std::unique_ptr<DefaultBrowserActionRecorder> recorder,
287 const base::Closure& on_finished_callback) {
288 recorder.reset();
289 on_finished_callback.Run();
290 }
291
227 // There is no way to make sure the user is done with the system settings, but a 292 // There is no way to make sure the user is done with the system settings, but a
228 // signal that the interaction is finished is needed for UMA. A timer of 2 293 // signal that the interaction is finished is needed for UMA. A timer of 2
229 // minutes is used as a substitute. The registry keys for the protocol 294 // minutes is used as a substitute. The registry keys for the protocol
230 // association with an app are also monitored to signal the end of the 295 // association with an app are also monitored to signal the end of the
231 // interaction early when it is clear that the user made a choice (e.g. http 296 // interaction early when it is clear that the user made a choice (e.g. http
232 // and https for default browser). 297 // and https for default browser).
233 // 298 //
234 // This helper class manages both the timer and the registry watchers and makes 299 // This helper class manages both the timer and the registry watchers and makes
235 // sure the callback for the end of the settings interaction is only run once. 300 // sure the callback for the end of the settings interaction is only run once.
236 // This class also manages its own lifetime. 301 // This class also manages its own lifetime.
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 const base::Closure& on_finished_callback) { 547 const base::Closure& on_finished_callback) {
483 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 548 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
484 549
485 base::FilePath chrome_exe; 550 base::FilePath chrome_exe;
486 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 551 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
487 NOTREACHED() << "Error getting app exe path"; 552 NOTREACHED() << "Error getting app exe path";
488 on_finished_callback.Run(); 553 on_finished_callback.Run();
489 return; 554 return;
490 } 555 }
491 556
492 // The helper manages its own lifetime. 557 // Create an action recorder that will open the settings app once it has
558 // initialized.
559 std::unique_ptr<DefaultBrowserActionRecorder> recorder(
560 new DefaultBrowserActionRecorder(base::Bind(
561 base::IgnoreResult(&ShellUtil::ShowMakeChromeDefaultSystemUI),
562 base::Unretained(BrowserDistribution::GetDistribution()),
563 chrome_exe)));
564
565 // The helper manages its own lifetime. Bind the action recorder
566 // into the finished callback to keep it alive throughout the
567 // interaction.
493 static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr}; 568 static const wchar_t* const kProtocols[] = {L"http", L"https", nullptr};
494 OpenSystemSettingsHelper::Begin(kProtocols, on_finished_callback); 569 OpenSystemSettingsHelper::Begin(
495 570 kProtocols, base::Bind(&OnSettingsAppFinished, base::Passed(&recorder),
496 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 571 on_finished_callback));
497 ShellUtil::ShowMakeChromeDefaultSystemUI(dist, chrome_exe);
498 } 572 }
499 573
500 bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) { 574 bool SetAsDefaultProtocolClientUsingIntentPicker(const std::string& protocol) {
501 base::FilePath chrome_exe; 575 base::FilePath chrome_exe;
502 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { 576 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) {
503 NOTREACHED() << "Error getting app exe path"; 577 NOTREACHED() << "Error getting app exe path";
504 return false; 578 return false;
505 } 579 }
506 580
507 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 581 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
708 if (base::PathExists(shortcut)) 782 if (base::PathExists(shortcut))
709 return shortcut; 783 return shortcut;
710 } 784 }
711 785
712 return base::FilePath(); 786 return base::FilePath();
713 } 787 }
714 788
715 } // namespace win 789 } // namespace win
716 790
717 } // namespace shell_integration 791 } // namespace shell_integration
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/win/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698