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

Side by Side Diff: chrome/browser/ui/cocoa/confirm_quit_panel_controller.mm

Issue 6794030: [Mac] Confirm-to-quit: Add histogram metrics. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/confirm_quit_panel_controller.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 #import <QuartzCore/QuartzCore.h> 6 #import <QuartzCore/QuartzCore.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_nsobject.h" 9 #include "base/memory/scoped_nsobject.h"
10 #include "base/metrics/histogram.h"
10 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
11 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h" 12 #import "chrome/browser/ui/cocoa/confirm_quit_panel_controller.h"
12 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util_mac.h" 14 #include "ui/base/l10n/l10n_util_mac.h"
14 15
15 // Constants /////////////////////////////////////////////////////////////////// 16 // Constants ///////////////////////////////////////////////////////////////////
16 17
17 // How long the user must hold down Cmd+Q to confirm the quit. 18 // How long the user must hold down Cmd+Q to confirm the quit.
18 const NSTimeInterval kTimeToConfirmQuit = 1.5; 19 const NSTimeInterval kTimeToConfirmQuit = 1.5;
19 20
20 // Leeway between the |targetDate| and the current time that will confirm a 21 // Leeway between the |targetDate| and the current time that will confirm a
21 // quit. 22 // quit.
22 const NSTimeInterval kTimeDeltaFuzzFactor = 1.0; 23 const NSTimeInterval kTimeDeltaFuzzFactor = 1.0;
23 24
24 // Duration of the window fade out animation. 25 // Duration of the window fade out animation.
25 const NSTimeInterval kWindowFadeAnimationDuration = 0.2; 26 const NSTimeInterval kWindowFadeAnimationDuration = 0.2;
26 27
28 // For metrics recording only: How long the user must hold the keys to
29 // differentitate kDoubleTap from kTapHold.
30 const NSTimeInterval kDoubleTapTimeDelta = 0.32;
31
32 // Functions ///////////////////////////////////////////////////////////////////
33
34 namespace confirm_quit {
35
36 void RecordHistogram(ConfirmQuitMetric sample) {
37 HISTOGRAM_ENUMERATION("ConfirmToQuit", sample, kSampleCount);
38 }
39
40 } // namespace confirm_quit
41
27 // Custom Content View ///////////////////////////////////////////////////////// 42 // Custom Content View /////////////////////////////////////////////////////////
28 43
29 // The content view of the window that draws a custom frame. 44 // The content view of the window that draws a custom frame.
30 @interface ConfirmQuitFrameView : NSView { 45 @interface ConfirmQuitFrameView : NSView {
31 @private 46 @private
32 NSTextField* message_; // Weak, owned by the view hierarchy. 47 NSTextField* message_; // Weak, owned by the view hierarchy.
33 } 48 }
34 - (void)setMessageText:(NSString*)text; 49 - (void)setMessageText:(NSString*)text;
35 @end 50 @end
36 51
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // tap Cmd+Q and then hold it with the window still open, this double-tap 225 // tap Cmd+Q and then hold it with the window still open, this double-tap
211 // logic will run and cause the quit to get committed. If the key 226 // logic will run and cause the quit to get committed. If the key
212 // combination held down, the system will start sending the Cmd+Q event to 227 // combination held down, the system will start sending the Cmd+Q event to
213 // the next key application, and so on. This is bad, so instead we hide all 228 // the next key application, and so on. This is bad, so instead we hide all
214 // the windows (without animation) to look like we've "quit" and then wait 229 // the windows (without animation) to look like we've "quit" and then wait
215 // for the KeyUp event to commit the quit. 230 // for the KeyUp event to commit the quit.
216 [self hideAllWindowsForApplication:app withDuration:0]; 231 [self hideAllWindowsForApplication:app withDuration:0];
217 NSEvent* nextEvent = [self pumpEventQueueForKeyUp:app 232 NSEvent* nextEvent = [self pumpEventQueueForKeyUp:app
218 untilDate:[NSDate distantFuture]]; 233 untilDate:[NSDate distantFuture]];
219 [app discardEventsMatchingMask:NSAnyEventMask beforeEvent:nextEvent]; 234 [app discardEventsMatchingMask:NSAnyEventMask beforeEvent:nextEvent];
235
236 // Based on how long the user held the keys, record the metric.
237 if ([[NSDate date] timeIntervalSinceDate:timeNow] < kDoubleTapTimeDelta)
238 confirm_quit::RecordHistogram(confirm_quit::kDoubleTap);
239 else
240 confirm_quit::RecordHistogram(confirm_quit::kTapHold);
220 return NSTerminateNow; 241 return NSTerminateNow;
221 } else { 242 } else {
222 [lastQuitAttempt release]; // Harmless if already nil. 243 [lastQuitAttempt release]; // Harmless if already nil.
223 lastQuitAttempt = [timeNow retain]; // Record this attempt for next time. 244 lastQuitAttempt = [timeNow retain]; // Record this attempt for next time.
224 } 245 }
225 246
226 // Show the info panel that explains what the user must to do confirm quit. 247 // Show the info panel that explains what the user must to do confirm quit.
227 [self showWindow:self]; 248 [self showWindow:self];
228 249
229 // Spin a nested run loop until the |targetDate| is reached or a KeyUp event 250 // Spin a nested run loop until the |targetDate| is reached or a KeyUp event
(...skipping 26 matching lines...) Expand all
256 } 277 }
257 } while (!nextEvent); 278 } while (!nextEvent);
258 279
259 // The user has released the key combo. Discard any events (i.e. the 280 // The user has released the key combo. Discard any events (i.e. the
260 // repeated KeyDown Cmd+Q). 281 // repeated KeyDown Cmd+Q).
261 [app discardEventsMatchingMask:NSAnyEventMask beforeEvent:nextEvent]; 282 [app discardEventsMatchingMask:NSAnyEventMask beforeEvent:nextEvent];
262 283
263 if (willQuit) { 284 if (willQuit) {
264 // The user held down the combination long enough that quitting should 285 // The user held down the combination long enough that quitting should
265 // happen. 286 // happen.
287 confirm_quit::RecordHistogram(confirm_quit::kHoldDuration);
266 return NSTerminateNow; 288 return NSTerminateNow;
267 } else { 289 } else {
268 // Slowly fade the confirm window out in case the user doesn't 290 // Slowly fade the confirm window out in case the user doesn't
269 // understand what they have to do to quit. 291 // understand what they have to do to quit.
270 [self dismissPanel]; 292 [self dismissPanel];
271 return NSTerminateCancel; 293 return NSTerminateCancel;
272 } 294 }
273 295
274 // Default case: terminate. 296 // Default case: terminate.
275 return NSTerminateNow; 297 return NSTerminateNow;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 if (modifiers & NSAlternateKeyMask) 393 if (modifiers & NSAlternateKeyMask)
372 [string appendString:@"\u2325"]; 394 [string appendString:@"\u2325"];
373 if (modifiers & NSShiftKeyMask) 395 if (modifiers & NSShiftKeyMask)
374 [string appendString:@"\u21E7"]; 396 [string appendString:@"\u21E7"];
375 397
376 [string appendString:[item.characters() uppercaseString]]; 398 [string appendString:[item.characters() uppercaseString]];
377 return string; 399 return string;
378 } 400 }
379 401
380 @end 402 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/confirm_quit_panel_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698