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

Side by Side Diff: chromeos/network/cros_network_functions.cc

Issue 11756002: Move cros_network_functions.cc to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clang fixes Created 7 years, 11 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 | Annotate | Revision Log
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/cros_network_functions.h" 5 #include "chromeos/network/cros_network_functions.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_tokenizer.h"
11 #include "base/stringprintf.h"
12 #include "base/values.h" 10 #include "base/values.h"
13 #include "chrome/browser/chromeos/cros/sms_watcher.h"
14 #include "chromeos/dbus/dbus_thread_manager.h" 11 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "chromeos/dbus/shill_device_client.h" 12 #include "chromeos/dbus/shill_device_client.h"
16 #include "chromeos/dbus/shill_ipconfig_client.h" 13 #include "chromeos/dbus/shill_ipconfig_client.h"
17 #include "chromeos/dbus/shill_manager_client.h" 14 #include "chromeos/dbus/shill_manager_client.h"
18 #include "chromeos/dbus/shill_network_client.h" 15 #include "chromeos/dbus/shill_network_client.h"
19 #include "chromeos/dbus/shill_profile_client.h" 16 #include "chromeos/dbus/shill_profile_client.h"
20 #include "chromeos/dbus/shill_property_changed_observer.h" 17 #include "chromeos/dbus/shill_property_changed_observer.h"
21 #include "chromeos/dbus/shill_service_client.h" 18 #include "chromeos/dbus/shill_service_client.h"
19 #include "chromeos/network/network_util.h"
20 #include "chromeos/network/sms_watcher.h"
22 #include "dbus/object_path.h" 21 #include "dbus/object_path.h"
23 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
24 23
25 using base::DoNothing; 24 using base::DoNothing;
26 25
27 namespace chromeos { 26 namespace chromeos {
28 27
29 namespace { 28 namespace {
30 29
31 // Class to watch network manager's properties without Libcros. 30 // Class to watch network manager's properties without Libcros.
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 if (properties->GetListWithoutPathExpansion(flimflam::kNameServersProperty, 265 if (properties->GetListWithoutPathExpansion(flimflam::kNameServersProperty,
267 &name_servers)) { 266 &name_servers)) {
268 name_servers_string = ConvertNameSerersListToString(*name_servers); 267 name_servers_string = ConvertNameSerersListToString(*name_servers);
269 } else { 268 } else {
270 LOG(ERROR) << "Cannot get name servers."; 269 LOG(ERROR) << "Cannot get name servers.";
271 } 270 }
272 ipconfig_vector->push_back( 271 ipconfig_vector->push_back(
273 NetworkIPConfig(device_path, 272 NetworkIPConfig(device_path,
274 ParseIPConfigType(type_string), 273 ParseIPConfigType(type_string),
275 address, 274 address,
276 CrosPrefixLengthToNetmask(prefix_len), 275 network_util::PrefixLengthToNetmask(prefix_len),
277 gateway, 276 gateway,
278 name_servers_string)); 277 name_servers_string));
279 return true; 278 return true;
280 } 279 }
281 280
282 void ListIPConfigsCallback(const NetworkGetIPConfigsCallback& callback, 281 void ListIPConfigsCallback(const NetworkGetIPConfigsCallback& callback,
283 const std::string& device_path, 282 const std::string& device_path,
284 DBusMethodCallStatus call_status, 283 DBusMethodCallStatus call_status,
285 const base::DictionaryValue& properties) { 284 const base::DictionaryValue& properties) {
286 NetworkIPConfigVector ipconfig_vector; 285 NetworkIPConfigVector ipconfig_vector;
(...skipping 16 matching lines...) Expand all
303 } 302 }
304 // Get the hardware address as well. 303 // Get the hardware address as well.
305 properties.GetStringWithoutPathExpansion(flimflam::kAddressProperty, 304 properties.GetStringWithoutPathExpansion(flimflam::kAddressProperty,
306 &hardware_address); 305 &hardware_address);
307 306
308 callback.Run(ipconfig_vector, hardware_address); 307 callback.Run(ipconfig_vector, hardware_address);
309 } 308 }
310 309
311 } // namespace 310 } // namespace
312 311
313 SMS::SMS()
314 : validity(0),
315 msgclass(0) {
316 }
317
318 SMS::~SMS() {}
319
320 bool CrosActivateCellularModem(const std::string& service_path, 312 bool CrosActivateCellularModem(const std::string& service_path,
321 const std::string& carrier) { 313 const std::string& carrier) {
322 return DBusThreadManager::Get()->GetShillServiceClient()-> 314 return DBusThreadManager::Get()->GetShillServiceClient()->
323 CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path), 315 CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path),
324 carrier); 316 carrier);
325 } 317 }
326 318
327 void CrosSetNetworkServiceProperty(const std::string& service_path, 319 void CrosSetNetworkServiceProperty(const std::string& service_path,
328 const std::string& property, 320 const std::string& property,
329 const base::Value& value) { 321 const base::Value& value) {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 return false; // No powered device found that has a 'Networks' array. 735 return false; // No powered device found that has a 'Networks' array.
744 return true; 736 return true;
745 } 737 }
746 738
747 void CrosConfigureService(const base::DictionaryValue& properties) { 739 void CrosConfigureService(const base::DictionaryValue& properties) {
748 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( 740 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
749 properties, base::Bind(&DoNothing), 741 properties, base::Bind(&DoNothing),
750 base::Bind(&IgnoreErrors)); 742 base::Bind(&IgnoreErrors));
751 } 743 }
752 744
753 std::string CrosPrefixLengthToNetmask(int32 prefix_length) {
754 std::string netmask;
755 // Return the empty string for invalid inputs.
756 if (prefix_length < 0 || prefix_length > 32)
757 return netmask;
758 for (int i = 0; i < 4; i++) {
759 int remainder = 8;
760 if (prefix_length >= 8) {
761 prefix_length -= 8;
762 } else {
763 remainder = prefix_length;
764 prefix_length = 0;
765 }
766 if (i > 0)
767 netmask += ".";
768 int value = remainder == 0 ? 0 :
769 ((2L << (remainder - 1)) - 1) << (8 - remainder);
770 netmask += StringPrintf("%d", value);
771 }
772 return netmask;
773 }
774
775 int32 CrosNetmaskToPrefixLength(const std::string& netmask) {
776 int count = 0;
777 int prefix_length = 0;
778 StringTokenizer t(netmask, ".");
779 while (t.GetNext()) {
780 // If there are more than 4 numbers, then it's invalid.
781 if (count == 4)
782 return -1;
783
784 std::string token = t.token();
785 // If we already found the last mask and the current one is not
786 // "0" then the netmask is invalid. For example, 255.224.255.0
787 if (prefix_length / 8 != count) {
788 if (token != "0")
789 return -1;
790 } else if (token == "255") {
791 prefix_length += 8;
792 } else if (token == "254") {
793 prefix_length += 7;
794 } else if (token == "252") {
795 prefix_length += 6;
796 } else if (token == "248") {
797 prefix_length += 5;
798 } else if (token == "240") {
799 prefix_length += 4;
800 } else if (token == "224") {
801 prefix_length += 3;
802 } else if (token == "192") {
803 prefix_length += 2;
804 } else if (token == "128") {
805 prefix_length += 1;
806 } else if (token == "0") {
807 prefix_length += 0;
808 } else {
809 // mask is not a valid number.
810 return -1;
811 }
812 count++;
813 }
814 if (count < 4)
815 return -1;
816 return prefix_length;
817 }
818
819 // Changes the active cellular carrier. 745 // Changes the active cellular carrier.
820 void CrosSetCarrier(const std::string& device_path, 746 void CrosSetCarrier(const std::string& device_path,
821 const std::string& carrier, 747 const std::string& carrier,
822 const NetworkOperationCallback& callback) { 748 const NetworkOperationCallback& callback) {
823 DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier( 749 DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier(
824 dbus::ObjectPath(device_path), carrier, 750 dbus::ObjectPath(device_path), carrier,
825 base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE, 751 base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
826 std::string()), 752 std::string()),
827 base::Bind(&OnNetworkActionError, callback, device_path)); 753 base::Bind(&OnNetworkActionError, callback, device_path));
828 } 754 }
829 755
830 } // namespace chromeos 756 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/cros_network_functions.h ('k') | chromeos/network/cros_network_functions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698