1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_ARC_MIDIS_ARC_MIDIS_BRIDGE_H_ 6 #define COMPONENTS_ARC_MIDIS_ARC_MIDIS_BRIDGE_H_ 7 8 #include <stdint.h> 9 10 #include <vector> 11 12 #include "base/macros.h" 13 #include "components/arc/mojom/midis.mojom.h" 14 #include "components/keyed_service/core/keyed_service.h" 15 #include "mojo/public/cpp/bindings/pending_receiver.h" 16 #include "mojo/public/cpp/bindings/pending_remote.h" 17 #include "mojo/public/cpp/bindings/remote.h" 18 19 namespace content { 20 class BrowserContext; 21 } // namespace content 22 23 namespace arc { 24 25 class ArcBridgeService; 26 27 class ArcMidisBridge : public KeyedService, 28 public mojom::MidisHost { 29 public: 30 // Returns singleton instance for the given BrowserContext, 31 // or nullptr if the browser |context| is not allowed to use ARC. 32 static ArcMidisBridge* GetForBrowserContext(content::BrowserContext* context); 33 34 ArcMidisBridge(content::BrowserContext* context, 35 ArcBridgeService* bridge_service); 36 ~ArcMidisBridge() override; 37 38 // Midis Mojo host interface 39 void Connect(mojo::PendingReceiver<mojom::MidisServer> receiver, 40 mojo::PendingRemote<mojom::MidisClient> client_remote) override; 41 42 private: 43 void OnBootstrapMojoConnection( 44 mojo::PendingReceiver<mojom::MidisServer> receiver, 45 mojo::PendingRemote<mojom::MidisClient> client_remote, 46 bool result); 47 void OnMojoConnectionError(); 48 49 ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager. 50 mojo::Remote<mojom::MidisHost> midis_host_remote_; 51 52 // WeakPtrFactory to use for callbacks. 53 base::WeakPtrFactory<ArcMidisBridge> weak_factory_{this}; 54 55 DISALLOW_COPY_AND_ASSIGN(ArcMidisBridge); 56 }; 57 58 } // namespace arc 59 60 #endif // COMPONENTS_ARC_MIDIS_ARC_MIDIS_BRIDGE_H_ 61