charleszhao | 17777f9 | 2020-04-23 12:53:11 +1000 | [diff] [blame] | 1 | // 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_HANDWRITING_RECOGNIZER_IMPL_H_ |
| 6 | #define ML_HANDWRITING_RECOGNIZER_IMPL_H_ |
| 7 | |
| 8 | #include <base/callback_forward.h> |
| 9 | #include <base/macros.h> |
| 10 | #include <mojo/public/cpp/bindings/binding.h> |
| 11 | |
| 12 | #include "chrome/knowledge/handwriting/interface.pb.h" |
| 13 | #include "ml/handwriting.h" |
| 14 | #include "ml/mojom/handwriting_recognizer.mojom.h" |
| 15 | |
| 16 | namespace ml { |
| 17 | |
| 18 | // The implementation of HandwritingRecognizer. |
| 19 | class HandwritingRecognizerImpl |
| 20 | : public chromeos::machine_learning::mojom::HandwritingRecognizer { |
| 21 | public: |
| 22 | // Constructs a HandwritingRecognizerImpl; and set_connection_error_handler so |
| 23 | // that the HandwritingRecognizerImpl will be deleted when the mojom |
| 24 | // connection is destroyed. |
| 25 | // Returns whether the object is create successfully. |
| 26 | static bool Create( |
charleszhao | 05c5a4a | 2020-06-09 16:49:54 +1000 | [diff] [blame] | 27 | chromeos::machine_learning::mojom::HandwritingRecognizerSpecPtr spec, |
charleszhao | 17777f9 | 2020-04-23 12:53:11 +1000 | [diff] [blame] | 28 | chromeos::machine_learning::mojom::HandwritingRecognizerRequest request); |
| 29 | |
| 30 | // Called when mojom connection is destroyed. |
| 31 | ~HandwritingRecognizerImpl(); |
| 32 | |
| 33 | private: |
Andrew Moylan | 79b34a4 | 2020-07-08 11:13:11 +1000 | [diff] [blame] | 34 | // Creates a HandwritingRecognizer and Binds to `request` inside so that |
charleszhao | 17777f9 | 2020-04-23 12:53:11 +1000 | [diff] [blame] | 35 | // Recognize can be called on the other side for a particular handwriting |
| 36 | // reconition query. |
| 37 | HandwritingRecognizerImpl( |
charleszhao | 05c5a4a | 2020-06-09 16:49:54 +1000 | [diff] [blame] | 38 | chromeos::machine_learning::mojom::HandwritingRecognizerSpecPtr spec, |
charleszhao | 17777f9 | 2020-04-23 12:53:11 +1000 | [diff] [blame] | 39 | chromeos::machine_learning::mojom::HandwritingRecognizerRequest request); |
| 40 | |
| 41 | // mojom::HandwritingRecognizer: |
| 42 | void Recognize( |
| 43 | chromeos::machine_learning::mojom::HandwritingRecognitionQueryPtr query, |
| 44 | RecognizeCallback callback) override; |
| 45 | |
| 46 | bool successfully_loaded_; |
| 47 | // Pointer to the internal implementation of HandwritingRecognizer inside |
| 48 | // the HandwritingLibrary. |
| 49 | ::HandwritingRecognizer recognizer_; |
| 50 | |
| 51 | mojo::Binding<chromeos::machine_learning::mojom::HandwritingRecognizer> |
| 52 | binding_; |
| 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(HandwritingRecognizerImpl); |
| 55 | }; |
| 56 | |
| 57 | } // namespace ml |
| 58 | |
| 59 | #endif // ML_HANDWRITING_RECOGNIZER_IMPL_H_ |