[go: nahoru, domu]

Adding mojo calls for easy unlock service

BUG=721524

Review-Url: https://codereview.chromium.org/2903353003
Cr-Commit-Position: refs/heads/master@{#477722}
diff --git a/ash/login/lock_screen_controller.cc b/ash/login/lock_screen_controller.cc
index 5ff835e..8b99e6f 100644
--- a/ash/login/lock_screen_controller.cc
+++ b/ash/login/lock_screen_controller.cc
@@ -17,17 +17,6 @@
   bindings_.AddBinding(this, std::move(request));
 }
 
-void LockScreenController::AuthenticateUser(const AccountId& account_id,
-                                            const std::string& password,
-                                            bool authenticated_by_pin) {
-  if (!lock_screen_client_)
-    return;
-
-  chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind(
-      &LockScreenController::DoAuthenticateUser, base::Unretained(this),
-      account_id, password, authenticated_by_pin));
-}
-
 void LockScreenController::SetClient(mojom::LockScreenClientPtr client) {
   lock_screen_client_ = std::move(client);
 }
@@ -43,6 +32,56 @@
   NOTIMPLEMENTED();
 }
 
+void LockScreenController::ShowUserPodCustomIcon(
+    const AccountId& account_id,
+    mojom::UserPodCustomIconOptionsPtr icon) {
+  NOTIMPLEMENTED();
+}
+
+void LockScreenController::HideUserPodCustomIcon(const AccountId& account_id) {
+  NOTIMPLEMENTED();
+}
+
+void LockScreenController::SetAuthType(const AccountId& account_id,
+                                       mojom::AuthType auth_type,
+                                       const base::string16& initial_value) {
+  NOTIMPLEMENTED();
+}
+
+void LockScreenController::LoadUsers(std::unique_ptr<base::ListValue> users,
+                                     bool show_guest) {
+  NOTIMPLEMENTED();
+}
+
+void LockScreenController::AuthenticateUser(const AccountId& account_id,
+                                            const std::string& password,
+                                            bool authenticated_by_pin) {
+  if (!lock_screen_client_)
+    return;
+
+  chromeos::SystemSaltGetter::Get()->GetSystemSalt(base::Bind(
+      &LockScreenController::DoAuthenticateUser, base::Unretained(this),
+      account_id, password, authenticated_by_pin));
+}
+
+void LockScreenController::AttemptUnlock(const AccountId& account_id) {
+  if (!lock_screen_client_)
+    return;
+  lock_screen_client_->AttemptUnlock(account_id);
+}
+
+void LockScreenController::HardlockPod(const AccountId& account_id) {
+  if (!lock_screen_client_)
+    return;
+  lock_screen_client_->HardlockPod(account_id);
+}
+
+void LockScreenController::RecordClickOnLockIcon(const AccountId& account_id) {
+  if (!lock_screen_client_)
+    return;
+  lock_screen_client_->RecordClickOnLockIcon(account_id);
+}
+
 void LockScreenController::DoAuthenticateUser(const AccountId& account_id,
                                               const std::string& password,
                                               bool authenticated_by_pin,
diff --git a/ash/login/lock_screen_controller.h b/ash/login/lock_screen_controller.h
index 50bc9e5..6d01961 100644
--- a/ash/login/lock_screen_controller.h
+++ b/ash/login/lock_screen_controller.h
@@ -33,8 +33,16 @@
                         const std::string& help_link_text,
                         int32_t help_topic_id) override;
   void ClearErrors() override;
+  void ShowUserPodCustomIcon(const AccountId& account_id,
+                             mojom::UserPodCustomIconOptionsPtr icon) override;
+  void HideUserPodCustomIcon(const AccountId& account_id) override;
+  void SetAuthType(const AccountId& account_id,
+                   mojom::AuthType auth_type,
+                   const base::string16& initial_value) override;
+  void LoadUsers(std::unique_ptr<base::ListValue> users,
+                 bool show_guest) override;
 
-  // Wrappers around the mojom::SystemTrayClient interface.
+  // Wrappers around the mojom::LockScreenClient interface.
   // Hash the password and send AuthenticateUser request to LockScreenClient.
   // LockScreenClient(chrome) will do the authentication and request to show
   // error messages in the lock screen if auth fails, or request to clear
@@ -42,6 +50,9 @@
   void AuthenticateUser(const AccountId& account_id,
                         const std::string& password,
                         bool authenticated_by_pin);
+  void AttemptUnlock(const AccountId& account_id);
+  void HardlockPod(const AccountId& account_id);
+  void RecordClickOnLockIcon(const AccountId& account_id);
 
  private:
   void DoAuthenticateUser(const AccountId& account_id,
diff --git a/ash/login/lock_screen_controller_unittest.cc b/ash/login/lock_screen_controller_unittest.cc
index 3e42c9e..a1c3deb 100644
--- a/ash/login/lock_screen_controller_unittest.cc
+++ b/ash/login/lock_screen_controller_unittest.cc
@@ -38,4 +38,26 @@
   base::RunLoop().RunUntilIdle();
 }
 
