Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 1 | // Copyright 2019 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 REMOTING_CLIENT_JNI_JNI_DIRECTORY_SERVICE_H_ |
| 6 | #define REMOTING_CLIENT_JNI_JNI_DIRECTORY_SERVICE_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | |
| 10 | #include "base/android/scoped_java_ref.h" |
| 11 | #include "base/memory/scoped_refptr.h" |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 12 | #include "base/memory/weak_ptr.h" |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 13 | #include "base/sequence_checker.h" |
| 14 | #include "base/sequenced_task_runner.h" |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 15 | #include "base/threading/sequence_bound.h" |
| 16 | #include "remoting/base/directory_service_client.h" |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 17 | |
| 18 | namespace remoting { |
| 19 | |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 20 | class ProtobufHttpStatus; |
| 21 | |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 22 | class JniDirectoryService { |
| 23 | public: |
| 24 | // TODO(rkjnsn): Update error codes to better align with those returned by the |
| 25 | // new gRPC API. |
| 26 | // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chromoting.jni |
| 27 | // GENERATED_JAVA_CLASS_NAME_OVERRIDE: DirectoryServiceRequestError |
| 28 | enum class RequestError : int { |
| 29 | AUTH_FAILED = 0, |
| 30 | NETWORK_ERROR = 1, |
| 31 | SERVICE_UNAVAILABLE = 2, |
| 32 | UNEXPECTED_RESPONSE = 3, |
| 33 | UNKNOWN = 4, |
| 34 | }; |
| 35 | JniDirectoryService(); |
| 36 | ~JniDirectoryService(); |
| 37 | |
| 38 | void RetrieveHostList(JNIEnv* env, |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 39 | const base::android::JavaParamRef<jobject>& callback); |
| 40 | void DeleteHost(JNIEnv* env, |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 41 | const base::android::JavaParamRef<jstring>& host_id, |
| 42 | const base::android::JavaParamRef<jobject>& callback); |
| 43 | |
Eric Stevenson | d6b8ada | 2019-07-26 21:26:06 | [diff] [blame] | 44 | void Destroy(JNIEnv* env); |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 45 | |
| 46 | private: |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 47 | void OnHostListRetrieved( |
| 48 | base::android::ScopedJavaGlobalRef<jobject> callback, |
| 49 | const ProtobufHttpStatus& status, |
| 50 | std::unique_ptr<apis::v1::GetHostListResponse> response); |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 51 | void OnHostDeleted(base::android::ScopedJavaGlobalRef<jobject> callback, |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 52 | const ProtobufHttpStatus& status, |
| 53 | std::unique_ptr<apis::v1::DeleteHostResponse> response); |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 54 | |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 55 | base::SequenceBound<DirectoryServiceClient> client_; |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 56 | scoped_refptr<base::SequencedTaskRunner> sequence_; |
| 57 | SEQUENCE_CHECKER(sequence_checker_); |
Yuwei Huang | fa4b0e7 | 2020-07-28 00:08:38 | [diff] [blame^] | 58 | |
| 59 | base::WeakPtrFactory<JniDirectoryService> weak_factory_{this}; |
Erik Jensen | 1662a30 | 2019-05-08 19:34:46 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } // namespace remoting |
| 63 | |
| 64 | #endif // REMOTING_CLIENT_JNI_JNI_DIRECTORY_SERVICE_H_ |