blob: f9f9bc60c534dff8f0d1fc72b93bb31579e3ae72 [file] [log] [blame]
Jing Wang961b8af2020-10-26 12:40:35 +11001// Copyright 2020 The Chromium OS 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 ML_GRAMMAR_CHECKER_IMPL_H_
6#define ML_GRAMMAR_CHECKER_IMPL_H_
7
8#include <base/callback_forward.h>
9#include <base/macros.h>
10#include <mojo/public/cpp/bindings/pending_receiver.h>
11#include <mojo/public/cpp/bindings/receiver.h>
12
13#include "chrome/knowledge/grammar/grammar_interface.pb.h"
14#include "ml/grammar_library.h"
15#include "ml/mojom/grammar_checker.mojom.h"
16
17namespace ml {
18
19class GrammarCheckerImpl
20 : public chromeos::machine_learning::mojom::GrammarChecker {
21 public:
22 // Constructs a GrammarCheckerImpl; and set disconnect handler so that the
23 // GrammarCheckerImpl will be deleted when the mojom connection is destroyed.
24 // Returns whether the object is create successfully.
25 static bool Create(
26 mojo::PendingReceiver<chromeos::machine_learning::mojom::GrammarChecker>
27 receiver);
28
29 // Called when mojom connection is destroyed.
30 ~GrammarCheckerImpl();
31
32 private:
33 // Creates a GrammarChecker and Binds to `receiver` inside so that Check can
34 // be called on the other side for a particular grammar check query.
35 GrammarCheckerImpl(
36 mojo::PendingReceiver<chromeos::machine_learning::mojom::GrammarChecker>
37 receiver);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090038 GrammarCheckerImpl(const GrammarCheckerImpl&) = delete;
39 GrammarCheckerImpl& operator=(const GrammarCheckerImpl&) = delete;
Jing Wang961b8af2020-10-26 12:40:35 +110040
41 // mojom::GrammarChecker
42 void Check(chromeos::machine_learning::mojom::GrammarCheckerQueryPtr query,
43 CheckCallback callback) override;
44
45 bool successfully_loaded_;
46
47 // Pointer to the internal implementation of GrammarChecker inside the
48 // GrammarLibrary.
49 ::GrammarChecker checker_;
50 const ml::GrammarLibrary* const library_;
51
52 mojo::Receiver<chromeos::machine_learning::mojom::GrammarChecker> receiver_;
Jing Wang961b8af2020-10-26 12:40:35 +110053};
54
55} // namespace ml
56
57#endif // ML_GRAMMAR_CHECKER_IMPL_H_