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

Unified Diff: chromeos/network/network_activation_handler.cc

Issue 22611005: Switch over MobileActivator to use Network*Handler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add activation handler files Created 7 years, 4 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/network_activation_handler.cc
diff --git a/chromeos/network/network_activation_handler.cc b/chromeos/network/network_activation_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7b765b24c3dea5a0c6156f1e9b49996c09f9150f
--- /dev/null
+++ b/chromeos/network/network_activation_handler.cc
@@ -0,0 +1,109 @@
+// Copyright 2013 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/network_activation_handler.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/memory/weak_ptr.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/shill_service_client.h"
+#include "chromeos/network/network_event_log.h"
+#include "chromeos/network/network_handler.h"
+#include "chromeos/network/network_state.h"
+#include "chromeos/network/network_state_handler.h"
+#include "dbus/object_proxy.h"
+
+namespace chromeos {
+
+namespace {
+
+void InvokeErrorCallback(const std::string& service_path,
+ const network_handler::ErrorCallback& error_callback,
+ const std::string& error_name) {
+ std::string error_msg = "Activation Error: " + error_name;
+ NET_LOG_ERROR(error_msg, service_path);
+ if (error_callback.is_null())
+ return;
+ scoped_ptr<base::DictionaryValue> error_data(
+ network_handler::CreateErrorData(service_path, error_name, error_msg));
+ error_callback.Run(error_name, error_data.Pass());
+}
+
+} // namespace
+
+// static
+const char NetworkActivationHandler::kErrorShillError[] = "shill-error";
+const char NetworkActivationHandler::kErrorNotFound[] = "error-not-found";
+
+NetworkActivationHandler::NetworkActivationHandler() {}
+NetworkActivationHandler::~NetworkActivationHandler() {}
+
+void NetworkActivationHandler::Activate(
+ const std::string& service_path,
+ const std::string& carrier,
+ const base::Closure& success_callback,
+ const network_handler::ErrorCallback& error_callback) {
+ NET_LOG_USER("ActivateNetwork", service_path);
+ const NetworkState* network =
+ NetworkHandler::Get()->network_state_handler()->GetNetworkState(
+ service_path);
stevenjb 2013/08/14 02:28:31 We need to pass NetworkStateHandler to NetworkActi
gauravsh 2013/08/14 21:42:29 Done.
+ if (!network) {
+ InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
+ return;
+ }
+ CallShillActivate(service_path, carrier, success_callback, error_callback);
+}
+
+void NetworkActivationHandler::CompleteActivation(
+ const std::string& service_path,
+ const base::Closure& success_callback,
+ const network_handler::ErrorCallback& error_callback) {
+ NET_LOG_USER("CompleteActivation", service_path);
+ const NetworkState* network =
+ NetworkHandler::Get()->network_state_handler()->GetNetworkState(
+ service_path);
+ if (!network) {
+ InvokeErrorCallback(service_path, error_callback, kErrorNotFound);
+ return;
+ }
+ CallShillCompleteActivation(service_path, success_callback, error_callback);
+}
+
+void NetworkActivationHandler::CallShillActivate(
+ const std::string& service_path,
+ const std::string& carrier,
+ const base::Closure& success_callback,
+ const network_handler::ErrorCallback& error_callback) {
+ NET_LOG_USER("Activation Request", service_path + ": '" + carrier + "'");
+ DBusThreadManager::Get()->GetShillServiceClient()->ActivateCellularModem(
+ dbus::ObjectPath(service_path),
+ carrier,
+ base::Bind(&NetworkActivationHandler::HandleShillSuccess,
+ AsWeakPtr(), service_path, success_callback),
+ base::Bind(&network_handler::ShillErrorCallbackFunction,
+ kErrorShillError, service_path, error_callback));
+}
+
+void NetworkActivationHandler::CallShillCompleteActivation(
+ const std::string& service_path,
+ const base::Closure& success_callback,
+ const network_handler::ErrorCallback& error_callback) {
+ NET_LOG_USER("CompleteActivation Request", service_path);
+ DBusThreadManager::Get()->GetShillServiceClient()->CompleteCellularActivation(
+ dbus::ObjectPath(service_path),
+ base::Bind(&NetworkActivationHandler::HandleShillSuccess,
+ AsWeakPtr(), service_path, success_callback),
+ base::Bind(&network_handler::ShillErrorCallbackFunction,
+ kErrorShillError, service_path, error_callback));
+}
+
+void NetworkActivationHandler::HandleShillSuccess(
+ const std::string& service_path,
+ const base::Closure& success_callback) {
+ if (!success_callback.is_null())
+ success_callback.Run();
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698