blob: a5ed47eb5b74ca0914c46e5d82ceb955938a2771 [file] [log] [blame]
// Copyright 2019 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 "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/arc/mojom/keymaster.mojom.h"
#include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc {
class ArcBridgeService;
// This class is responsible for providing a KeymasterServer proxy by
// bootstrapping a mojo connection with the arc-keymasterd daemon. The mojo
// connection is bootstrapped lazily during the first call to GetServer. Chrome
// has no further involvement once the KeymasterServer proxy has been forwarded
// to the KeymasterInstance in ARC.
class ArcKeymasterBridge : public KeyedService, public mojom::KeymasterHost {
// Returns singleton instance for the given BrowserContext, or nullptr if the
// browser |context| is not allowed to use ARC.
static ArcKeymasterBridge* GetForBrowserContext(
content::BrowserContext* context);
ArcKeymasterBridge(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcKeymasterBridge() override;
// KeymasterHost mojo interface.
using mojom::KeymasterHost::GetServerCallback;
void GetServer(GetServerCallback callback) override;
void BootstrapMojoConnection(GetServerCallback callback);
void OnBootstrapMojoConnection(GetServerCallback callback, bool result);
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
// Points to a proxy bound to the implementation in arc-keymasterd.
mojom::KeymasterServerPtr keymaster_server_proxy_;
// WeakPtrFactory to use for callbacks.
base::WeakPtrFactory<ArcKeymasterBridge> weak_factory_;
} // namespace arc