Garrett Casto | 07ecd9d | 2016-10-21 14:31:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | * Copyright 2016 gRPC authors. |
Garrett Casto | 07ecd9d | 2016-10-21 14:31:39 -0700 | [diff] [blame] | 4 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Garrett Casto | 07ecd9d | 2016-10-21 14:31:39 -0700 | [diff] [blame] | 8 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
Garrett Casto | 07ecd9d | 2016-10-21 14:31:39 -0700 | [diff] [blame] | 10 | * |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Garrett Casto | 07ecd9d | 2016-10-21 14:31:39 -0700 | [diff] [blame] | 16 | * |
| 17 | */ |
| 18 | |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 19 | #include <grpc++/security/credentials.h> |
| 20 | |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 21 | #include <grpc++/channel.h> |
| 22 | #include <grpc++/support/channel_arguments.h> |
Garrett Casto | a2a3250 | 2016-10-20 16:51:04 -0700 | [diff] [blame] | 23 | #include <grpc/grpc_cronet.h> |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 24 | #include "src/cpp/client/create_channel_internal.h" |
| 25 | |
| 26 | namespace grpc { |
| 27 | |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 28 | class CronetChannelCredentialsImpl final : public ChannelCredentials { |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 29 | public: |
Garrett Casto | a2a3250 | 2016-10-20 16:51:04 -0700 | [diff] [blame] | 30 | CronetChannelCredentialsImpl(void* engine) : engine_(engine) {} |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 31 | |
| 32 | std::shared_ptr<grpc::Channel> CreateChannel( |
Vijay Pai | c0b2acb | 2016-11-01 16:31:56 -0700 | [diff] [blame] | 33 | const string& target, const grpc::ChannelArguments& args) override { |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 34 | grpc_channel_args channel_args; |
| 35 | args.SetChannelArgs(&channel_args); |
| 36 | return CreateChannelInternal( |
Garrett Casto | a2a3250 | 2016-10-20 16:51:04 -0700 | [diff] [blame] | 37 | "", grpc_cronet_secure_channel_create(engine_, target.c_str(), |
| 38 | &channel_args, nullptr)); |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Vijay Pai | 713c7b8 | 2016-11-01 16:33:18 -0700 | [diff] [blame] | 41 | SecureChannelCredentials* AsSecureCredentials() override { return nullptr; } |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 42 | |
Garrett Casto | a2a3250 | 2016-10-20 16:51:04 -0700 | [diff] [blame] | 43 | private: |
Garrett Casto | 931a26b | 2016-10-04 09:18:29 -0700 | [diff] [blame] | 44 | void* engine_; |
| 45 | }; |
| 46 | |
| 47 | std::shared_ptr<ChannelCredentials> CronetChannelCredentials(void* engine) { |
| 48 | return std::shared_ptr<ChannelCredentials>( |
| 49 | new CronetChannelCredentialsImpl(engine)); |
| 50 | } |
| 51 | |
| 52 | } // namespace grpc |