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.
4
5#ifndef CHROME_BROWSER_UI_COCOA_PROFILES_PROFILE_CHOOSER_CONTROLLER_H_
6#define CHROME_BROWSER_UI_COCOA_PROFILES_PROFILE_CHOOSER_CONTROLLER_H_
7
8#import <Cocoa/Cocoa.h>
9#include <map>
10#include <string>
11
12#include "base/memory/scoped_ptr.h"
13#include "chrome/browser/profiles/profile_metrics.h"
14#include "chrome/browser/signin/signin_header_helper.h"
15#include "chrome/browser/ui/profile_chooser_constants.h"
16#import "chrome/browser/ui/cocoa/base_bubble_controller.h"
17
18class AvatarMenu;
19class ActiveProfileObserverBridge;
20class Browser;
21class ProfileOAuth2TokenService;
22
23namespace content {
24class WebContents;
25}
26
27// This window controller manages the bubble that displays a "menu" of profiles.
28// It is brought open by clicking on the avatar icon in the window frame.
29@interface ProfileChooserController : BaseBubbleController<NSTextViewDelegate> {
30 @private
31  // The menu that contains the data from the backend.
32  scoped_ptr<AvatarMenu> avatarMenu_;
33
34  // An observer to be notified when the OAuth2 tokens change or the avatar
35  // menu model updates for the active profile.
36  scoped_ptr<ActiveProfileObserverBridge> observer_;
37
38  // The browser that launched the bubble. Not owned.
39  Browser* browser_;
40
41  // The id for the account that the user has requested to remove from the
42  // current profile. It is set in |showAccountRemovalView| and used in
43  // |removeAccount|.
44  std::string accountIdToRemove_;
45
46  // Active view mode.
47  profiles::BubbleViewMode viewMode_;
48
49  // The current tutorial mode.
50  profiles::TutorialMode tutorialMode_;
51
52  // List of the full, un-elided accounts for the active profile. The keys are
53  // generated used to tag the UI buttons, and the values are the original
54  // emails displayed by the buttons.
55  std::map<int, std::string> currentProfileAccounts_;
56
57  // Web contents used by the inline signin view.
58  scoped_ptr<content::WebContents> webContents_;
59
60  // Whether the bubble is displayed for an active guest profile.
61  BOOL isGuestSession_;
62
63  // The GAIA service type that caused this menu to open.
64  signin::GAIAServiceType serviceType_;
65}
66
67- (id)initWithBrowser:(Browser*)browser
68           anchoredAt:(NSPoint)point
69             viewMode:(profiles::BubbleViewMode)viewMode
70         tutorialMode:(profiles::TutorialMode)tutorialMode
71          serviceType:(signin::GAIAServiceType)GAIAServiceType;
72
73// Creates all the subviews of the avatar bubble for |viewToDisplay|.
74- (void)initMenuContentsWithView:(profiles::BubbleViewMode)viewToDisplay;
75
76// Returns the view currently displayed by the bubble.
77- (profiles::BubbleViewMode)viewMode;
78
79// Sets the tutorial mode of the bubble.
80- (void)setTutorialMode:(profiles::TutorialMode)tutorialMode;
81
82// Switches to a given profile. |sender| is an ProfileChooserItemController.
83- (IBAction)switchToProfile:(id)sender;
84
85// Shows the User Manager.
86- (IBAction)showUserManager:(id)sender;
87
88// Closes all guest browsers and shows the User Manager.
89- (IBAction)exitGuest:(id)sender;
90
91// Shows the account management view.
92- (IBAction)showAccountManagement:(id)sender;
93
94// Hides the account management view and shows the default view.
95- (IBAction)hideAccountManagement:(id)sender;
96
97// Locks the active profile.
98- (IBAction)lockProfile:(id)sender;
99
100// Shows the inline signin page.
101- (IBAction)showInlineSigninPage:(id)sender;
102
103// Adds an account to the active profile.
104- (IBAction)addAccount:(id)sender;
105
106// Shows the account removal view to confirm removing the currently selected
107// account from the active profile if possible.
108- (IBAction)showAccountRemovalView:(id)sender;
109
110// Shows the account reauthentication view to re-sign in the currently selected
111// account from the active profile if possible.
112- (IBAction)showAccountReauthenticationView:(id)sender;
113
114// Removes the current account |accountIdToRemove_|.
115- (IBAction)removeAccount:(id)sender;
116
117// Reset the WebContents used by the Gaia embedded view.
118- (void)cleanUpEmbeddedViewContents;
119
120// Clean-up done after an action was performed in the ProfileChooser.
121- (void)postActionPerformed:(ProfileMetrics::ProfileDesktopMenu)action;
122@end
123
124// Testing API /////////////////////////////////////////////////////////////////
125
126@interface ProfileChooserController (ExposedForTesting)
127- (id)initWithBrowser:(Browser*)browser
128           anchoredAt:(NSPoint)point
129             viewMode:(profiles::BubbleViewMode)viewMode
130         tutorialMode:(profiles::TutorialMode)tutorialMode
131          serviceType:(signin::GAIAServiceType)GAIAServiceType;
132@end
133
134#endif  // CHROME_BROWSER_UI_COCOA_PROFILES_PROFILE_CHOOSER_CONTROLLER_H_
135