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

Unified Diff: chromeos/network/device_state.cc

Issue 11192024: Add chromeos::NetworkStateManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to feedback Round 2 Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/network/device_state.cc
diff --git a/chromeos/network/device_state.cc b/chromeos/network/device_state.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d3b20729791e28a0570baaadbb1a83bfb444e3a4
--- /dev/null
+++ b/chromeos/network/device_state.cc
@@ -0,0 +1,76 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chromeos/network/device_state.h"
+
+#include "base/logging.h"
+#include "base/stringprintf.h"
+#include "base/values.h"
+#include "third_party/cros_system_api/dbus/service_constants.h"
+
+namespace {
+
+// List of cellular operators names that should have data roaming always enabled
+// to be able to connect to any network.
+const char* kAlwaysInRoamingOperators[] = {
+ "CUBIC",
gauravsh 2012/10/25 23:41:05 Where does this list come from? Should it be in se
stevenjb 2012/10/26 21:36:39 Actually, this was recently replaced in NetworkLib
+ "Cubic",
+};
+
+} // namespace
+
+namespace chromeos {
+
+DeviceState::DeviceState(const std::string& path)
+ : ManagedState(MANAGED_TYPE_DEVICE, path),
+ always_in_roaming_(false),
+ support_network_scan_(false) {
+}
+
+bool DeviceState::PropertyChanged(const std::string& key,
+ const base::Value& value) {
+ if (key == flimflam::kNameProperty) {
gauravsh 2012/10/25 23:41:05 Do you expect to add more properties, or does this
stevenjb 2012/10/26 21:36:39 Don't know. This covers (almost all of) the status
+ return value.GetAsString(&name_);
+ } else if (key == flimflam::kTypeProperty) {
+ return value.GetAsString(&type_);
+ } else if (key == flimflam::kAddressProperty) {
+ bool res = value.GetAsString(&mac_address_);
+ LOG(ERROR) << "Hardware Address: " << mac_address_;
gauravsh 2012/10/25 23:41:05 Why is this a LOG(ERROR)?
stevenjb 2012/10/26 21:36:39 Leftover debugging. Removed.
+ return res;
+ } else if (key == flimflam::kSupportNetworkScanProperty) {
+ return value.GetAsBoolean(&support_network_scan_);
+ } else if (key == flimflam::kHomeProviderProperty) {
+ const DictionaryValue* dict = NULL;
+ if (value.GetAsDictionary(&dict)) {
+ std::string home_provider_country;
+ std::string home_provider_name;
+ dict->GetStringWithoutPathExpansion(flimflam::kOperatorCountryKey,
+ &home_provider_country);
+ dict->GetStringWithoutPathExpansion(flimflam::kOperatorNameKey,
+ &home_provider_name);
+ // Set always_in_roaming_
+ for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) {
gauravsh 2012/10/25 23:41:05 You could also consider using find() here.
stevenjb 2012/10/26 21:36:39 Removed.
+ if (home_provider_name == kAlwaysInRoamingOperators[i])
+ always_in_roaming_ = true;
+ }
+ // Set home_provider_id_
+ if (!home_provider_name.empty() && !home_provider_country.empty()) {
+ home_provider_id_ = base::StringPrintf(
+ "%s (%s)",
+ home_provider_name.c_str(),
+ home_provider_country.c_str());
+ } else {
+ dict->GetStringWithoutPathExpansion(flimflam::kOperatorCodeKey,
+ &home_provider_id_);
+ LOG(WARNING) << "Carrier ID not defined, using code instead: "
+ << home_provider_id_;
+ }
+ } else {
+ return false;
gauravsh 2012/10/25 23:41:05 LOG a warning with the unknown key?
stevenjb 2012/10/26 21:36:39 No warning necessary, this is not intended to hand
+ }
+ }
+ return true;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698