Merge pull request #4207 from yang-g/server_builder_options

Server builder options
diff --git a/BUILD b/BUILD
index f1395da..ee3ce57 100644
--- a/BUILD
+++ b/BUILD
@@ -748,14 +748,13 @@
     "src/cpp/server/dynamic_thread_pool.h",
     "src/cpp/server/fixed_size_thread_pool.h",
     "src/cpp/server/thread_pool_interface.h",
-    "src/cpp/client/secure_channel_arguments.cc",
     "src/cpp/client/secure_credentials.cc",
     "src/cpp/common/auth_property_iterator.cc",
     "src/cpp/common/secure_auth_context.cc",
+    "src/cpp/common/secure_channel_arguments.cc",
     "src/cpp/common/secure_create_auth_context.cc",
     "src/cpp/server/secure_server_credentials.cc",
     "src/cpp/client/channel.cc",
-    "src/cpp/client/channel_arguments.cc",
     "src/cpp/client/client_context.cc",
     "src/cpp/client/create_channel.cc",
     "src/cpp/client/create_channel_internal.cc",
@@ -763,6 +762,7 @@
     "src/cpp/client/generic_stub.cc",
     "src/cpp/client/insecure_credentials.cc",
     "src/cpp/common/call.cc",
+    "src/cpp/common/channel_arguments.cc",
     "src/cpp/common/completion_queue.cc",
     "src/cpp/common/rpc_method.cc",
     "src/cpp/proto/proto_utils.cc",
@@ -796,6 +796,7 @@
     "include/grpc++/impl/rpc_method.h",
     "include/grpc++/impl/rpc_service_method.h",
     "include/grpc++/impl/serialization_traits.h",
+    "include/grpc++/impl/server_builder_option.h",
     "include/grpc++/impl/service_type.h",
     "include/grpc++/impl/sync.h",
     "include/grpc++/impl/sync_cxx11.h",
@@ -847,7 +848,6 @@
     "src/cpp/server/thread_pool_interface.h",
     "src/cpp/common/insecure_create_auth_context.cc",
     "src/cpp/client/channel.cc",
-    "src/cpp/client/channel_arguments.cc",
     "src/cpp/client/client_context.cc",
     "src/cpp/client/create_channel.cc",
     "src/cpp/client/create_channel_internal.cc",
@@ -855,6 +855,7 @@
     "src/cpp/client/generic_stub.cc",
     "src/cpp/client/insecure_credentials.cc",
     "src/cpp/common/call.cc",
+    "src/cpp/common/channel_arguments.cc",
     "src/cpp/common/completion_queue.cc",
     "src/cpp/common/rpc_method.cc",
     "src/cpp/proto/proto_utils.cc",
@@ -888,6 +889,7 @@
     "include/grpc++/impl/rpc_method.h",
     "include/grpc++/impl/rpc_service_method.h",
     "include/grpc++/impl/serialization_traits.h",
+    "include/grpc++/impl/server_builder_option.h",
     "include/grpc++/impl/service_type.h",
     "include/grpc++/impl/sync.h",
     "include/grpc++/impl/sync_cxx11.h",
diff --git a/Makefile b/Makefile
index d6a6dcd..00fa921 100644
--- a/Makefile
+++ b/Makefile
@@ -5098,14 +5098,13 @@
 
 
 LIBGRPC++_SRC = \
-    src/cpp/client/secure_channel_arguments.cc \
     src/cpp/client/secure_credentials.cc \
     src/cpp/common/auth_property_iterator.cc \
     src/cpp/common/secure_auth_context.cc \
+    src/cpp/common/secure_channel_arguments.cc \
     src/cpp/common/secure_create_auth_context.cc \
     src/cpp/server/secure_server_credentials.cc \
     src/cpp/client/channel.cc \
-    src/cpp/client/channel_arguments.cc \
     src/cpp/client/client_context.cc \
     src/cpp/client/create_channel.cc \
     src/cpp/client/create_channel_internal.cc \
@@ -5113,6 +5112,7 @@
     src/cpp/client/generic_stub.cc \
     src/cpp/client/insecure_credentials.cc \
     src/cpp/common/call.cc \
+    src/cpp/common/channel_arguments.cc \
     src/cpp/common/completion_queue.cc \
     src/cpp/common/rpc_method.cc \
     src/cpp/proto/proto_utils.cc \
