[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / restart_browser.mm
blob891bfb8959a63f45a764d96ddc1678fb726cf3b4
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/restart_browser.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/lifetime/application_lifetime.h"
9 #include "grit/chromium_strings.h"
10 #include "grit/generated_resources.h"
11 #include "grit/ui_strings.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/l10n/l10n_util_mac.h"
15 // Helper to clean up after the notification that the alert was dismissed.
16 @interface RestartHelper : NSObject {
17  @private
18   NSAlert* alert_;
20 - (NSAlert*)alert;
21 - (void)alertDidEnd:(NSAlert*)alert
22          returnCode:(int)returnCode
23         contextInfo:(void*)contextInfo;
24 @end
26 @implementation RestartHelper
28 - (NSAlert*)alert {
29   alert_ = [[NSAlert alloc] init];
30   return alert_;
33 - (void)dealloc {
34   [alert_ release];
35   [super dealloc];
38 - (void)alertDidEnd:(NSAlert*)alert
39          returnCode:(int)returnCode
40         contextInfo:(void*)contextInfo {
41   if (returnCode == NSAlertFirstButtonReturn) {
42     chrome::AttemptRestart();
43   } else if (returnCode == NSAlertSecondButtonReturn) {
44     // Nothing to do. User will restart later.
45   } else {
46     NOTREACHED();
47   }
48   [self autorelease];
51 @end
53 namespace restart_browser {
55 void RequestRestart(NSWindow* parent) {
56   NSString* title =
57       l10n_util::GetNSStringFWithFixup(IDS_PLEASE_RELAUNCH_BROWSER,
58           l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
59   NSString* text =
60       l10n_util::GetNSStringFWithFixup(IDS_UPDATE_RECOMMENDED,
61           l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
62   NSString* notNowButton = l10n_util::GetNSStringWithFixup(IDS_NOT_NOW);
63   NSString* restartButton =
64       l10n_util::GetNSStringWithFixup(IDS_RELAUNCH_AND_UPDATE);
66   RestartHelper* helper = [[RestartHelper alloc] init];
68   NSAlert* alert = [helper alert];
69   [alert setAlertStyle:NSInformationalAlertStyle];
70   [alert setMessageText:title];
71   [alert setInformativeText:text];
72   [alert addButtonWithTitle:restartButton];
73   [alert addButtonWithTitle:notNowButton];
75   if (parent) {
76     [alert beginSheetModalForWindow:parent
77                       modalDelegate:helper
78                      didEndSelector:@selector(alertDidEnd:
79                                                returnCode:
80                                               contextInfo:)
81                         contextInfo:nil];
82   } else {
83     NSInteger returnCode = [alert runModal];
84     [helper alertDidEnd:alert
85              returnCode:returnCode
86             contextInfo:NULL];
87   }
90 }  // namespace restart_browser