Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / screen_manager.h
blob448bc5f19baca0e09bab27742c2c5b32bef02d38
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SCREEN_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SCREEN_MANAGER_H_
8 #include <map>
9 #include <stack>
10 #include <string>
12 #include "base/memory/linked_ptr.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/ui/webui/chromeos/login/screen_manager_handler.h"
17 namespace chromeos {
19 class BaseScreen;
20 class OobeDisplay;
21 class ScreenContext;
22 class ScreenFactory;
23 class ScreenFlow;
25 // Class that manages screen states and flow.
26 // TODO(antrim): add implementation details comments.
27 class ScreenManager : public ScreenManagerHandler::Delegate {
28 public:
29 ScreenManager(ScreenFactory* factory,
30 OobeDisplay* oobe_display,
31 ScreenFlow* initial_flow);
32 virtual ~ScreenManager();
34 // Creates and initializes screen, without showing it.
35 void WarmupScreen(const std::string& id,
36 ScreenContext* context);
38 // Creates, initializes and shows a screen identified by |id|.
39 // Should be called when no popup screens are displayed.
40 // Closes the previous screen.
41 void ShowScreen(const std::string& id);
43 // Creates, initializes with |context| and shows a screen identified by |id|.
44 // Should be called when no popup screens are displayed.
45 // Closes the previous screen.
46 void ShowScreenWithParameters(const std::string& id,
47 ScreenContext* context);
49 // Creates, initializes and shows a popup screen identified by |id|.
50 void PopupScreen(const std::string& id);
52 // Creates, initializes with |context| and shows a popup screen identified
53 // by |id|.
54 void PopupScreenWithParameters(const std::string& id,
55 ScreenContext* context);
57 // Hides the popup screen identified by |screen_id|.
58 void HidePopupScreen(const std::string& screen_id);
60 std::string GetCurrentScreenId();
62 // Sets new screen flow.
63 void SetScreenFlow(ScreenFlow* flow);
65 private:
66 void ShowScreenImpl(const std::string& id,
67 ScreenContext* context,
68 bool isPopup);
69 void TransitionScreen(const std::string& from_id,
70 const std::string& to_id);
72 void TearDownTopmostScreen();
74 void OnDisplayIsReady();
76 BaseScreen* GetTopmostScreen();
77 BaseScreen* FindOrCreateScreen(const std::string& id);
79 // Helper method which simply calls corresponding method on the
80 // screen if it exists
81 template<typename A1>
82 void CallOnScreen(const std::string& screen_name,
83 void (BaseScreen::*method)(A1 arg1),
84 A1 arg1) {
85 ScreenMap::const_iterator it = existing_screens_.find(screen_name);
86 if (it != existing_screens_.end()) {
87 BaseScreen* screen = it->second.get();
88 (screen->*method)(arg1);
89 } else {
90 NOTREACHED();
94 // ScreenManagerHandler::Delegate implementation:
95 virtual void OnButtonPressed(const std::string& screen_name,
96 const std::string& button_id) OVERRIDE;
97 virtual void OnContextChanged(const std::string& screen_name,
98 const base::DictionaryValue* diff) OVERRIDE;
100 typedef std::map<std::string, linked_ptr<BaseScreen> > ScreenMap;
102 // Factory of screens.
103 scoped_ptr<ScreenFactory> factory_;
105 // Root of all screen handlers.
106 OobeDisplay* display_;
108 // Current screen flow.
109 scoped_ptr<ScreenFlow> flow_;
111 base::WeakPtrFactory<ScreenManager> weak_factory_;
113 // Map of existing screens. All screen instances are owned by screen manager.
114 ScreenMap existing_screens_;
116 // Current stack of screens (screen ids, all screens are assumed to have an
117 // instance in |existing_screens_|. Only topmost screen is visible.
118 std::stack<std::string> screen_stack_;
120 // Flag that indicates if JS counterpart is fully initialized.
121 bool js_is_ready_;
123 // Capture of parameters for ShowScreen() if it was called before JS
124 // counterpart is fully initialized.
125 std::string start_screen_;
126 scoped_ptr<ScreenContext> start_screen_params_;
127 bool start_screen_popup_;
129 DISALLOW_COPY_AND_ASSIGN(ScreenManager);
132 } // namespace chromeos
134 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SCREEN_MANAGER_H_