@@ -5146,6 +5146,7 @@
     include/grpc++/impl/rpc_method.h \
     include/grpc++/impl/rpc_service_method.h \
     include/grpc++/impl/serialization_traits.h \
+    include/grpc++/impl/server_builder_option.h \
     include/grpc++/impl/service_type.h \
     include/grpc++/impl/sync.h \
     include/grpc++/impl/sync_cxx11.h \
@@ -5351,7 +5352,6 @@
 LIBGRPC++_UNSECURE_SRC = \
     src/cpp/common/insecure_create_auth_context.cc \
     src/cpp/client/channel.cc \
-    src/cpp/client/channel_arguments.cc \
     src/cpp/client/client_context.cc \
     src/cpp/client/create_channel.cc \
     src/cpp/client/create_channel_internal.cc \
@@ -5359,6 +5359,7 @@
     src/cpp/client/generic_stub.cc \
     src/cpp/client/insecure_credentials.cc \
     src/cpp/common/call.cc \
+    src/cpp/common/channel_arguments.cc \
     src/cpp/common/completion_queue.cc \
     src/cpp/common/rpc_method.cc \
     src/cpp/proto/proto_utils.cc \
@@ -5392,6 +5393,7 @@
     include/grpc++/impl/rpc_method.h \
     include/grpc++/impl/rpc_service_method.h \
     include/grpc++/impl/serialization_traits.h \
+    include/grpc++/impl/server_builder_option.h \
     include/grpc++/impl/service_type.h \
     include/grpc++/impl/sync.h \
     include/grpc++/impl/sync_cxx11.h \
@@ -10694,7 +10696,7 @@
 
 
 CHANNEL_ARGUMENTS_TEST_SRC = \
-    test/cpp/client/channel_arguments_test.cc \
+    test/cpp/common/channel_arguments_test.cc \
 
 CHANNEL_ARGUMENTS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHANNEL_ARGUMENTS_TEST_SRC))))
 ifeq ($(NO_SECURE),true)
@@ -10723,7 +10725,7 @@
 
 endif
 
-$(OBJDIR)/$(CONFIG)/test/cpp/client/channel_arguments_test.o:  $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
+$(OBJDIR)/$(CONFIG)/test/cpp/common/channel_arguments_test.o:  $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
 deps_channel_arguments_test: $(CHANNEL_ARGUMENTS_TEST_OBJS:.o=.dep)
 
 ifneq ($(NO_SECURE),true)
@@ -24259,10 +24261,10 @@
 src/core/tsi/fake_transport_security.c: $(OPENSSL_DEP)
 src/core/tsi/ssl_transport_security.c: $(OPENSSL_DEP)
 src/core/tsi/transport_security.c: $(OPENSSL_DEP)
-src/cpp/client/secure_channel_arguments.cc: $(OPENSSL_DEP)
 src/cpp/client/secure_credentials.cc: $(OPENSSL_DEP)
 src/cpp/common/auth_property_iterator.cc: $(OPENSSL_DEP)
 src/cpp/common/secure_auth_context.cc: $(OPENSSL_DEP)
+src/cpp/common/secure_channel_arguments.cc: $(OPENSSL_DEP)
 src/cpp/common/secure_create_auth_context.cc: $(OPENSSL_DEP)
 src/cpp/server/secure_server_credentials.cc: $(OPENSSL_DEP)
 src/csharp/ext/grpc_csharp_ext.c: $(OPENSSL_DEP)
diff --git a/build.yaml b/build.yaml
index 0f9f63f..b993ff9 100644
--- a/build.yaml
+++ b/build.yaml
@@ -37,6 +37,7 @@
   - include/grpc++/impl/rpc_method.h
   - include/grpc++/impl/rpc_service_method.h
   - include/grpc++/impl/serialization_traits.h
+  - include/grpc++/impl/server_builder_option.h
   - include/grpc++/impl/service_type.h
   - include/grpc++/impl/sync.h
   - include/grpc++/impl/sync_cxx11.h
@@ -72,7 +73,6 @@
   - src/cpp/server/thread_pool_interface.h
   src:
   - src/cpp/client/channel.cc
