OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chromeos/network/network_activation_handler.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "chromeos/dbus/dbus_thread_manager.h" | |
11 #include "chromeos/dbus/shill_service_client.h" | |
12 #include "chromeos/network/network_event_log.h" | |
13 #include "chromeos/network/network_handler.h" | |
14 #include "chromeos/network/network_state.h" | |
15 #include "chromeos/network/network_state_handler.h" | |
16 #include "dbus/object_proxy.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 namespace { | |
21 | |
22 void InvokeErrorCallback(const std::string& service_path, | |
23 const network_handler::ErrorCallback& error_callback, | |
24 const std::string& error_name) { | |
25 std::string error_msg = "Activation Error: " + error_name; | |
26 NET_LOG_ERROR(error_msg, service_path); | |
27 if (error_callback.is_null()) | |
28 return; | |
29 scoped_ptr<base::DictionaryValue> error_data( | |
30 network_handler::CreateErrorData(service_path, error_name, error_msg)); | |
31 error_callback.Run(error_name, error_data.Pass()); | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 // static | |
37 const char NetworkActivationHandler::kErrorShillError[] = "shill-error"; | |
38 const char NetworkActivationHandler::kErrorNotFound[] = "error-not-found"; | |
39 | |
40 NetworkActivationHandler::NetworkActivationHandler() {} | |
41 NetworkActivationHandler::~NetworkActivationHandler() {} | |
42 | |
43 void NetworkActivationHandler::Activate( | |
44 const std::string& service_path, | |
45 const std::string& carrier, | |
46 const base::Closure& success_callback, | |
47 const network_handler::ErrorCallback& error_callback) { | |
48 NET_LOG_USER("ActivateNetwork", service_path); | |
49 const NetworkState* network = | |
50 NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
51 service_path); | |
stevenjb
2013/08/14 02:28:31
We need to pass NetworkStateHandler to NetworkActi
gauravsh
2013/08/14 21:42:29
Done.
| |
52 if (!network) { | |
53 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
54 return; | |
55 } | |
56 CallShillActivate(service_path, carrier, success_callback, error_callback); | |
57 } | |
58 | |
59 void NetworkActivationHandler::CompleteActivation( | |
60 const std::string& service_path, | |
61 const base::Closure& success_callback, | |
62 const network_handler::ErrorCallback& error_callback) { | |
63 NET_LOG_USER("CompleteActivation", service_path); | |
64 const NetworkState* network = | |
65 NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
66 service_path); | |
67 if (!network) { | |
68 InvokeErrorCallback(service_path, error_callback, kErrorNotFound); | |
69 return; | |
70 } | |
71 CallShillCompleteActivation(service_path, success_callback, error_callback); | |
72 } | |
73 | |
74 void NetworkActivationHandler::CallShillActivate( | |
75 const std::string& service_path, | |
76 const std::string& carrier, | |
77 const base::Closure& success_callback, | |
78 const network_handler::ErrorCallback& error_callback) { | |
79 NET_LOG_USER("Activation Request", service_path + ": '" + carrier + "'"); | |
80 DBusThreadManager::Get()->GetShillServiceClient()->ActivateCellularModem( | |
81 dbus::ObjectPath(service_path), | |
82 carrier, | |
83 base::Bind(&NetworkActivationHandler::HandleShillSuccess, | |
84 AsWeakPtr(), service_path, success_callback), | |
85 base::Bind(&network_handler::ShillErrorCallbackFunction, | |
86 kErrorShillError, service_path, error_callback)); | |
87 } | |
88 | |
89 void NetworkActivationHandler::CallShillCompleteActivation( | |
90 const std::string& service_path, | |
91 const base::Closure& success_callback, | |
92 const network_handler::ErrorCallback& error_callback) { | |
93 NET_LOG_USER("CompleteActivation Request", service_path); | |
94 DBusThreadManager::Get()->GetShillServiceClient()->CompleteCellularActivation( | |
95 dbus::ObjectPath(service_path), | |
96 base::Bind(&NetworkActivationHandler::HandleShillSuccess, | |
97 AsWeakPtr(), service_path, success_callback), | |
98 base::Bind(&network_handler::ShillErrorCallbackFunction, | |
99 kErrorShillError, service_path, error_callback)); | |
100 } | |
101 | |
102 void NetworkActivationHandler::HandleShillSuccess( | |
103 const std::string& service_path, | |
104 const base::Closure& success_callback) { | |
105 if (!success_callback.is_null()) | |
106 success_callback.Run(); | |
107 } | |
108 | |
109 } // namespace chromeos | |
OLD | NEW |