blob: a874a6e68f4dd6c979cd6e9e406717f8cc2b28e2 [file] [log] [blame]
Garrett Casto07ecd9d2016-10-21 14:31:39 -07001/*
2 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003 * Copyright 2016 gRPC authors.
Garrett Casto07ecd9d2016-10-21 14:31:39 -07004 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005 * 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 Casto07ecd9d2016-10-21 14:31:39 -07008 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009 * http://www.apache.org/licenses/LICENSE-2.0
Garrett Casto07ecd9d2016-10-21 14:31:39 -070010 *
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011 * 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 Casto07ecd9d2016-10-21 14:31:39 -070016 *
17 */
18
Garrett Casto931a26b2016-10-04 09:18:29 -070019#include <grpc++/security/credentials.h>
20
Garrett Casto931a26b2016-10-04 09:18:29 -070021#include <grpc++/channel.h>
22#include <grpc++/support/channel_arguments.h>
Garrett Castoa2a32502016-10-20 16:51:04 -070023#include <grpc/grpc_cronet.h>
Garrett Casto931a26b2016-10-04 09:18:29 -070024#include "src/cpp/client/create_channel_internal.h"
25
26namespace grpc {
27
Vijay Paic0b2acb2016-11-01 16:31:56 -070028class CronetChannelCredentialsImpl final : public ChannelCredentials {
Garrett Casto931a26b2016-10-04 09:18:29 -070029 public:
Garrett Castoa2a32502016-10-20 16:51:04 -070030 CronetChannelCredentialsImpl(void* engine) : engine_(engine) {}
Garrett Casto931a26b2016-10-04 09:18:29 -070031
32 std::shared_ptr<grpc::Channel> CreateChannel(
Vijay Paic0b2acb2016-11-01 16:31:56 -070033 const string& target, const grpc::ChannelArguments& args) override {
Garrett Casto931a26b2016-10-04 09:18:29 -070034 grpc_channel_args channel_args;
35 args.SetChannelArgs(&channel_args);
36 return CreateChannelInternal(
Garrett Castoa2a32502016-10-20 16:51:04 -070037 "", grpc_cronet_secure_channel_create(engine_, target.c_str(),
38 &channel_args, nullptr));
Garrett Casto931a26b2016-10-04 09:18:29 -070039 }
40
Vijay Pai713c7b82016-11-01 16:33:18 -070041 SecureChannelCredentials* AsSecureCredentials() override { return nullptr; }
Garrett Casto931a26b2016-10-04 09:18:29 -070042
Garrett Castoa2a32502016-10-20 16:51:04 -070043 private:
Garrett Casto931a26b2016-10-04 09:18:29 -070044 void* engine_;
45};
46
47std::shared_ptr<ChannelCredentials> CronetChannelCredentials(void* engine) {
48 return std::shared_ptr<ChannelCredentials>(
49 new CronetChannelCredentialsImpl(engine));
50}
51
52} // namespace grpc