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/cros/cros_network_functions.h" | 5 #include "chrome/browser/chromeos/cros/cros_network_functions.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chromeos/cros/gvalue_util.h" | 10 #include "chrome/browser/chromeos/cros/gvalue_util.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 ResetPropertyChangedHandler(dbus::ObjectPath(device_path_)); | 131 ResetPropertyChangedHandler(dbus::ObjectPath(device_path_)); |
132 } | 132 } |
133 | 133 |
134 private: | 134 private: |
135 std::string device_path_; | 135 std::string device_path_; |
136 }; | 136 }; |
137 | 137 |
138 // Class to watch data plan update with Libcros. | 138 // Class to watch data plan update with Libcros. |
139 class CrosDataPlanUpdateWatcher : public CrosNetworkWatcher { | 139 class CrosDataPlanUpdateWatcher : public CrosNetworkWatcher { |
140 public: | 140 public: |
141 CrosDataPlanUpdateWatcher(MonitorDataPlanCallback callback, void* object) | 141 explicit CrosDataPlanUpdateWatcher( |
142 : monitor_(chromeos::MonitorCellularDataPlan(callback, object)) {} | 142 const DataPlanUpdateWatcherCallback& callback) |
| 143 : callback_(callback), |
| 144 monitor_(chromeos::MonitorCellularDataPlan(&OnDataPlanUpdate, this)) {} |
143 virtual ~CrosDataPlanUpdateWatcher() { | 145 virtual ~CrosDataPlanUpdateWatcher() { |
144 chromeos::DisconnectDataPlanUpdateMonitor(monitor_); | 146 chromeos::DisconnectDataPlanUpdateMonitor(monitor_); |
145 } | 147 } |
146 | 148 |
147 private: | 149 private: |
| 150 static void OnDataPlanUpdate(void* object, |
| 151 const char* modem_service_path, |
| 152 const CellularDataPlanList* data_plan_list) { |
| 153 CrosDataPlanUpdateWatcher* watcher = |
| 154 static_cast<CrosDataPlanUpdateWatcher*>(object); |
| 155 if (modem_service_path && data_plan_list) { |
| 156 // Copy contents of |data_plan_list| from libcros to |data_plan_vector|. |
| 157 CellularDataPlanVector* data_plan_vector = new CellularDataPlanVector; |
| 158 for (size_t i = 0; i < data_plan_list->plans_size; ++i) { |
| 159 const CellularDataPlanInfo* info = |
| 160 data_plan_list->GetCellularDataPlan(i); |
| 161 CellularDataPlan* plan = new CellularDataPlan(*info); |
| 162 data_plan_vector->push_back(plan); |
| 163 VLOG(2) << " Plan: " << plan->GetPlanDesciption() |
| 164 << " : " << plan->GetDataRemainingDesciption(); |
| 165 } |
| 166 // |data_plan_vector| will be owned by callback. |
| 167 watcher->callback_.Run(modem_service_path, data_plan_vector); |
| 168 } |
| 169 } |
| 170 |
| 171 DataPlanUpdateWatcherCallback callback_; |
148 DataPlanUpdateMonitor monitor_; | 172 DataPlanUpdateMonitor monitor_; |
149 }; | 173 }; |
150 | 174 |
151 // Class to watch sms with Libcros. | 175 // Class to watch sms with Libcros. |
152 class CrosSMSWatcher : public CrosNetworkWatcher { | 176 class CrosSMSWatcher : public CrosNetworkWatcher { |
153 public: | 177 public: |
154 CrosSMSWatcher(const std::string& modem_device_path, | 178 CrosSMSWatcher(const std::string& modem_device_path, |
155 MonitorSMSCallback callback, | 179 MonitorSMSCallback callback, |
156 void* object) | 180 void* object) |
157 : monitor_(chromeos::MonitorSMS(modem_device_path.c_str(), | 181 : monitor_(chromeos::MonitorSMS(modem_device_path.c_str(), |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties( | 413 CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties( |
390 const NetworkPropertiesWatcherCallback& callback, | 414 const NetworkPropertiesWatcherCallback& callback, |
391 const std::string& device_path) { | 415 const std::string& device_path) { |
392 if (g_libcros_network_functions_enabled) | 416 if (g_libcros_network_functions_enabled) |
393 return new CrosNetworkDevicePropertiesWatcher(callback, device_path); | 417 return new CrosNetworkDevicePropertiesWatcher(callback, device_path); |
394 else | 418 else |
395 return new NetworkDevicePropertiesWatcher(callback, device_path); | 419 return new NetworkDevicePropertiesWatcher(callback, device_path); |
396 } | 420 } |
397 | 421 |
398 CrosNetworkWatcher* CrosMonitorCellularDataPlan( | 422 CrosNetworkWatcher* CrosMonitorCellularDataPlan( |
399 MonitorDataPlanCallback callback, void* object) { | 423 const DataPlanUpdateWatcherCallback& callback) { |
400 return new CrosDataPlanUpdateWatcher(callback, object); | 424 return new CrosDataPlanUpdateWatcher(callback); |
401 } | 425 } |
402 | 426 |
403 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, | 427 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path, |
404 MonitorSMSCallback callback, | 428 MonitorSMSCallback callback, |
405 void* object) { | 429 void* object) { |
406 return new CrosSMSWatcher(modem_device_path, callback, object); | 430 return new CrosSMSWatcher(modem_device_path, callback, object); |
407 } | 431 } |
408 | 432 |
409 void CrosRequestNetworkServiceConnect(const std::string& service_path, | 433 void CrosRequestNetworkServiceConnect(const std::string& service_path, |
410 NetworkActionCallback callback, | 434 NetworkActionCallback callback, |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 ScopedGHashTable ghash( | 920 ScopedGHashTable ghash( |
897 ConvertDictionaryValueToStringValueGHashTable(properties)); | 921 ConvertDictionaryValueToStringValueGHashTable(properties)); |
898 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); | 922 chromeos::ConfigureService("", ghash.get(), OnConfigureService, NULL); |
899 } else { | 923 } else { |
900 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( | 924 DBusThreadManager::Get()->GetFlimflamManagerClient()->ConfigureService( |
901 properties, base::Bind(&DoNothing)); | 925 properties, base::Bind(&DoNothing)); |
902 } | 926 } |
903 } | 927 } |
904 | 928 |
905 } // namespace chromeos | 929 } // namespace chromeos |
OLD | NEW |