+TEST_F(LockScreenControllerTest, RequestEasyUnlock) {
+  LockScreenController* controller = Shell::Get()->lock_screen_controller();
+  std::unique_ptr<MockLockScreenClient> client = BindMockLockScreenClient();
+
+  AccountId id = AccountId::FromUserEmail("user1@test.com");
+
+  // Verify AttemptUnlock mojo call is run with the same account id.
+  EXPECT_CALL(*client, AttemptUnlock(id));
+  controller->AttemptUnlock(id);
+  base::RunLoop().RunUntilIdle();
+
+  // Verify HardlockPod mojo call is run with the same account id.
+  EXPECT_CALL(*client, HardlockPod(id));
+  controller->HardlockPod(id);
+  base::RunLoop().RunUntilIdle();
+
+  // Verify RecordClickOnLockIcon mojo call is run with the same account id.
+  EXPECT_CALL(*client, RecordClickOnLockIcon(id));
+  controller->RecordClickOnLockIcon(id);
+  base::RunLoop().RunUntilIdle();
+}
+
 }  // namespace ash
diff --git a/ash/login/mock_lock_screen_client.h b/ash/login/mock_lock_screen_client.h
index 52874b35..3900daf 100644
--- a/ash/login/mock_lock_screen_client.h
+++ b/ash/login/mock_lock_screen_client.h
@@ -23,6 +23,9 @@
                void(const AccountId& account_id,
                     const std::string& password,
                     bool authenticated_by_pin));
+  MOCK_METHOD1(AttemptUnlock, void(const AccountId& account_id));
+  MOCK_METHOD1(HardlockPod, void(const AccountId& account_id));
+  MOCK_METHOD1(RecordClickOnLockIcon, void(const AccountId& account_id));
 
  private:
   mojo::Binding<ash::mojom::LockScreenClient> binding_;
diff --git a/ash/public/interfaces/lock_screen.mojom b/ash/public/interfaces/lock_screen.mojom
index d29b331..0b4a141 100644
--- a/ash/public/interfaces/lock_screen.mojom
+++ b/ash/public/interfaces/lock_screen.mojom
@@ -5,6 +5,29 @@
 module ash.mojom;
 
 import "components/signin/public/interfaces/account_id.mojom";
+import "mojo/common/string16.mojom";
+import "mojo/common/values.mojom";
+
+// Supported authentication types. Keep in sync with enum in
+// screenlock_bridge.h
+enum AuthType {
+  OFFLINE_PASSWORD,
+  ONLINE_SIGN_IN,
+  NUMERIC_PIN,
+  USER_CLICK,
+  EXPAND_THEN_USER_CLICK,
+  FORCE_OFFLINE_PASSWORD,
+};
+
+// Information about the custom icon in the user pod.
+struct UserPodCustomIconOptions {
+  string id;
+  mojo.common.mojom.String16 tooltip;
+  bool autoshow_tooltip;
+  mojo.common.mojom.String16 aria_label;
+  bool hardlock_on_click;
+  bool is_trial_run;
+};
 
 // Allows clients (e.g. Chrome browser) to control the ash lock screen.
 interface LockScreen {
@@ -25,6 +48,32 @@
 
   // Requests to close any displayed error messages in ash lock screen.
   ClearErrors();
+
+  // Requests to show the custom icon in the user pod.
+  // |account_id|:  The account id of the user in the user pod.
+  // |icon|:        Information regarding the icon.
+  ShowUserPodCustomIcon(signin.mojom.AccountId account_id,
+                        UserPodCustomIconOptions icon);
+
+  // Requests to hide the custom icon in the user pod.
+  // |account_id|:  The account id of the user in the user pod.
+  HideUserPodCustomIcon(signin.mojom.AccountId account_id);
+
+  // Requests to set the authentication type.
+  // |account_id|:    The account id of the user in the user pod.
+  // |auth_type|:     Authentication type.
+  // |initial_value|: A message shown in the password field of the user pod.
+  SetAuthType(signin.mojom.AccountId account_id,
+              AuthType auth_type,
+              mojo.common.mojom.String16 initial_value);
+
+  // Requests to load users in the lock screen.
+  // TODO: create a mojo struct for |users|, this contains user information
+  // for login/lock screen, some of which might not be needed for the new
+  // view-based UI. See crbug.com/729687.
+  // |users|:      A list of users who can unlock the device.
+  // |show_guest|: Whether to show guest session button.
+  LoadUsers(mojo.common.mojom.ListValue users, bool show_guest);
 };
 
 // Allows ash lock screen to control a client (e.g. Chrome browser). Requests
@@ -41,4 +90,16 @@
   AuthenticateUser(signin.mojom.AccountId account_id,
                    string hashed_password,
 	           bool authenticated_by_pin);
+
+  // Request to attempt easy unlock in chrome.
+  // |account_id|:   The account id of the user we are authenticating.
+  AttemptUnlock(signin.mojom.AccountId account_id);
+
+  // Request to hard lock the user pod.
+  // |account_id|:    The account id of the user in the user pod.
+  HardlockPod(signin.mojom.AccountId account_id);
+
+  // Record clicks on the lock icon in the user pod.
+  // |account_id|:    The account id of the user in the user pod.
+  RecordClickOnLockIcon(signin.mojom.AccountId account_id);
 };