[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / profiles / profile_signin_confirmation_dialog_cocoa.mm
blob44fa0c33155ae92708fda674a3f4bf431e02d021
1 // Copyright 2014 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/profiles/profile_signin_confirmation_dialog_cocoa.h"
7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_dialogs.h"
10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_sheet.h"
13 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_custom_window.h"
14 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 namespace {
19 // static
20 void ShowDialog(
21     Browser* browser,
22     content::WebContents* web_contents,
23     Profile* profile,
24     const std::string& username,
25     ui::ProfileSigninConfirmationDelegate* delegate,
26     bool offer_profile_creation) {
27   // The dialog owns itself.
28   new ProfileSigninConfirmationDialogCocoa(browser,
29                                            web_contents,
30                                            profile,
31                                            username,
32                                            delegate,
33                                            offer_profile_creation);
36 }  // namespace
38 namespace chrome {
40 // Declared in browser_dialogs.h
41 void ShowProfileSigninConfirmationDialog(
42     Browser* browser,
43     content::WebContents* web_contents,
44     Profile* profile,
45     const std::string& username,
46     ui::ProfileSigninConfirmationDelegate* delegate) {
47   ui::CheckShouldPromptForNewProfile(
48       profile,
49       base::Bind(ShowDialog,
50                  browser, web_contents, profile, username, delegate));
53 }  // namespace chrome
55 ProfileSigninConfirmationDialogCocoa::ProfileSigninConfirmationDialogCocoa(
56     Browser* browser,
57     content::WebContents* web_contents,
58     Profile* profile,
59     const std::string& username,
60     ui::ProfileSigninConfirmationDelegate* delegate,
61     bool offer_profile_creation) {
62   // Setup the dialog view controller.
63   const base::Closure& closeDialogCallback =
64       base::Bind(&ProfileSigninConfirmationDialogCocoa::Close,
65                  base::Unretained(this));
66   controller_.reset(
67       [[ProfileSigninConfirmationViewController alloc]
68           initWithBrowser:browser
69                  username:username
70                  delegate:delegate
71       closeDialogCallback:closeDialogCallback
72      offerProfileCreation:offer_profile_creation]);
74   // Setup the constrained window that will show the view.
75   base::scoped_nsobject<NSWindow> window([[ConstrainedWindowCustomWindow alloc]
76       initWithContentRect:[[controller_ view] bounds]]);
77   [[window contentView] addSubview:[controller_ view]];
78   base::scoped_nsobject<CustomConstrainedWindowSheet> sheet(
79       [[CustomConstrainedWindowSheet alloc] initWithCustomWindow:window]);
80   window_.reset(new ConstrainedWindowMac(this, web_contents, sheet));
83 ProfileSigninConfirmationDialogCocoa::~ProfileSigninConfirmationDialogCocoa() {
86 void ProfileSigninConfirmationDialogCocoa::Close() {
87   window_->CloseWebContentsModalDialog();
90 void ProfileSigninConfirmationDialogCocoa::OnConstrainedWindowClosed(
91     ConstrainedWindowMac* window) {
92   base::MessageLoop::current()->DeleteSoon(FROM_HERE, this);