-  - src/cpp/client/channel_arguments.cc
   - src/cpp/client/client_context.cc
   - src/cpp/client/create_channel.cc
   - src/cpp/client/create_channel_internal.cc
@@ -80,6 +80,7 @@
   - src/cpp/client/generic_stub.cc
   - src/cpp/client/insecure_credentials.cc
   - src/cpp/common/call.cc
+  - src/cpp/common/channel_arguments.cc
   - src/cpp/common/completion_queue.cc
   - src/cpp/common/rpc_method.cc
   - src/cpp/proto/proto_utils.cc
@@ -612,10 +613,10 @@
   - src/cpp/common/secure_auth_context.h
   - src/cpp/server/secure_server_credentials.h
   src:
-  - src/cpp/client/secure_channel_arguments.cc
   - src/cpp/client/secure_credentials.cc
   - src/cpp/common/auth_property_iterator.cc
   - src/cpp/common/secure_auth_context.cc
+  - src/cpp/common/secure_channel_arguments.cc
   - src/cpp/common/secure_create_auth_context.cc
   - src/cpp/server/secure_server_credentials.cc
   deps:
@@ -1692,7 +1693,7 @@
   build: test
   language: c++
   src:
-  - test/cpp/client/channel_arguments_test.cc
+  - test/cpp/common/channel_arguments_test.cc
   deps:
   - grpc++
   - grpc
diff --git a/include/grpc++/impl/server_builder_option.h b/include/grpc++/impl/server_builder_option.h
new file mode 100644
index 0000000..bcb1982
--- /dev/null
+++ b/include/grpc++/impl/server_builder_option.h
@@ -0,0 +1,51 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_IMPL_SERVER_BUILDER_OPTION_H
+#define GRPCXX_IMPL_SERVER_BUILDER_OPTION_H
+
+#include <grpc++/support/channel_arguments.h>
+
+namespace grpc {
+
+/// Interface to pass an option to a \a ServerBuilder.
+class ServerBuilderOption {
+ public:
+  virtual ~ServerBuilderOption() {}
+  /// Alter the \a ChannelArguments used to create the gRPC server.
+  virtual void UpdateArguments(ChannelArguments* args) = 0;
+};
+
+}  // namespace grpc
+
+#endif  // GRPCXX_IMPL_SERVER_BUILDER_OPTION_H
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index 7bb3cdf..644e66e 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -37,14 +37,15 @@
 #include <list>
 #include <memory>
 
-#include <grpc/compression.h>
 #include <grpc++/completion_queue.h>
 #include <grpc++/impl/call.h>
 #include <grpc++/impl/grpc_library.h>
 #include <grpc++/impl/sync.h>
 #include <grpc++/security/server_credentials.h>
+#include <grpc++/support/channel_arguments.h>
 #include <grpc++/support/config.h>
 #include <grpc++/support/status.h>
+#include <grpc/compression.h>
 
 struct grpc_server;
 
@@ -118,7 +119,7 @@
   /// \param max_message_size Maximum message length that the channel can
   /// receive.
   Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
-         int max_message_size, grpc_compression_options compression_options);
+         int max_message_size, const ChannelArguments& args);
 
   /// Register a service. This call does not take ownership of the service.
   /// The service must exist for the lifetime of the Server instance.
diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index 05937f1..b324deb 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -37,8 +37,9 @@
 #include <memory>
 #include <vector>
 
-#include <grpc/compression.h>
+#include <grpc++/impl/server_builder_option.h>
 #include <grpc++/support/config.h>
+#include <grpc/compression.h>
 
 namespace grpc {
 
@@ -98,6 +99,8 @@
     compression_options_ = options;
   }
 
+  void SetOption(std::unique_ptr<ServerBuilderOption> option);
+
   /// Tries to bind \a server to the given \a addr.
   ///
   /// It can be invoked multiple times.
@@ -140,6 +143,7 @@
 
   int max_message_size_;
   grpc_compression_options compression_options_;
+  std::vector<std::unique_ptr<ServerBuilderOption>> options_;
   std::vector<std::unique_ptr<NamedService<RpcService>>> services_;
   std::vector<std::unique_ptr<NamedService<AsynchronousService>>>
       async_services_;
diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h
index cf8eab3..a2960a7 100644
--- a/include/grpc++/support/channel_arguments.h
+++ b/include/grpc++/support/channel_arguments.h
@@ -80,6 +80,11 @@
   // Generic channel argument setters. Only for advanced use cases.
   /// Set an integer argument \a value under \a key.
   void SetInt(const grpc::string& key, int value);
+
+  // Generic channel argument setter. Only for advanced use cases.
+  /// Set a pointer argument \a value under \a key. Owership is not transferred.
+  void SetPointer(const grpc::string& key, void* value);
+
   /// Set a textual argument \a value under \a key.
   void SetString(const grpc::string& key, const grpc::string& value);
 
diff --git a/src/cpp/client/channel_arguments.cc b/src/cpp/common/channel_arguments.cc
similarity index 87%
rename from src/cpp/client/channel_arguments.cc
rename to src/cpp/common/channel_arguments.cc
index 50422d0..90cd513 100644
--- a/src/cpp/client/channel_arguments.cc
+++ b/src/cpp/common/channel_arguments.cc
@@ -62,7 +62,9 @@
         break;
       case GRPC_ARG_POINTER:
         ap.value.pointer = a->value.pointer;
-        ap.value.pointer.p = a->value.pointer.copy(ap.value.pointer.p);
+        ap.value.pointer.p = a->value.pointer.copy
+                                 ? a->value.pointer.copy(ap.value.pointer.p)
+                                 : ap.value.pointer.p;
         break;
     }
     args_.push_back(ap);
@@ -89,6 +91,17 @@
   args_.push_back(arg);
 }
 
+void ChannelArguments::SetPointer(const grpc::string& key, void* value) {
+  grpc_arg arg;
+  arg.type = GRPC_ARG_POINTER;
+  strings_.push_back(key);
+  arg.key = const_cast<char*>(strings_.back().c_str());
+  arg.value.pointer.p = value;
+  arg.value.pointer.copy = nullptr;
+  arg.value.pointer.destroy = nullptr;
+  args_.push_back(arg);
+}
+
 void ChannelArguments::SetString(const grpc::string& key,
                                  const grpc::string& value) {
   grpc_arg arg;
diff --git a/src/cpp/client/secure_channel_arguments.cc b/src/cpp/common/secure_channel_arguments.cc
similarity index 100%
rename from src/cpp/client/secure_channel_arguments.cc
rename to src/cpp/common/secure_channel_arguments.cc
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index 377c1ed..878775b 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -269,36 +269,21 @@
   grpc_completion_queue* cq_;
 };
 
-static grpc_server* CreateServer(
-    int max_message_size, const grpc_compression_options& compression_options) {
-  grpc_arg args[2];
-  size_t args_idx = 0;
-  if (max_message_size > 0) {
-    args[args_idx].type = GRPC_ARG_INTEGER;
-    args[args_idx].key = const_cast<char*>(GRPC_ARG_MAX_MESSAGE_LENGTH);
-    args[args_idx].value.integer = max_message_size;
-    args_idx++;
-  }
-
-  args[args_idx].type = GRPC_ARG_INTEGER;
-  args[args_idx].key = const_cast<char*>(GRPC_COMPRESSION_ALGORITHM_STATE_ARG);
-  args[args_idx].value.integer = compression_options.enabled_algorithms_bitset;
-  args_idx++;
-
-  grpc_channel_args channel_args = {args_idx, args};
+static grpc_server* CreateServer(const ChannelArguments& args) {
+  grpc_channel_args channel_args;
+  args.SetChannelArgs(&channel_args);
   return grpc_server_create(&channel_args, nullptr);
 }
 
 Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
-               int max_message_size,
-               grpc_compression_options compression_options)
+               int max_message_size, const ChannelArguments& args)
     : max_message_size_(max_message_size),
       started_(false),
       shutdown_(false),
       num_running_cb_(0),
       sync_methods_(new std::list<SyncRequest>),
       has_generic_service_(false),
-      server_(CreateServer(max_message_size, compression_options)),
+      server_(CreateServer(args)),
       thread_pool_(thread_pool),
       thread_pool_owned_(thread_pool_owned) {
   gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks);
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index b8094aa..26c0724 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -84,6 +84,10 @@
   generic_service_ = service;
 }
 
