| // Copyright 2023 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef SERVICES_WEBNN_WEBNN_CONTEXT_IMPL_H_ |
| #define SERVICES_WEBNN_WEBNN_CONTEXT_IMPL_H_ |
| |
| #include "base/component_export.h" |
| #include "mojo/public/cpp/bindings/pending_receiver.h" |
| #include "mojo/public/cpp/bindings/receiver.h" |
| #include "services/webnn/public/mojom/webnn_context_provider.mojom.h" |
| |
| namespace webnn { |
| |
| class WebNNContextProviderImpl; |
| |
| class COMPONENT_EXPORT(WEBNN_SERVICE) WebNNContextImpl |
| : public mojom::WebNNContext { |
| public: |
| WebNNContextImpl(mojo::PendingReceiver<mojom::WebNNContext> receiver, |
| WebNNContextProviderImpl* context_provider); |
| |
| WebNNContextImpl(const WebNNContextImpl&) = delete; |
| WebNNContextImpl& operator=(const WebNNContextImpl&) = delete; |
| |
| ~WebNNContextImpl() override; |
| |
| protected: |
| void OnConnectionError(); |
| |
| // mojom::WebNNContext |
| void CreateGraph(mojom::GraphInfoPtr graph_info, |
| CreateGraphCallback callback) override; |
| |
| // This method will be called by `CreateGraph()` after the graph info is |
| // validated. A backend subclass should implement this method to build and |
| // compile a platform specific graph asynchronously. |
| virtual void CreateGraphImpl(mojom::GraphInfoPtr graph_info, |
| CreateGraphCallback callback) = 0; |
| |
| mojo::Receiver<mojom::WebNNContext> receiver_; |
| |
| // Owns this object. |
| raw_ptr<WebNNContextProviderImpl> context_provider_; |
| }; |
| |
| } // namespace webnn |
| |
| #endif // SERVICES_WEBNN_WEBNN_CONTEXT_IMPL_H_ |