shill: Move PIN management to the capability delegates.

BUG=chromium-os:18735
TEST=unit tests

Change-Id: Icdaca0ee95f56d84e15a10029551a0abeaee79c1
Reviewed-on: https://gerrit.chromium.org/gerrit/11261
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Eric Shienbrood <ers@chromium.org>
Commit-Ready: Darin Petkov <petkov@chromium.org>
diff --git a/cellular_capability_gsm.cc b/cellular_capability_gsm.cc
index 169e717..464d62b 100644
--- a/cellular_capability_gsm.cc
+++ b/cellular_capability_gsm.cc
@@ -9,10 +9,13 @@
 #include "shill/cellular.h"
 #include "shill/proxy_factory.h"
 
+using std::string;
+
 namespace shill {
 
 CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular)
-    : CellularCapability(cellular) {}
+    : CellularCapability(cellular),
+      task_factory_(this) {}
 
 void CellularCapabilityGSM::InitProxies() {
   VLOG(2) << __func__;
@@ -27,4 +30,65 @@
                                                   cellular()->dbus_owner()));
 }
 
+void CellularCapabilityGSM::RequirePIN(
+    const string &pin, bool require, Error */*error*/) {
+  VLOG(2) << __func__ << "(" << pin << ", " << require << ")";
+  // Defer because we may be in a dbus-c++ callback.
+  dispatcher()->PostTask(
+      task_factory_.NewRunnableMethod(
+          &CellularCapabilityGSM::RequirePINTask, pin, require));
+}
+
+void CellularCapabilityGSM::RequirePINTask(const string &pin, bool require) {
+  VLOG(2) << __func__ << "(" << pin << ", " << require << ")";
+  // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
+  cellular()->modem_gsm_card_proxy()->EnablePIN(pin, require);
+}
+
+void CellularCapabilityGSM::EnterPIN(const string &pin, Error */*error*/) {
+  VLOG(2) << __func__ << "(" << pin << ")";
+  // Defer because we may be in a dbus-c++ callback.
+  dispatcher()->PostTask(
+      task_factory_.NewRunnableMethod(
+          &CellularCapabilityGSM::EnterPINTask, pin));
+}
+
+void CellularCapabilityGSM::EnterPINTask(const string &pin) {
+  VLOG(2) << __func__ << "(" << pin << ")";
+  // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
+  cellular()->modem_gsm_card_proxy()->SendPIN(pin);
+}
+
+void CellularCapabilityGSM::UnblockPIN(
+    const string &unblock_code, const string &pin, Error */*error*/) {
+  VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")";
+  // Defer because we may be in a dbus-c++ callback.
+  dispatcher()->PostTask(
+      task_factory_.NewRunnableMethod(
+          &CellularCapabilityGSM::UnblockPINTask, unblock_code, pin));
+}
+
+void CellularCapabilityGSM::UnblockPINTask(
+    const string &unblock_code, const string &pin) {
+  VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")";
+  // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
+  cellular()->modem_gsm_card_proxy()->SendPUK(unblock_code, pin);
+}
+
+void CellularCapabilityGSM::ChangePIN(
+    const string &old_pin, const string &new_pin, Error */*error*/) {
+  VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")";
+  // Defer because we may be in a dbus-c++ callback.
+  dispatcher()->PostTask(
+      task_factory_.NewRunnableMethod(
+          &CellularCapabilityGSM::ChangePINTask, old_pin, new_pin));
+}
+
+void CellularCapabilityGSM::ChangePINTask(
+    const string &old_pin, const string &new_pin) {
+  VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")";
+  // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
+  cellular()->modem_gsm_card_proxy()->ChangePIN(old_pin, new_pin);
+}
+
 }  // namespace shill