+void ServerBuilder::SetOption(std::unique_ptr<ServerBuilderOption> option) {
+  options_.push_back(std::move(option));
+}
+
 void ServerBuilder::AddListeningPort(const grpc::string& addr,
                                      std::shared_ptr<ServerCredentials> creds,
                                      int* selected_port) {
@@ -101,9 +105,17 @@
     thread_pool_ = CreateDefaultThreadPool();
     thread_pool_owned = true;
   }
-  std::unique_ptr<Server> server(new Server(thread_pool_, thread_pool_owned,
-                                            max_message_size_,
-                                            compression_options_));
+  ChannelArguments args;
+  for (auto option = options_.begin(); option != options_.end(); ++option) {
+    (*option)->UpdateArguments(&args);
+  }
+  if (max_message_size_ > 0) {
+    args.SetInt(GRPC_ARG_MAX_MESSAGE_LENGTH, max_message_size_);
+  }
+  args.SetInt(GRPC_COMPRESSION_ALGORITHM_STATE_ARG,
+              compression_options_.enabled_algorithms_bitset);
+  std::unique_ptr<Server> server(
+      new Server(thread_pool_, thread_pool_owned, max_message_size_, args));
   for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) {
     grpc_server_register_completion_queue(server->server_, (*cq)->cq(),
                                           nullptr);
diff --git a/test/cpp/client/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc
similarity index 89%
rename from test/cpp/client/channel_arguments_test.cc
rename to test/cpp/common/channel_arguments_test.cc
index 3d75e7b..e010d37 100644
--- a/test/cpp/client/channel_arguments_test.cc
+++ b/test/cpp/common/channel_arguments_test.cc
@@ -115,6 +115,22 @@
   }
 }
 
+TEST_F(ChannelArgumentsTest, SetPointer) {
+  grpc_channel_args args;
+  ChannelArguments channel_args;
+  // Empty arguments.
+  SetChannelArgs(channel_args, &args);
+  EXPECT_EQ(static_cast<size_t>(0), args.num_args);
+
+  grpc::string key("key0");
+  channel_args.SetPointer(key, &key);
+  SetChannelArgs(channel_args, &args);
+  EXPECT_EQ(static_cast<size_t>(1), args.num_args);
+  EXPECT_EQ(GRPC_ARG_POINTER, args.args[0].type);
+  EXPECT_STREQ("key0", args.args[0].key);
+  EXPECT_EQ(&key, args.args[0].value.pointer.p);
+}
+
 }  // namespace testing
 }  // namespace grpc
 
diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++
index f077185..500d110 100644
--- a/tools/doxygen/Doxyfile.c++
+++ b/tools/doxygen/Doxyfile.c++
@@ -774,6 +774,7 @@
 include/grpc++/impl/rpc_method.h \
 include/grpc++/impl/rpc_service_method.h \
 include/grpc++/impl/serialization_traits.h \
+include/grpc++/impl/server_builder_option.h \
 include/grpc++/impl/service_type.h \
 include/grpc++/impl/sync.h \
 include/grpc++/impl/sync_cxx11.h \
diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal
index 11aaa37..ba1dec0 100644
--- a/tools/doxygen/Doxyfile.c++.internal
+++ b/tools/doxygen/Doxyfile.c++.internal
@@ -774,6 +774,7 @@
 include/grpc++/impl/rpc_method.h \
 include/grpc++/impl/rpc_service_method.h \
 include/grpc++/impl/serialization_traits.h \
+include/grpc++/impl/server_builder_option.h \
 include/grpc++/impl/service_type.h \
 include/grpc++/impl/sync.h \
 include/grpc++/impl/sync_cxx11.h \
@@ -809,14 +810,13 @@
 src/cpp/server/dynamic_thread_pool.h \
 src/cpp/server/fixed_size_thread_pool.h \
 src/cpp/server/thread_pool_interface.h \
-src/cpp/client/secure_channel_arguments.cc \
 src/cpp/client/secure_credentials.cc \
 src/cpp/common/auth_property_iterator.cc \
 src/cpp/common/secure_auth_context.cc \
+src/cpp/common/secure_channel_arguments.cc \
 src/cpp/common/secure_create_auth_context.cc \
 src/cpp/server/secure_server_credentials.cc \
 src/cpp/client/channel.cc \
-src/cpp/client/channel_arguments.cc \
 src/cpp/client/client_context.cc \
 src/cpp/client/create_channel.cc \
 src/cpp/client/create_channel_internal.cc \
