• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) : engine_(engine) {}
39 
CreateChannelImpl(const string & target,const grpc::ChannelArguments & args)40   std::shared_ptr<grpc::Channel> CreateChannelImpl(
41       const string& target, const grpc::ChannelArguments& args) override {
42     return CreateChannelWithInterceptors(
43         target, args,
44         std::vector<std::unique_ptr<
45             experimental::ClientInterceptorFactoryInterface>>());
46   }
47 
AsSecureCredentials()48   SecureChannelCredentials* AsSecureCredentials() override { return nullptr; }
49 
50  private:
CreateChannelWithInterceptors(const string & target,const grpc::ChannelArguments & args,std::vector<std::unique_ptr<experimental::ClientInterceptorFactoryInterface>> interceptor_creators)51   std::shared_ptr<grpc::Channel> CreateChannelWithInterceptors(
52       const string& target, const grpc::ChannelArguments& args,
53       std::vector<
54           std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
55           interceptor_creators) override {
56     grpc_channel_args channel_args;
57     args.SetChannelArgs(&channel_args);
58     return CreateChannelInternal(
59         "",
60         grpc_cronet_secure_channel_create(engine_, target.c_str(),
61                                           &channel_args, nullptr),
62         std::move(interceptor_creators));
63   }
64   void* engine_;
65 };
66 
CronetChannelCredentials(void * engine)67 std::shared_ptr<ChannelCredentials> CronetChannelCredentials(void* engine) {
68   return std::shared_ptr<ChannelCredentials>(
69       new grpc::CronetChannelCredentialsImpl(engine));
70 }
71 }  // namespace grpc
72