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

Side by Side Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 10554013: Add a CONNECT_REQUESTED state to Network ConnectionState. (Closed) Base URL: http://git.chromium.org/git/chromium/src@master
Patch Set: Rebase Created 8 years, 6 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/cros/network_library.h" 5 #include "chrome/browser/chromeos/cros/network_library.h"
6 6
7 #include <dbus/dbus-glib.h> 7 #include <dbus/dbus-glib.h>
8 8
9 #include "base/i18n/icu_encoding_detection.h" 9 #include "base/i18n/icu_encoding_detection.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(), 127 bool is_unicode_char = base::ReadUnicodeCharacter(str.c_str(), str.size(),
128 &index, &code_point_out); 128 &index, &code_point_out);
129 if (is_unicode_char && (code_point_out >= 0x20)) 129 if (is_unicode_char && (code_point_out >= 0x20))
130 base::WriteUnicodeCharacter(code_point_out, output); 130 base::WriteUnicodeCharacter(code_point_out, output);
131 else 131 else
132 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8 132 // Puts REPLACEMENT CHARACTER (U+FFFD) if character is not readable UTF-8
133 base::WriteUnicodeCharacter(0xFFFD, output); 133 base::WriteUnicodeCharacter(0xFFFD, output);
134 } 134 }
135 } 135 }
136 136
137 std::string ConnectionStateString(ConnectionState state) {
138 switch (state) {
139 case STATE_UNKNOWN:
140 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNKNOWN);
141 case STATE_IDLE:
142 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_IDLE);
143 case STATE_CARRIER:
144 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_CARRIER);
145 case STATE_ASSOCIATION:
146 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_ASSOCIATION);
147 case STATE_CONFIGURATION:
148 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_CONFIGURATION);
149 case STATE_READY:
150 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_READY);
151 case STATE_DISCONNECT:
152 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_DISCONNECT);
153 case STATE_FAILURE:
154 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_FAILURE);
155 case STATE_ACTIVATION_FAILURE:
156 return l10n_util::GetStringUTF8(
157 IDS_CHROMEOS_NETWORK_STATE_ACTIVATION_FAILURE);
158 case STATE_PORTAL:
159 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_PORTAL);
160 case STATE_ONLINE:
161 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_ONLINE);
162 case STATE_CONNECT_REQUESTED:
163 return l10n_util::GetStringUTF8(
164 IDS_CHROMEOS_NETWORK_STATE_CONNECT_REQUESTED);
165 }
166 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED);
167 }
168
137 } // namespace 169 } // namespace
138 170
139 //////////////////////////////////////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////////
140 // FoundCellularNetwork 172 // FoundCellularNetwork
141 173
142 FoundCellularNetwork::FoundCellularNetwork() {} 174 FoundCellularNetwork::FoundCellularNetwork() {}
143 175
144 FoundCellularNetwork::~FoundCellularNetwork() {} 176 FoundCellularNetwork::~FoundCellularNetwork() {}
145 177
146 //////////////////////////////////////////////////////////////////////////////// 178 ////////////////////////////////////////////////////////////////////////////////
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 delete iter->second; 250 delete iter->second;
219 property_map_.erase(iter); 251 property_map_.erase(iter);
220 } 252 }
221 return; 253 return;
222 } 254 }
223 255
224 // Add the property to property_map_. Delete previous value if necessary. 256 // Add the property to property_map_. Delete previous value if necessary.
225 Value*& entry = property_map_[index]; 257 Value*& entry = property_map_[index];
226 delete entry; 258 delete entry;
227 entry = value->DeepCopy(); 259 entry = value->DeepCopy();
228 if (VLOG_IS_ON(2)) { 260 if (VLOG_IS_ON(3)) {
229 std::string value_json; 261 std::string value_json;
230 base::JSONWriter::WriteWithOptions(value, 262 base::JSONWriter::WriteWithOptions(value,
231 base::JSONWriter::OPTIONS_PRETTY_PRINT, 263 base::JSONWriter::OPTIONS_PRETTY_PRINT,
232 &value_json); 264 &value_json);
233 VLOG(2) << "Updated property map on network: " 265 VLOG(3) << "Updated property map on network: "
234 << unique_id() << "[" << index << "] = " << value_json; 266 << unique_id() << "[" << index << "] = " << value_json;
235 } 267 }
236 } 268 }
237 269
238 bool Network::GetProperty(PropertyIndex index, 270 bool Network::GetProperty(PropertyIndex index,
239 const base::Value** value) const { 271 const base::Value** value) const {
240 PropertyMap::const_iterator i = property_map_.find(index); 272 PropertyMap::const_iterator i = property_map_.find(index);
241 if (i == property_map_.end()) 273 if (i == property_map_.end())
242 return false; 274 return false;
243 if (value != NULL) 275 if (value != NULL)
244 *value = i->second; 276 *value = i->second;
245 return true; 277 return true;
246 } 278 }
247 279
248 // static 280 // static
249 Network* Network::CreateForTesting(ConnectionType type) { 281 Network* Network::CreateForTesting(ConnectionType type) {
250 return new Network("fake_service_path", type); 282 return new Network("fake_service_path", type);
251 } 283 }
252 284
253 void Network::SetState(ConnectionState new_state) { 285 void Network::SetState(ConnectionState new_state) {
254 if (new_state == state_) 286 if (new_state == state_)
255 return; 287 return;
288 if (state_ == STATE_CONNECT_REQUESTED && new_state == STATE_IDLE) {
289 // CONNECT_REQUESTED is set internally. Shill/flimflam do not update the
290 // state immediately, so ignore any Idle state updates sent while a
291 // connection attempt is in progress.
292 return;
293 }
256 ConnectionState old_state = state_; 294 ConnectionState old_state = state_;
257 state_ = new_state; 295 state_ = new_state;
258 if (!IsConnectingState(new_state)) 296 if (!IsConnectingState(new_state))
259 set_connection_started(false); 297 set_connection_started(false);
260 if (new_state == STATE_FAILURE) { 298 if (new_state == STATE_FAILURE) {
261 if (old_state != STATE_UNKNOWN && 299 if (old_state != STATE_UNKNOWN &&
262 old_state != STATE_IDLE) { 300 old_state != STATE_IDLE) {
263 // New failure, the user needs to be notified. 301 // New failure, the user needs to be notified.
264 // Transition STATE_IDLE -> STATE_FAILURE sometimes happens on resume 302 // Transition STATE_IDLE -> STATE_FAILURE sometimes happens on resume
265 // but is not an actual failure as network device is not ready yet. 303 // but is not an actual failure as network device is not ready yet.
266 notify_failure_ = true; 304 notify_failure_ = true;
267 // Normally error_ should be set, but if it is not we need to set it to 305 // Normally error_ should be set, but if it is not we need to set it to
268 // something here so that the retry logic will be triggered. 306 // something here so that the retry logic will be triggered.
269 if (error_ == ERROR_NO_ERROR) 307 if (error_ == ERROR_NO_ERROR)
270 error_ = ERROR_UNKNOWN; 308 error_ = ERROR_UNKNOWN;
271 } 309 }
272 } else { 310 } else {
273 // State changed, so refresh IP address. 311 // State changed, so refresh IP address.
274 // Note: blocking DBus call. TODO(stevenjb): refactor this. 312 // Note: blocking DBus call. TODO(stevenjb): refactor this.
275 InitIPAddress(); 313 InitIPAddress();
276 } 314 }
277 VLOG(1) << name() << ".State = " << GetStateString(); 315 VLOG(1) << name() << ".State [" << service_path() << "]: " << GetStateString()
316 << " (was: " << ConnectionStateString(old_state) << ")";
278 } 317 }
279 318
280 void Network::SetName(const std::string& name) { 319 void Network::SetName(const std::string& name) {
281 std::string name_utf8; 320 std::string name_utf8;
282 ValidateUTF8(name, &name_utf8); 321 ValidateUTF8(name, &name_utf8);
283 set_name(name_utf8); 322 set_name(name_utf8);
284 } 323 }
285 324
286 void Network::ParseInfo(const DictionaryValue& info) { 325 void Network::ParseInfo(const DictionaryValue& info) {
287 if (network_parser_.get()) 326 if (network_parser_.get())
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 closure.Run(); 421 closure.Run();
383 } 422 }
384 423
385 void Network::SetProfilePath(const std::string& profile_path) { 424 void Network::SetProfilePath(const std::string& profile_path) {
386 VLOG(1) << "Setting profile for: " << name_ << " to: " << profile_path; 425 VLOG(1) << "Setting profile for: " << name_ << " to: " << profile_path;
387 SetOrClearStringProperty( 426 SetOrClearStringProperty(
388 flimflam::kProfileProperty, profile_path, &profile_path_); 427 flimflam::kProfileProperty, profile_path, &profile_path_);
389 } 428 }
390 429
391 std::string Network::GetStateString() const { 430 std::string Network::GetStateString() const {
392 switch (state_) { 431 return ConnectionStateString(state_);
393 case STATE_UNKNOWN:
394 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNKNOWN);
395 case STATE_IDLE:
396 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_IDLE);
397 case STATE_CARRIER:
398 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_CARRIER);
399 case STATE_ASSOCIATION:
400 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_ASSOCIATION);
401 case STATE_CONFIGURATION:
402 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_CONFIGURATION);
403 case STATE_READY:
404 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_READY);
405 case STATE_DISCONNECT:
406 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_DISCONNECT);
407 case STATE_FAILURE:
408 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_FAILURE);
409 case STATE_ACTIVATION_FAILURE:
410 return l10n_util::GetStringUTF8(
411 IDS_CHROMEOS_NETWORK_STATE_ACTIVATION_FAILURE);
412 case STATE_PORTAL:
413 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_PORTAL);
414 case STATE_ONLINE:
415 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_ONLINE);
416 }
417 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED);
418 } 432 }
419 433
420 std::string Network::GetErrorString() const { 434 std::string Network::GetErrorString() const {
421 switch (error_) { 435 switch (error_) {
422 case ERROR_NO_ERROR: 436 case ERROR_NO_ERROR:
423 // TODO(nkostylev): Introduce new error message "None" instead. 437 // TODO(nkostylev): Introduce new error message "None" instead.
424 return std::string(); 438 return std::string();
425 case ERROR_OUT_OF_RANGE: 439 case ERROR_OUT_OF_RANGE:
426 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); 440 return l10n_util::GetStringUTF8(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE);
427 case ERROR_PIN_MISSING: 441 case ERROR_PIN_MISSING:
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 NetworkLibrary* impl; 1313 NetworkLibrary* impl;
1300 if (stub) 1314 if (stub)
1301 impl = new NetworkLibraryImplStub(); 1315 impl = new NetworkLibraryImplStub();
1302 else 1316 else
1303 impl = new NetworkLibraryImplCros(); 1317 impl = new NetworkLibraryImplCros();
1304 impl->Init(); 1318 impl->Init();
1305 return impl; 1319 return impl;
1306 } 1320 }
1307 1321
1308 } // namespace chromeos 1322 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/network_library.h ('k') | chrome/browser/chromeos/cros/network_library_impl_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698