Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: chrome/browser/chromeos/login/screens/network_screen.cc

Issue 2649873009: cros: Fold NetworkModel into NetworkScreen (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/login/screens/network_screen.h" 5 #include "chrome/browser/chromeos/login/screens/network_screen.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 19 matching lines...) Expand all
30 #include "chromeos/network/network_state_handler.h" 30 #include "chromeos/network/network_state_handler.h"
31 #include "components/prefs/pref_service.h" 31 #include "components/prefs/pref_service.h"
32 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
33 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
34 34
35 namespace { 35 namespace {
36 36
37 // Time in seconds for connection timeout. 37 // Time in seconds for connection timeout.
38 const int kConnectionTimeoutSec = 40; 38 const int kConnectionTimeoutSec = 40;
39 39
40 constexpr const char kUserActionContinueButtonClicked[] = "continue";
41 constexpr const char kUserActionConnectDebuggingFeaturesClicked[] =
42 "connect-debugging-features";
43 constexpr const char kContextKeyLocale[] = "locale";
44 constexpr const char kContextKeyInputMethod[] = "input-method";
45 constexpr const char kContextKeyTimezone[] = "timezone";
46 constexpr const char kContextKeyContinueButtonEnabled[] =
47 "continue-button-enabled";
48
40 } // namespace 49 } // namespace
41 50
42 namespace chromeos { 51 namespace chromeos {
43 52
44 /////////////////////////////////////////////////////////////////////////////// 53 ///////////////////////////////////////////////////////////////////////////////
45 // NetworkScreen, public: 54 // NetworkScreen, public:
46 55
47 // static 56 // static
48 NetworkScreen* NetworkScreen::Get(ScreenManager* manager) { 57 NetworkScreen* NetworkScreen::Get(ScreenManager* manager) {
49 return static_cast<NetworkScreen*>( 58 return static_cast<NetworkScreen*>(
50 manager->GetScreen(OobeScreen::SCREEN_OOBE_NETWORK)); 59 manager->GetScreen(OobeScreen::SCREEN_OOBE_NETWORK));
51 } 60 }
52 61
53 NetworkScreen::NetworkScreen(BaseScreenDelegate* base_screen_delegate, 62 NetworkScreen::NetworkScreen(BaseScreenDelegate* base_screen_delegate,
54 Delegate* delegate, 63 Delegate* delegate,
55 NetworkView* view) 64 NetworkView* view)
56 : NetworkModel(base_screen_delegate), 65 : BaseScreen(base_screen_delegate, OobeScreen::SCREEN_OOBE_NETWORK),
57 is_network_subscribed_(false),
58 continue_pressed_(false),
59 view_(view), 66 view_(view),
60 delegate_(delegate), 67 delegate_(delegate),
61 network_state_helper_(new login::NetworkStateHelper), 68 network_state_helper_(new login::NetworkStateHelper),
62 weak_factory_(this) { 69 weak_factory_(this) {
63 if (view_) 70 if (view_)
64 view_->Bind(*this); 71 view_->Bind(this);
65 72
66 input_method::InputMethodManager::Get()->AddObserver(this); 73 input_method::InputMethodManager::Get()->AddObserver(this);
67 InitializeTimezoneObserver(); 74 InitializeTimezoneObserver();
68 OnSystemTimezoneChanged(); 75 OnSystemTimezoneChanged();
69 UpdateLanguageList(); 76 UpdateLanguageList();
70 } 77 }
71 78
72 NetworkScreen::~NetworkScreen() { 79 NetworkScreen::~NetworkScreen() {
73 if (view_) 80 if (view_)
74 view_->Unbind(); 81 view_->Unbind();
75 connection_timer_.Stop(); 82 connection_timer_.Stop();
76 UnsubscribeNetworkNotification(); 83 UnsubscribeNetworkNotification();
77 84
78 input_method::InputMethodManager::Get()->RemoveObserver(this); 85 input_method::InputMethodManager::Get()->RemoveObserver(this);
79 } 86 }
80 87
81 //////////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////////
82 // NetworkScreen, NetworkModel implementation: 89 // NetworkScreen, public API, setters and getters for input method and timezone.
83
84 void NetworkScreen::Show() {
85 Refresh();
86
87 // Here we should handle default locales, for which we do not have UI
88 // resources. This would load fallback, but properly show "selected" locale
89 // in the UI.
90 if (selected_language_code_.empty()) {
91 const StartupCustomizationDocument* startup_manifest =
92 StartupCustomizationDocument::GetInstance();
93 SetApplicationLocale(startup_manifest->initial_locale_default());
94 }
95
96 if (!timezone_subscription_)
97 InitializeTimezoneObserver();
98
99 if (view_)
100 view_->Show();
101 }
102
103 void NetworkScreen::Hide() {
104 timezone_subscription_.reset();
105 if (view_)
106 view_->Hide();
107 }
108 90
109 void NetworkScreen::OnViewDestroyed(NetworkView* view) { 91 void NetworkScreen::OnViewDestroyed(NetworkView* view) {
110 if (view_ == view) { 92 if (view_ == view) {
111 view_ = nullptr; 93 view_ = nullptr;
112 timezone_subscription_.reset(); 94 timezone_subscription_.reset();
113 // Ownership of NetworkScreen is complicated; ensure that we remove 95 // Ownership of NetworkScreen is complicated; ensure that we remove
114 // this as a NetworkStateHandler observer when the view is destroyed. 96 // this as a NetworkStateHandler observer when the view is destroyed.
115 UnsubscribeNetworkNotification(); 97 UnsubscribeNetworkNotification();
116 } 98 }
117 } 99 }
118 100
119 void NetworkScreen::OnUserAction(const std::string& action_id) {
120 if (action_id == kUserActionContinueButtonClicked) {
121 OnContinueButtonPressed();
122 } else if (action_id == kUserActionConnectDebuggingFeaturesClicked) {
123 if (delegate_)
124 delegate_->OnEnableDebuggingScreenRequested();
125 } else {
126 BaseScreen::OnUserAction(action_id);
127 }
128 }
129
130 void NetworkScreen::OnContextKeyUpdated(
131 const ::login::ScreenContext::KeyType& key) {
132 if (key == kContextKeyLocale)
133 SetApplicationLocale(context_.GetString(kContextKeyLocale));
134 else if (key == kContextKeyInputMethod)
135 SetInputMethod(context_.GetString(kContextKeyInputMethod));
136 else if (key == kContextKeyTimezone)
137 SetTimezone(context_.GetString(kContextKeyTimezone));
138 else
139 NetworkModel::OnContextKeyUpdated(key);
140 }
141
142 std::string NetworkScreen::GetLanguageListLocale() const {
143 return language_list_locale_;
144 }
145
146 const base::ListValue* NetworkScreen::GetLanguageList() const {
147 return language_list_.get();
148 }
149 101
150 void NetworkScreen::UpdateLanguageList() { 102 void NetworkScreen::UpdateLanguageList() {
151 ScheduleResolveLanguageList( 103 ScheduleResolveLanguageList(
152 std::unique_ptr<locale_util::LanguageSwitchResult>()); 104 std::unique_ptr<locale_util::LanguageSwitchResult>());
153 } 105 }
154 106
155 ////////////////////////////////////////////////////////////////////////////////
156 // NetworkScreen, NetworkStateHandlerObserver implementation:
157
158 void NetworkScreen::NetworkConnectionStateChanged(const NetworkState* network) {
159 UpdateStatus();
160 }
161
162 void NetworkScreen::DefaultNetworkChanged(const NetworkState* network) {
163 UpdateStatus();
164 }
165
166 ////////////////////////////////////////////////////////////////////////////////
167 // NetworkScreen, InputMethodManager::Observer implementation:
168
169 void NetworkScreen::InputMethodChanged(
170 input_method::InputMethodManager* manager,
171 Profile* /* proflie */,
172 bool /* show_message */) {
173 GetContextEditor().SetString(
174 kContextKeyInputMethod,
175 manager->GetActiveIMEState()->GetCurrentInputMethod().id());
176 }
177
178 ////////////////////////////////////////////////////////////////////////////////
179 // NetworkScreen, setters and getters for input method and timezone.
180
181 void NetworkScreen::SetApplicationLocaleAndInputMethod( 107 void NetworkScreen::SetApplicationLocaleAndInputMethod(
182 const std::string& locale, 108 const std::string& locale,
183 const std::string& input_method) { 109 const std::string& input_method) {
184 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 110 const std::string& app_locale = g_browser_process->GetApplicationLocale();
185 if (app_locale == locale || locale.empty()) { 111 if (app_locale == locale || locale.empty()) {
186 // If the locale doesn't change, set input method directly. 112 // If the locale doesn't change, set input method directly.
187 SetInputMethod(input_method); 113 SetInputMethod(input_method);
188 return; 114 return;
189 } 115 }
190 116
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if (observer) 164 if (observer)
239 observers_.AddObserver(observer); 165 observers_.AddObserver(observer);
240 } 166 }
241 167
242 void NetworkScreen::RemoveObserver(Observer* observer) { 168 void NetworkScreen::RemoveObserver(Observer* observer) {
243 if (observer) 169 if (observer)
244 observers_.RemoveObserver(observer); 170 observers_.RemoveObserver(observer);
245 } 171 }
246 172
247 //////////////////////////////////////////////////////////////////////////////// 173 ////////////////////////////////////////////////////////////////////////////////
174 // BaseScreen implementation:
achuithb 2017/01/27 01:20:54 This chunk of code just moved right? No changes?
jdufault 2017/01/27 23:57:43 Yep
175
176 void NetworkScreen::Show() {
177 Refresh();
178
179 // Here we should handle default locales, for which we do not have UI
180 // resources. This would load fallback, but properly show "selected" locale
181 // in the UI.
182 if (selected_language_code_.empty()) {
183 const StartupCustomizationDocument* startup_manifest =
184 StartupCustomizationDocument::GetInstance();
185 SetApplicationLocale(startup_manifest->initial_locale_default());
186 }
187
188 if (!timezone_subscription_)
189 InitializeTimezoneObserver();
190
191 if (view_)
192 view_->Show();
193 }
194
195 void NetworkScreen::Hide() {
196 timezone_subscription_.reset();
197 if (view_)
198 view_->Hide();
199 }
200
201 void NetworkScreen::OnUserAction(const std::string& action_id) {
202 if (action_id == kUserActionContinueButtonClicked) {
203 OnContinueButtonPressed();
204 } else if (action_id == kUserActionConnectDebuggingFeaturesClicked) {
205 if (delegate_)
206 delegate_->OnEnableDebuggingScreenRequested();
207 } else {
208 BaseScreen::OnUserAction(action_id);
209 }
210 }
211
212 void NetworkScreen::OnContextKeyUpdated(
213 const ::login::ScreenContext::KeyType& key) {
214 if (key == kContextKeyLocale)
215 SetApplicationLocale(context_.GetString(kContextKeyLocale));
216 else if (key == kContextKeyInputMethod)
217 SetInputMethod(context_.GetString(kContextKeyInputMethod));
218 else if (key == kContextKeyTimezone)
219 SetTimezone(context_.GetString(kContextKeyTimezone));
220 else
221 BaseScreen::OnContextKeyUpdated(key);
222 }
223
224 ////////////////////////////////////////////////////////////////////////////////
225 // NetworkScreen, NetworkStateHandlerObserver implementation:
226
227 void NetworkScreen::NetworkConnectionStateChanged(const NetworkState* network) {
228 UpdateStatus();
229 }
230
231 void NetworkScreen::DefaultNetworkChanged(const NetworkState* network) {
232 UpdateStatus();
233 }
234
235 ////////////////////////////////////////////////////////////////////////////////
236 // NetworkScreen, InputMethodManager::Observer implementation:
237
238 void NetworkScreen::InputMethodChanged(
239 input_method::InputMethodManager* manager,
240 Profile* /* proflie */,
241 bool /* show_message */) {
242 GetContextEditor().SetString(
243 kContextKeyInputMethod,
244 manager->GetActiveIMEState()->GetCurrentInputMethod().id());
245 }
246
247 ////////////////////////////////////////////////////////////////////////////////
248 // NetworkScreen, private: 248 // NetworkScreen, private:
249 249
250 void NetworkScreen::SetApplicationLocale(const std::string& locale) { 250 void NetworkScreen::SetApplicationLocale(const std::string& locale) {
251 const std::string& app_locale = g_browser_process->GetApplicationLocale(); 251 const std::string& app_locale = g_browser_process->GetApplicationLocale();
252 if (app_locale == locale || locale.empty()) 252 if (app_locale == locale || locale.empty())
253 return; 253 return;
254 254
255 // Block UI while resource bundle is being reloaded. 255 // Block UI while resource bundle is being reloaded.
256 // (InputEventsBlocker will live until callback is finished.) 256 // (InputEventsBlocker will live until callback is finished.)
257 locale_util::SwitchLanguageCallback callback(base::Bind( 257 locale_util::SwitchLanguageCallback callback(base::Bind(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 observer.OnLanguageListReloaded(); 440 observer.OnLanguageListReloaded();
441 } 441 }
442 442
443 void NetworkScreen::OnSystemTimezoneChanged() { 443 void NetworkScreen::OnSystemTimezoneChanged() {
444 std::string current_timezone_id; 444 std::string current_timezone_id;
445 CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id); 445 CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
446 GetContextEditor().SetString(kContextKeyTimezone, current_timezone_id); 446 GetContextEditor().SetString(kContextKeyTimezone, current_timezone_id);
447 } 447 }
448 448
449 } // namespace chromeos 449 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698