blob: 76113ca35c1442f0f32cbfb9577d16ede2db6f0a [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);
38
39 // mojom::GrammarChecker
40 void Check(chromeos::machine_learning::mojom::GrammarCheckerQueryPtr query,
41 CheckCallback callback) override;
42
43 bool successfully_loaded_;
44
45 // Pointer to the internal implementation of GrammarChecker inside the
46 // GrammarLibrary.
47 ::GrammarChecker checker_;
48 const ml::GrammarLibrary* const library_;
49
50 mojo::Receiver<chromeos::machine_learning::mojom::GrammarChecker> receiver_;
51
52 DISALLOW_COPY_AND_ASSIGN(GrammarCheckerImpl);
53};
54
55} // namespace ml
56
57#endif // ML_GRAMMAR_CHECKER_IMPL_H_