[auth] Add context to AccountHandler init calls.

Previously I'd been working on the basis that we'd be able to insert the
AccountHandlerContext directly into the AccountHandler's namespace while
launching it, but a recent email thread indicates this isn't going to
work well until the next version of component architecture. Until then
I'm moving to explicitly supplying the context in the calls that are
used to initialize AccountHandler.

AUTH-107

Tested: CQ, demonstrates no breakage. This CL doesn't yet add any new
functionality to test.

Change-Id: I2901d1dfc235ef89b3f29c99518aa5ef37e28a6f
diff --git a/bin/auth/account_handler/src/account.rs b/bin/auth/account_handler/src/account.rs
index 0f97fa1..39d6d3b 100644
--- a/bin/auth/account_handler/src/account.rs
+++ b/bin/auth/account_handler/src/account.rs
@@ -2,9 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-use account_common::{FidlLocalPersonaId, LocalAccountId, LocalPersonaId};
 use crate::account_handler::AccountHandler;
 use crate::persona::Persona;
+use account_common::{FidlLocalPersonaId, LocalAccountId, LocalPersonaId};
 use failure::Error;
 use fidl::encoding::OutOfLine;
 use fidl::endpoints::{ClientEnd, ServerEnd};
diff --git a/bin/auth/account_handler/src/account_handler.rs b/bin/auth/account_handler/src/account_handler.rs
index 43be205..9a41221 100644
--- a/bin/auth/account_handler/src/account_handler.rs
+++ b/bin/auth/account_handler/src/account_handler.rs
@@ -61,7 +61,10 @@
     /// based on its type.
     pub fn handle_request(&self, req: AccountHandlerControlRequest) -> Result<(), fidl::Error> {
         match req {
-            AccountHandlerControlRequest::CreateAccount { responder } => {
+            AccountHandlerControlRequest::CreateAccount {
+                context: _,
+                responder,
+            } => {
                 let response = self.create_account();
                 responder.send(
                     response.0,
@@ -72,7 +75,11 @@
                         .map(OutOfLine),
                 )?;
             }
-            AccountHandlerControlRequest::LoadAccount { id, responder } => {
+            AccountHandlerControlRequest::LoadAccount {
+                context: _,
+                id,
+                responder,
+            } => {
                 let response = self.load_account(id.into());
                 responder.send(response)?;
             }
@@ -256,11 +263,15 @@
     fn test_double_initialize() {
         let location = TempLocation::new();
         request_stream_test(AccountHandler::new(location.path), async move |proxy| {
-            let (status, account_id_optional) = await!(proxy.create_account())?;
+            let (_, ahc_client_chan_1) = zx::Channel::create().unwrap();
+            let (status, account_id_optional) =
+                await!(proxy.create_account(ClientEnd::new(ahc_client_chan_1)))?;
             assert_eq!(status, Status::Ok);
             assert!(account_id_optional.is_some());
+
+            let (_, ahc_client_chan_2) = zx::Channel::create().unwrap();
             assert_eq!(
-                await!(proxy.create_account())?,
+                await!(proxy.create_account(ClientEnd::new(ahc_client_chan_2)))?,
                 (Status::InvalidRequest, None)
             );
             Ok(())
@@ -273,7 +284,9 @@
         request_stream_test(
             AccountHandler::new(location.path),
             async move |account_handler_proxy| {
-                let (status, account_id_optional) = await!(account_handler_proxy.create_account())?;
+                let (_, ahc_client_chan) = zx::Channel::create().unwrap();
+                let (status, account_id_optional) =
+                    await!(account_handler_proxy.create_account(ClientEnd::new(ahc_client_chan)))?;
                 assert_eq!(status, Status::Ok);
                 assert!(account_id_optional.is_some());
 
@@ -311,7 +324,9 @@
         request_stream_test(
             AccountHandler::new(location.path.clone()),
             async move |account_handler_proxy| {
-                let (status, account_id_optional) = await!(account_handler_proxy.create_account())?;
+                let (_, ahc_client_chan) = zx::Channel::create().unwrap();
+                let (status, account_id_optional) =
+                    await!(account_handler_proxy.create_account(ClientEnd::new(ahc_client_chan)))?;
                 assert_eq!(status, Status::Ok);
                 assert!(account_id_optional.is_some());
                 let mut acc_id = acc_id_borrow.lock().unwrap();
@@ -320,8 +335,10 @@
             },
         );
         request_stream_test(AccountHandler::new(location.path), async move |proxy| {
+            let (_, ahc_client_chan) = zx::Channel::create().unwrap();
             assert_eq!(
-                await!(proxy.load_account(&mut acc_id.lock().unwrap()))?,
+                await!(proxy
+                    .load_account(ClientEnd::new(ahc_client_chan), &mut acc_id.lock().unwrap()))?,
                 Status::Ok
             );
             Ok(())
@@ -332,10 +349,14 @@
     fn test_load_account_not_found() {
         let location = TempLocation::new();
         request_stream_test(AccountHandler::new(location.path), async move |proxy| {
+            let (_, ahc_client_chan) = zx::Channel::create().unwrap();
             assert_eq!(
-                await!(proxy.load_account(&mut FidlLocalAccountId {
-                    id: WRONG_ACCOUNT_ID
-                }))?,
+                await!(proxy.load_account(
+                    ClientEnd::new(ahc_client_chan),
+                    &mut FidlLocalAccountId {
+                        id: WRONG_ACCOUNT_ID
+                    }
+                ))?,
                 Status::NotFound
             );
             Ok(())
diff --git a/bin/auth/account_handler/src/persona.rs b/bin/auth/account_handler/src/persona.rs
index 707f1d1ed..95f206b 100644
--- a/bin/auth/account_handler/src/persona.rs
+++ b/bin/auth/account_handler/src/persona.rs
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-use account_common::{LocalAccountId, LocalPersonaId};
 use crate::account_handler::AccountHandler;
+use account_common::{LocalAccountId, LocalPersonaId};
 use failure::Error;
 use fidl::encoding::OutOfLine;
 use fidl::endpoints::{ClientEnd, ServerEnd};
diff --git a/bin/auth/account_manager/src/account_handler_connection.rs b/bin/auth/account_manager/src/account_handler_connection.rs
index a624b75..e3503fd 100644
--- a/bin/auth/account_manager/src/account_handler_connection.rs
+++ b/bin/auth/account_manager/src/account_handler_connection.rs
@@ -4,9 +4,11 @@
 
 use account_common::{AccountManagerError, LocalAccountId};
 use failure::{format_err, ResultExt};
+use fidl::endpoints::ClientEnd;
 use fidl_fuchsia_auth_account::Status;
 use fidl_fuchsia_auth_account_internal::{AccountHandlerControlMarker, AccountHandlerControlProxy};
 use fuchsia_app::client::{App, Launcher};
+use fuchsia_zircon as zx;
 use futures::prelude::*;
 use log::{info, warn};
 
@@ -51,8 +53,14 @@
     pub async fn new_for_account(account_id: &LocalAccountId) -> Result<Self, AccountManagerError> {
         let connection = Self::new()?;
         let mut fidl_account_id = account_id.clone().into();
-        match await!(connection.proxy.load_account(&mut fidl_account_id))
-            .map_err(|err| AccountManagerError::new(Status::IoError).with_cause(err))?
+        // TODO(jsankey): Supply a real AccountHandlerContext
+        let (_, dummy_context) = zx::Channel::create()
+            .context("Failed to create AccountHandlerContext channel")
+            .map_err(|err| AccountManagerError::new(Status::IoError).with_cause(err))?;
+        match await!(connection
+            .proxy
+            .load_account(ClientEnd::new(dummy_context), &mut fidl_account_id))
+        .map_err(|err| AccountManagerError::new(Status::IoError).with_cause(err))?
         {
             Status::Ok => Ok(connection),
             stat => Err(AccountManagerError::new(stat)
diff --git a/bin/auth/account_manager/src/account_manager.rs b/bin/auth/account_manager/src/account_manager.rs
index bbb1b24..6dfa265 100644
--- a/bin/auth/account_manager/src/account_manager.rs
+++ b/bin/auth/account_manager/src/account_manager.rs
@@ -10,6 +10,7 @@
     AccountAuthState, AccountListenerMarker, AccountListenerOptions, AccountManagerRequest,
     AccountManagerRequestStream, AccountMarker, Status,
 };
+use fuchsia_zircon as zx;
 
 use failure::Error;
 use futures::lock::Mutex;
@@ -197,8 +198,19 @@
                 return (err.status, None);
             }
         };
+        // TODO(jsankey): Supply a real AccountHandlerContext
+        let dummy_context = match zx::Channel::create() {
+            Ok((_, client_chan)) => client_chan,
+            Err(err) => {
+                warn!("Failure to create AccountHandlerContext channel: {:?}", err);
+                return (Status::IoError, None);
+            }
+        };
 
-        let account_id = match await!(account_handler.proxy().create_account()) {
+        let account_id = match await!(account_handler
+            .proxy()
+            .create_account(ClientEnd::new(dummy_context)))
+        {
             Ok((Status::Ok, Some(account_id))) => LocalAccountId::from(*account_id),
             Ok((Status::Ok, None)) => {
                 warn!("Failure creating account, handler returned success without ID");
diff --git a/lib/auth/fidl/account_handler.fidl b/lib/auth/fidl/account_handler.fidl
index b429b7e..4400c7b 100644
--- a/lib/auth/fidl/account_handler.fidl
+++ b/lib/auth/fidl/account_handler.fidl
@@ -22,20 +22,28 @@
 interface AccountHandlerControl {
     // Creates a completely new Fuchsia account.
     //
+    // |context| An |AccountHandlerContext| that can supply account and
+    //           authentication services and contextual state.
+    //
     // Returns: |status| A |Status| indicating whether the operation was
     //                   successful
     //          |id| The new account's local identifier, if successful
-    CreateAccount() -> (fuchsia.auth.account.Status status,
-                        fuchsia.auth.account.LocalAccountId? id);
+    CreateAccount(AccountHandlerContext context)
+        -> (fuchsia.auth.account.Status status,
+            fuchsia.auth.account.LocalAccountId? id);
 
     // Loads information about a Fuchsia account that was previously provisioned
     // on the current device.
     //
+    // |context| An |AccountHandlerContext| that can supply account and
+    //           authentication services and contextual state.
     // |id| The account's local identifier
     //
     // Returns: |status| A |Status| indicating whether the operation was
     //                   successful
-    LoadAccount(fuchsia.auth.account.LocalAccountId id)
+    LoadAccount(
+        AccountHandlerContext context,
+        fuchsia.auth.account.LocalAccountId id)
         -> (fuchsia.auth.account.Status status);
 
     // Deletes all persistent information about the Fuchsia account handled by
@@ -75,9 +83,12 @@
 };
 
 // An interface that supplies the account and authentication services that
-// an AccountHandler needs to perform its role in the system. This service is
-// supplied to the AccountHandler by the component that launches it, i.e. the
-// AccountManager.
+// an AccountHandler needs to perform its role in the system.
+//
+// In the v2 Component architecture this service will be supplied into the
+// namespace of AccountHandler by the component that launches it (i.e. the
+// AccountManager).  Until then an AccountHandlerContext is supplied explicitly
+// in the initialization calls on the AccountHandlerControl interface.
 interface AccountHandlerContext {
     // Connects an interface to a particular AuthProvider, launching it if
     // necessary.