OLD | NEW |
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/network_screen.h" | 5 #include "chrome/browser/chromeos/login/network_screen.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
32 // NetworkScreen, public: | 32 // NetworkScreen, public: |
33 | 33 |
34 NetworkScreen::NetworkScreen(ScreenObserver* screen_observer, | 34 NetworkScreen::NetworkScreen(ScreenObserver* screen_observer, |
35 NetworkScreenActor* actor) | 35 NetworkScreenActor* actor) |
36 : WizardScreen(screen_observer), | 36 : WizardScreen(screen_observer), |
37 is_network_subscribed_(false), | 37 is_network_subscribed_(false), |
38 continue_pressed_(false), | 38 continue_pressed_(false), |
39 actor_(actor) { | 39 actor_(actor) { |
40 actor_->SetDelegate(this); | 40 DCHECK(actor_); |
| 41 if (actor_) |
| 42 actor_->SetDelegate(this); |
41 } | 43 } |
42 | 44 |
43 NetworkScreen::~NetworkScreen() { | 45 NetworkScreen::~NetworkScreen() { |
| 46 if (actor_) |
| 47 actor_->SetDelegate(NULL); |
44 connection_timer_.Stop(); | 48 connection_timer_.Stop(); |
45 UnsubscribeNetworkNotification(); | 49 UnsubscribeNetworkNotification(); |
46 } | 50 } |
47 | 51 |
48 //////////////////////////////////////////////////////////////////////////////// | 52 //////////////////////////////////////////////////////////////////////////////// |
49 // NetworkScreen, WizardScreen implementation: | 53 // NetworkScreen, WizardScreen implementation: |
50 | 54 |
51 void NetworkScreen::PrepareToShow() { | 55 void NetworkScreen::PrepareToShow() { |
52 actor_->PrepareToShow(); | 56 if (actor_) |
| 57 actor_->PrepareToShow(); |
53 } | 58 } |
54 | 59 |
55 void NetworkScreen::Show() { | 60 void NetworkScreen::Show() { |
56 actor_->Show(); | 61 if (actor_) |
| 62 actor_->Show(); |
57 Refresh(); | 63 Refresh(); |
58 } | 64 } |
59 | 65 |
60 void NetworkScreen::Hide() { | 66 void NetworkScreen::Hide() { |
61 actor_->Hide(); | 67 if (actor_) |
| 68 actor_->Hide(); |
62 } | 69 } |
63 | 70 |
64 std::string NetworkScreen::GetName() const { | 71 std::string NetworkScreen::GetName() const { |
65 return WizardController::kNetworkScreenName; | 72 return WizardController::kNetworkScreenName; |
66 } | 73 } |
67 | 74 |
68 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
69 // NetworkScreen, NetworkLibrary::NetworkManagerObserver implementation: | 76 // NetworkScreen, NetworkLibrary::NetworkManagerObserver implementation: |
70 | 77 |
71 void NetworkScreen::OnNetworkManagerChanged(NetworkLibrary* network_lib) { | 78 void NetworkScreen::OnNetworkManagerChanged(NetworkLibrary* network_lib) { |
72 UpdateStatus(network_lib); | 79 UpdateStatus(network_lib); |
73 } | 80 } |
74 | 81 |
75 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
76 // NetworkScreen, public: | 83 // NetworkScreen, public: |
77 | 84 |
78 void NetworkScreen::Refresh() { | 85 void NetworkScreen::Refresh() { |
79 SubscribeNetworkNotification(); | 86 SubscribeNetworkNotification(); |
80 OnNetworkManagerChanged(chromeos::CrosLibrary::Get()->GetNetworkLibrary()); | 87 OnNetworkManagerChanged(chromeos::CrosLibrary::Get()->GetNetworkLibrary()); |
81 } | 88 } |
82 | 89 |
83 /////////////////////////////////////////////////////////////////////////////// | 90 /////////////////////////////////////////////////////////////////////////////// |
84 // NetworkScreen, NetworkScreenActor::Delegate implementation: | 91 // NetworkScreen, NetworkScreenActor::Delegate implementation: |
85 | 92 |
| 93 void NetworkScreen::OnActorDestroyed(NetworkScreenActor* actor) { |
| 94 if (actor_ == actor) |
| 95 actor_ = NULL; |
| 96 } |
| 97 |
86 void NetworkScreen::OnContinuePressed() { | 98 void NetworkScreen::OnContinuePressed() { |
87 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); | 99 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); |
88 if (network && network->Connected()) { | 100 if (network && network->Connected()) { |
89 NotifyOnConnection(); | 101 NotifyOnConnection(); |
90 } else { | 102 } else { |
91 continue_pressed_ = true; | 103 continue_pressed_ = true; |
92 WaitForConnection(network_id_); | 104 WaitForConnection(network_id_); |
93 } | 105 } |
94 } | 106 } |
95 | 107 |
(...skipping 21 matching lines...) Expand all Loading... |
117 UnsubscribeNetworkNotification(); | 129 UnsubscribeNetworkNotification(); |
118 connection_timer_.Stop(); | 130 connection_timer_.Stop(); |
119 get_screen_observer()->OnExit(ScreenObserver::NETWORK_CONNECTED); | 131 get_screen_observer()->OnExit(ScreenObserver::NETWORK_CONNECTED); |
120 } | 132 } |
121 | 133 |
122 void NetworkScreen::OnConnectionTimeout() { | 134 void NetworkScreen::OnConnectionTimeout() { |
123 StopWaitingForConnection(network_id_); | 135 StopWaitingForConnection(network_id_); |
124 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); | 136 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); |
125 bool is_connected = network && network->Connected(); | 137 bool is_connected = network && network->Connected(); |
126 | 138 |
127 if (!is_connected) { | 139 if (!is_connected && actor_) { |
128 // Show error bubble. | 140 // Show error bubble. |
129 actor_->ShowError( | 141 actor_->ShowError( |
130 l10n_util::GetStringFUTF16( | 142 l10n_util::GetStringFUTF16( |
131 IDS_NETWORK_SELECTION_ERROR, | 143 IDS_NETWORK_SELECTION_ERROR, |
132 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME), | 144 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME), |
133 network_id_)); | 145 network_id_)); |
134 } | 146 } |
135 } | 147 } |
136 | 148 |
137 void NetworkScreen::UpdateStatus(NetworkLibrary* network) { | 149 void NetworkScreen::UpdateStatus(NetworkLibrary* network) { |
(...skipping 18 matching lines...) Expand all Loading... |
156 bool is_connected = network && network->Connected(); | 168 bool is_connected = network && network->Connected(); |
157 if (is_connected && continue_pressed_) { | 169 if (is_connected && continue_pressed_) { |
158 NotifyOnConnection(); | 170 NotifyOnConnection(); |
159 return; | 171 return; |
160 } | 172 } |
161 | 173 |
162 continue_pressed_ = false; | 174 continue_pressed_ = false; |
163 connection_timer_.Stop(); | 175 connection_timer_.Stop(); |
164 | 176 |
165 network_id_ = network_id; | 177 network_id_ = network_id; |
166 actor_->ShowConnectingStatus(false, network_id_); | 178 if (actor_) { |
167 actor_->EnableContinue(is_connected); | 179 actor_->ShowConnectingStatus(false, network_id_); |
| 180 actor_->EnableContinue(is_connected); |
| 181 } |
168 } | 182 } |
169 | 183 |
170 void NetworkScreen::WaitForConnection(const string16& network_id) { | 184 void NetworkScreen::WaitForConnection(const string16& network_id) { |
171 if (network_id_ != network_id || !connection_timer_.IsRunning()) { | 185 if (network_id_ != network_id || !connection_timer_.IsRunning()) { |
172 connection_timer_.Stop(); | 186 connection_timer_.Stop(); |
173 connection_timer_.Start(FROM_HERE, | 187 connection_timer_.Start(FROM_HERE, |
174 base::TimeDelta::FromSeconds(kConnectionTimeoutSec), | 188 base::TimeDelta::FromSeconds(kConnectionTimeoutSec), |
175 this, | 189 this, |
176 &NetworkScreen::OnConnectionTimeout); | 190 &NetworkScreen::OnConnectionTimeout); |
177 } | 191 } |
178 | 192 |
179 network_id_ = network_id; | 193 network_id_ = network_id; |
180 actor_->ShowConnectingStatus(continue_pressed_, network_id_); | 194 if (actor_) { |
181 | 195 actor_->ShowConnectingStatus(continue_pressed_, network_id_); |
182 actor_->EnableContinue(false); | 196 actor_->EnableContinue(false); |
| 197 } |
183 } | 198 } |
184 | 199 |
185 } // namespace chromeos | 200 } // namespace chromeos |
OLD | NEW |