xref: /aosp_15_r20/external/grpc-grpc/src/cpp/client/cronet_credentials.cc (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 //
2 //
3 // Copyright 2016 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include <grpc/grpc.h>
25 #include <grpc/grpc_cronet.h>
26 #include <grpcpp/channel.h>
27 #include <grpcpp/security/credentials.h>
28 #include <grpcpp/support/channel_arguments.h>
29 #include <grpcpp/support/client_interceptor.h>
30 #include <grpcpp/support/config.h>
31 
32 #include "src/cpp/client/create_channel_internal.h"
33 
34 namespace grpc {
35 
36 class CronetChannelCredentialsImpl final : public ChannelCredentials {
37  public:
CronetChannelCredentialsImpl(void * engine)38   explicit CronetChannelCredentialsImpl(void* engine)
39       : ChannelCredentials(nullptr), engine_(engine) {}
40 
41  private:
CreateChannelWithInterceptors(const string & target,const grpc::ChannelArguments & args,std::vector<std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators)42   std::shared_ptr<grpc::Channel> CreateChannelWithInterceptors(
43       const string& target, const grpc::ChannelArguments& args,
44       std::vector<
45           std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
46           interceptor_creators) override {
47     grpc_channel_args channel_args;
48     args.SetChannelArgs(&channel_args);
49     return CreateChannelInternal(
50         "",
51         grpc_cronet_secure_channel_create(engine_, target.c_str(),
52                                           &channel_args, nullptr),
53         std::move(interceptor_creators));
54   }
55 
56   void* engine_;
57 };
58 
CronetChannelCredentials(void * engine)59 std::shared_ptr<ChannelCredentials> CronetChannelCredentials(void* engine) {
60   return std::shared_ptr<ChannelCredentials>(
61       new grpc::CronetChannelCredentialsImpl(engine));
62 }
63 }  // namespace grpc
64