@@ -824,6 +824,7 @@
 src/cpp/client/generic_stub.cc \
 src/cpp/client/insecure_credentials.cc \
 src/cpp/common/call.cc \
+src/cpp/common/channel_arguments.cc \
 src/cpp/common/completion_queue.cc \
 src/cpp/common/rpc_method.cc \
 src/cpp/proto/proto_utils.cc \
diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json
index ed896d2..df19892 100644
--- a/tools/run_tests/sources_and_headers.json
+++ b/tools/run_tests/sources_and_headers.json
@@ -1153,7 +1153,7 @@
     "language": "c++", 
     "name": "channel_arguments_test", 
     "src": [
-      "test/cpp/client/channel_arguments_test.cc"
+      "test/cpp/common/channel_arguments_test.cc"
     ]
   }, 
   {
@@ -15319,6 +15319,7 @@
       "include/grpc++/impl/rpc_method.h", 
       "include/grpc++/impl/rpc_service_method.h", 
       "include/grpc++/impl/serialization_traits.h", 
+      "include/grpc++/impl/server_builder_option.h", 
       "include/grpc++/impl/service_type.h", 
       "include/grpc++/impl/sync.h", 
       "include/grpc++/impl/sync_cxx11.h", 
@@ -15372,6 +15373,7 @@
       "include/grpc++/impl/rpc_method.h", 
       "include/grpc++/impl/rpc_service_method.h", 
       "include/grpc++/impl/serialization_traits.h", 
+      "include/grpc++/impl/server_builder_option.h", 
       "include/grpc++/impl/service_type.h", 
       "include/grpc++/impl/sync.h", 
       "include/grpc++/impl/sync_cxx11.h", 
@@ -15400,7 +15402,6 @@
       "include/grpc++/support/sync_stream.h", 
       "include/grpc++/support/time.h", 
       "src/cpp/client/channel.cc", 
-      "src/cpp/client/channel_arguments.cc", 
       "src/cpp/client/client_context.cc", 
       "src/cpp/client/create_channel.cc", 
       "src/cpp/client/create_channel_internal.cc", 
@@ -15408,16 +15409,17 @@
       "src/cpp/client/credentials.cc", 
       "src/cpp/client/generic_stub.cc", 
       "src/cpp/client/insecure_credentials.cc", 
-      "src/cpp/client/secure_channel_arguments.cc", 
       "src/cpp/client/secure_credentials.cc", 
       "src/cpp/client/secure_credentials.h", 
       "src/cpp/common/auth_property_iterator.cc", 
       "src/cpp/common/call.cc", 
+      "src/cpp/common/channel_arguments.cc", 
       "src/cpp/common/completion_queue.cc", 
       "src/cpp/common/create_auth_context.h", 
       "src/cpp/common/rpc_method.cc", 
       "src/cpp/common/secure_auth_context.cc", 
       "src/cpp/common/secure_auth_context.h", 
+      "src/cpp/common/secure_channel_arguments.cc", 
       "src/cpp/common/secure_create_auth_context.cc", 
       "src/cpp/proto/proto_utils.cc", 
       "src/cpp/server/async_generic_service.cc", 
@@ -15503,6 +15505,7 @@
       "include/grpc++/impl/rpc_method.h", 
       "include/grpc++/impl/rpc_service_method.h", 
       "include/grpc++/impl/serialization_traits.h", 
+      "include/grpc++/impl/server_builder_option.h", 
       "include/grpc++/impl/service_type.h", 
       "include/grpc++/impl/sync.h", 
       "include/grpc++/impl/sync_cxx11.h", 
@@ -15553,6 +15556,7 @@
       "include/grpc++/impl/rpc_method.h", 
       "include/grpc++/impl/rpc_service_method.h", 
       "include/grpc++/impl/serialization_traits.h", 
+      "include/grpc++/impl/server_builder_option.h", 
       "include/grpc++/impl/service_type.h", 
       "include/grpc++/impl/sync.h", 
       "include/grpc++/impl/sync_cxx11.h", 
@@ -15581,7 +15585,6 @@
       "include/grpc++/support/sync_stream.h", 
       "include/grpc++/support/time.h", 
       "src/cpp/client/channel.cc", 
-      "src/cpp/client/channel_arguments.cc", 
       "src/cpp/client/client_context.cc", 
       "src/cpp/client/create_channel.cc", 
       "src/cpp/client/create_channel_internal.cc", 
@@ -15590,6 +15593,7 @@
       "src/cpp/client/generic_stub.cc", 
       "src/cpp/client/insecure_credentials.cc", 
       "src/cpp/common/call.cc", 
+      "src/cpp/common/channel_arguments.cc", 
       "src/cpp/common/completion_queue.cc", 
       "src/cpp/common/create_auth_context.h", 
       "src/cpp/common/insecure_create_auth_context.cc", 
diff --git a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj
index 74b0fbf..663709d 100644
--- a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj
+++ b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj
@@ -251,6 +251,7 @@
     <ClInclude Include="..\..\..\include\grpc++\impl\rpc_method.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\rpc_service_method.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\serialization_traits.h" />
+    <ClInclude Include="..\..\..\include\grpc++\impl\server_builder_option.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\service_type.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\sync.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\sync_cxx11.h" />
@@ -291,8 +292,6 @@
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\channel.cc">
     </ClCompile>
-    <ClCompile Include="..\..\..\src\cpp\client\channel_arguments.cc">
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\client_context.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\create_channel.cc">
@@ -307,6 +306,8 @@
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\call.cc">
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\channel_arguments.cc">
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\completion_queue.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\rpc_method.cc">
diff --git a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
index 96effe2..05bb819 100644
--- a/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
+++ b/vsprojects/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
@@ -7,9 +7,6 @@
     <ClCompile Include="..\..\..\src\cpp\client\channel.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\..\src\cpp\client\channel_arguments.cc">
-      <Filter>src\cpp\client</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\client_context.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
@@ -31,6 +28,9 @@
     <ClCompile Include="..\..\..\src\cpp\common\call.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\channel_arguments.cc">
+      <Filter>src\cpp\common</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\completion_queue.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
@@ -126,6 +126,9 @@
     <ClInclude Include="..\..\..\include\grpc++\impl\serialization_traits.h">
       <Filter>include\grpc++\impl</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\include\grpc++\impl\server_builder_option.h">
+      <Filter>include\grpc++\impl</Filter>
+    </ClInclude>
     <ClInclude Include="..\..\..\include\grpc++\impl\service_type.h">
       <Filter>include\grpc++\impl</Filter>
     </ClInclude>
diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj
index 9f88c72..2ddf4be 100644
--- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj
+++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj
@@ -251,6 +251,7 @@
     <ClInclude Include="..\..\..\include\grpc++\impl\rpc_method.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\rpc_service_method.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\serialization_traits.h" />
+    <ClInclude Include="..\..\..\include\grpc++\impl\server_builder_option.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\service_type.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\sync.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\sync_cxx11.h" />
@@ -290,22 +291,20 @@
     <ClInclude Include="..\..\..\src\cpp\server\thread_pool_interface.h" />
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="..\..\..\src\cpp\client\secure_channel_arguments.cc">
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\secure_credentials.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\auth_property_iterator.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\secure_auth_context.cc">
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\secure_channel_arguments.cc">
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\secure_create_auth_context.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\server\secure_server_credentials.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\channel.cc">
     </ClCompile>
-    <ClCompile Include="..\..\..\src\cpp\client\channel_arguments.cc">
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\client_context.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\create_channel.cc">
@@ -320,6 +319,8 @@
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\call.cc">
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\channel_arguments.cc">
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\completion_queue.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\rpc_method.cc">
diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
index 7d9cd47..782af6f 100644
--- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
@@ -1,9 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <ClCompile Include="..\..\..\src\cpp\client\secure_channel_arguments.cc">
-      <Filter>src\cpp\client</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\secure_credentials.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
@@ -13,6 +10,9 @@
     <ClCompile Include="..\..\..\src\cpp\common\secure_auth_context.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\secure_channel_arguments.cc">
+      <Filter>src\cpp\common</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\secure_create_auth_context.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
@@ -22,9 +22,6 @@
     <ClCompile Include="..\..\..\src\cpp\client\channel.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\..\src\cpp\client\channel_arguments.cc">
-      <Filter>src\cpp\client</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\client_context.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
@@ -46,6 +43,9 @@
     <ClCompile Include="..\..\..\src\cpp\common\call.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\channel_arguments.cc">
+      <Filter>src\cpp\common</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\completion_queue.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
@@ -141,6 +141,9 @@
     <ClInclude Include="..\..\..\include\grpc++\impl\serialization_traits.h">
       <Filter>include\grpc++\impl</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\include\grpc++\impl\server_builder_option.h">
+      <Filter>include\grpc++\impl</Filter>
+    </ClInclude>
     <ClInclude Include="..\..\..\include\grpc++\impl\service_type.h">
       <Filter>include\grpc++\impl</Filter>
     </ClInclude>
diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
index 74b0fbf..663709d 100644
--- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
+++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
@@ -251,6 +251,7 @@
     <ClInclude Include="..\..\..\include\grpc++\impl\rpc_method.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\rpc_service_method.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\serialization_traits.h" />
+    <ClInclude Include="..\..\..\include\grpc++\impl\server_builder_option.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\service_type.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\sync.h" />
     <ClInclude Include="..\..\..\include\grpc++\impl\sync_cxx11.h" />
@@ -291,8 +292,6 @@
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\channel.cc">
     </ClCompile>
-    <ClCompile Include="..\..\..\src\cpp\client\channel_arguments.cc">
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\client_context.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\create_channel.cc">
@@ -307,6 +306,8 @@
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\call.cc">
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\channel_arguments.cc">
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\completion_queue.cc">
     </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\rpc_method.cc">
diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
index 96effe2..05bb819 100644
--- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
@@ -7,9 +7,6 @@
     <ClCompile Include="..\..\..\src\cpp\client\channel.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\..\src\cpp\client\channel_arguments.cc">
-      <Filter>src\cpp\client</Filter>
-    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\client\client_context.cc">
       <Filter>src\cpp\client</Filter>
     </ClCompile>
@@ -31,6 +28,9 @@
     <ClCompile Include="..\..\..\src\cpp\common\call.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\..\src\cpp\common\channel_arguments.cc">
+      <Filter>src\cpp\common</Filter>
+    </ClCompile>
     <ClCompile Include="..\..\..\src\cpp\common\completion_queue.cc">
       <Filter>src\cpp\common</Filter>
     </ClCompile>
@@ -126,6 +126,9 @@
     <ClInclude Include="..\..\..\include\grpc++\impl\serialization_traits.h">
       <Filter>include\grpc++\impl</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\..\include\grpc++\impl\server_builder_option.h">
+      <Filter>include\grpc++\impl</Filter>
+    </ClInclude>
     <ClInclude Include="..\..\..\include\grpc++\impl\service_type.h">
       <Filter>include\grpc++\impl</Filter>
     </ClInclude>
diff --git a/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj b/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj
index 5b7e3a6..08e0910 100644
--- a/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj
+++ b/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj
@@ -145,7 +145,7 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="..\..\..\..\test\cpp\client\channel_arguments_test.cc">
+    <ClCompile Include="..\..\..\..\test\cpp\common\channel_arguments_test.cc">
     </ClCompile>
   </ItemGroup>
   <ItemGroup>
diff --git a/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj.filters b/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj.filters
index 99153d2..d2517f7 100644
--- a/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj.filters
+++ b/vsprojects/vcxproj/test/channel_arguments_test/channel_arguments_test.vcxproj.filters
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
-    <ClCompile Include="..\..\..\..\test\cpp\client\channel_arguments_test.cc">
-      <Filter>test\cpp\client</Filter>
+    <ClCompile Include="..\..\..\..\test\cpp\common\channel_arguments_test.cc">
+      <Filter>test\cpp\common</Filter>
     </ClCompile>
   </ItemGroup>
 
@@ -13,8 +13,8 @@
     <Filter Include="test\cpp">
       <UniqueIdentifier>{16fb3cfd-129c-a846-b9a5-dbec55fd83a8}</UniqueIdentifier>
     </Filter>
-    <Filter Include="test\cpp\client">
-      <UniqueIdentifier>{49a87562-f2d0-2d95-9dfa-87ebf2aed951}</UniqueIdentifier>
+    <Filter Include="test\cpp\common">
+      <UniqueIdentifier>{641fdf8b-9e1d-4d66-c744-217b0b527616}</UniqueIdentifier>
     </Filter>
   </ItemGroup>
 </Project>