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.
5 #include "chromeos/network/network_activation_handler.h"
8 #include "base/bind_helpers.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "chromeos/dbus/shill_service_client.h"
11 #include "chromeos/network/network_event_log.h"
12 #include "chromeos/network/network_handler.h"
13 #include "dbus/object_proxy.h"
18 const char NetworkActivationHandler::kErrorShillError
[] = "shill-error";
20 NetworkActivationHandler::NetworkActivationHandler() {}
21 NetworkActivationHandler::~NetworkActivationHandler() {}
23 void NetworkActivationHandler::Activate(
24 const std::string
& service_path
,
25 const std::string
& carrier
,
26 const base::Closure
& success_callback
,
27 const network_handler::ErrorCallback
& error_callback
) {
28 NET_LOG_USER("ActivateNetwork", service_path
);
29 CallShillActivate(service_path
, carrier
, success_callback
, error_callback
);
32 void NetworkActivationHandler::CompleteActivation(
33 const std::string
& service_path
,
34 const base::Closure
& success_callback
,
35 const network_handler::ErrorCallback
& error_callback
) {
36 NET_LOG_USER("CompleteActivation", service_path
);
37 CallShillCompleteActivation(service_path
, success_callback
, error_callback
);
40 void NetworkActivationHandler::CallShillActivate(
41 const std::string
& service_path
,
42 const std::string
& carrier
,
43 const base::Closure
& success_callback
,
44 const network_handler::ErrorCallback
& error_callback
) {
45 NET_LOG_USER("Activation Request", service_path
+ ": '" + carrier
+ "'");
46 DBusThreadManager::Get()->GetShillServiceClient()->ActivateCellularModem(
47 dbus::ObjectPath(service_path
),
49 base::Bind(&NetworkActivationHandler::HandleShillSuccess
,
50 AsWeakPtr(), service_path
, success_callback
),
51 base::Bind(&network_handler::ShillErrorCallbackFunction
,
52 kErrorShillError
, service_path
, error_callback
));
55 void NetworkActivationHandler::CallShillCompleteActivation(
56 const std::string
& service_path
,
57 const base::Closure
& success_callback
,
58 const network_handler::ErrorCallback
& error_callback
) {
59 NET_LOG_USER("CompleteActivation Request", service_path
);
60 DBusThreadManager::Get()->GetShillServiceClient()->CompleteCellularActivation(
61 dbus::ObjectPath(service_path
),
62 base::Bind(&NetworkActivationHandler::HandleShillSuccess
,
63 AsWeakPtr(), service_path
, success_callback
),
64 base::Bind(&network_handler::ShillErrorCallbackFunction
,
65 kErrorShillError
, service_path
, error_callback
));
68 void NetworkActivationHandler::HandleShillSuccess(
69 const std::string
& service_path
,
70 const base::Closure
& success_callback
) {
71 if (!success_callback
.is_null())
72 success_callback
.Run();
75 } // namespace chromeos