• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SCREEN_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SCREEN_MANAGER_H_
7 
8 #include <map>
9 #include <stack>
10 #include <string>
11 
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"
16 
17 namespace chromeos {
18 
19 class BaseScreen;
20 class OobeDisplay;
21 class ScreenContext;
22 class ScreenFactory;
23 class ScreenFlow;
24 
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();
33 
34   // Creates and initializes screen, without showing it.
35   void WarmupScreen(const std::string& id,
36                     ScreenContext* context);
37 
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);
42 
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);
48 
49   // Creates, initializes and shows a popup screen identified by |id|.
50   void PopupScreen(const std::string& id);
51 
52   // Creates, initializes with |context| and shows a popup screen identified
53   // by |id|.
54   void PopupScreenWithParameters(const std::string& id,
55                                  ScreenContext* context);
56 
57   // Hides the popup screen identified by |screen_id|.
58   void HidePopupScreen(const std::string& screen_id);
59 
60   std::string GetCurrentScreenId();
61 
62   // Sets new screen flow.
63   void SetScreenFlow(ScreenFlow* flow);
64 
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);
71 
72   void TearDownTopmostScreen();
73 
74   void OnDisplayIsReady();
75 
76   BaseScreen* GetTopmostScreen();
77   BaseScreen* FindOrCreateScreen(const std::string& id);
78 
79   // Helper method which simply calls corresponding method on the
80   // screen if it exists
81   template<typename A1>
CallOnScreen(const std::string & screen_name,void (BaseScreen::* method)(A1 arg1),A1 arg1)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();
91     }
92   }
93 
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 DictionaryValue* diff) OVERRIDE;
99 
100   typedef std::map<std::string, linked_ptr<BaseScreen> > ScreenMap;
101 
102   // Factory of screens.
103   scoped_ptr<ScreenFactory> factory_;
104 
105   // Root of all screen handlers.
106   OobeDisplay* display_;
107 
108   // Current screen flow.
109   scoped_ptr<ScreenFlow> flow_;
110 
111   base::WeakPtrFactory<ScreenManager> weak_factory_;
112 
113   // Map of existing screens. All screen instances are owned by screen manager.
114   ScreenMap existing_screens_;
115 
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_;
119 
120   // Flag that indicates if JS counterpart is fully initialized.
121   bool js_is_ready_;
122 
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_;
128 
129   DISALLOW_COPY_AND_ASSIGN(ScreenManager);
130 };
131 
132 }  // namespace chromeos
133 
134 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_SCREEN_MANAGER_H_
135