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_NETWORK_SCREEN_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_
8 #include "base/compiler_specific.h"
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/strings/string16.h"
15 #include "base/timer/timer.h"
16 #include "chrome/browser/chromeos/login/screens/network_model.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chromeos/network/network_state_handler_observer.h"
19 #include "ui/base/ime/chromeos/input_method_manager.h"
23 class InputEventsBlocker
;
27 namespace locale_util
{
28 struct LanguageSwitchResult
;
32 class NetworkStateHelper
;
35 class NetworkScreen
: public NetworkModel
,
36 public NetworkStateHandlerObserver
,
37 public input_method::InputMethodManager::Observer
{
41 virtual ~Delegate() {}
43 // Called when enable debugging screen is requested.
44 virtual void OnEnableDebuggingScreenRequested() = 0;
49 virtual ~Observer() {}
51 // Called when language list is reloaded.
52 virtual void OnLanguageListReloaded() = 0;
55 NetworkScreen(BaseScreenDelegate
* base_screen_delegate
,
58 ~NetworkScreen() override
;
60 static NetworkScreen
* Get(ScreenManager
* manager
);
62 // NetworkModel implementation:
63 void PrepareToShow() override
;
66 void Initialize(::login::ScreenContext
* context
) override
;
67 void OnViewDestroyed(NetworkView
* view
) override
;
68 void OnUserAction(const std::string
& action_id
) override
;
69 void OnContextKeyUpdated(const ::login::ScreenContext::KeyType
& key
) override
;
70 std::string
GetLanguageListLocale() const override
;
71 const base::ListValue
* GetLanguageList() const override
;
72 void UpdateLanguageList() override
;
74 // NetworkStateHandlerObserver implementation:
75 void NetworkConnectionStateChanged(const NetworkState
* network
) override
;
76 void DefaultNetworkChanged(const NetworkState
* network
) override
;
78 // InputMethodManager::Observer implementation:
79 void InputMethodChanged(input_method::InputMethodManager
* manager
,
81 bool show_message
) override
;
83 void SetApplicationLocale(const std::string
& locale
);
84 std::string
GetApplicationLocale();
86 void SetInputMethod(const std::string
& input_method
);
87 std::string
GetInputMethod() const;
89 void SetTimezone(const std::string
& timezone_id
);
90 std::string
GetTimezone() const;
92 void CreateNetworkFromOnc(const std::string
& onc_spec
);
94 void AddObserver(Observer
* observer
);
95 void RemoveObserver(Observer
* observer
);
98 friend class NetworkScreenTest
;
99 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest
, Timeout
);
100 FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest
, CanConnect
);
102 // Subscribe to timezone changes.
103 void InitializeTimezoneObserver();
105 // Subscribes NetworkScreen to the network change notification,
106 // forces refresh of current network state.
109 // Sets the NetworkStateHelper for use in tests. This
110 // class will take ownership of the pointed object.
111 void SetNetworkStateHelperForTest(login::NetworkStateHelper
* helper
);
113 // Subscribes to network change notifications.
114 void SubscribeNetworkNotification();
116 // Unsubscribes from network change notifications.
117 void UnsubscribeNetworkNotification();
119 // Notifies wizard on successful connection.
120 void NotifyOnConnection();
122 // Called by |connection_timer_| when connection to the network timed out.
123 void OnConnectionTimeout();
125 // Update UI based on current network status.
128 // Stops waiting for network to connect.
129 void StopWaitingForConnection(const base::string16
& network_id
);
131 // Starts waiting for network connection. Shows spinner.
132 void WaitForConnection(const base::string16
& network_id
);
134 // Called when continue button is pressed.
135 void OnContinueButtonPressed();
137 // Async callback after ReloadResourceBundle(locale) completed.
138 void OnLanguageChangedCallback(
139 const InputEventsBlocker
* input_events_blocker
,
140 const locale_util::LanguageSwitchResult
& result
);
142 // Starts resolving language list on BlockingPool.
143 void ScheduleResolveLanguageList(
144 scoped_ptr
<locale_util::LanguageSwitchResult
> language_switch_result
);
146 // Callback for chromeos::ResolveUILanguageList() (from l10n_util).
147 void OnLanguageListResolved(scoped_ptr
<base::ListValue
> new_language_list
,
148 std::string new_language_list_locale
,
149 std::string new_selected_language
);
151 // Callback when the system timezone settings is changed.
152 void OnSystemTimezoneChanged();
154 // True if subscribed to network change notification.
155 bool is_network_subscribed_
;
157 // ID of the the network that we are waiting for.
158 base::string16 network_id_
;
160 // True if user pressed continue button so we should proceed with OOBE
161 // as soon as we are connected.
162 bool continue_pressed_
;
164 // Timer for connection timeout.
165 base::OneShotTimer
<NetworkScreen
> connection_timer_
;
167 scoped_ptr
<CrosSettings::ObserverSubscription
> timezone_subscription_
;
171 scoped_ptr
<login::NetworkStateHelper
> network_state_helper_
;
173 std::string input_method_
;
174 std::string timezone_
;
176 // Creation of language list happens on Blocking Pool, so we cache
178 std::string language_list_locale_
;
179 scoped_ptr
<base::ListValue
> language_list_
;
181 // The exact language code selected by user in the menu.
182 std::string selected_language_code_
;
184 base::ObserverList
<Observer
> observers_
;
186 base::WeakPtrFactory
<NetworkScreen
> weak_factory_
;
188 DISALLOW_COPY_AND_ASSIGN(NetworkScreen
);
191 } // namespace chromeos
193 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SCREENS_NETWORK_SCREEN_H_