Create wire Client and Server classes with private impl

This creates proper Client and Server interfaces which will be necessary
for adding additional features to the Wire for chrome integration

Bug: dawn:103
Change-Id: I181e95079b0bac85c2c6152ad8066a94b80c8d28
Reviewed-on: https://dawn-review.googlesource.com/c/4002
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 8d0d8ed..bdd9141 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -760,6 +760,8 @@
   public_configs = [ ":dawn_public" ]
   sources = [
     "src/include/dawn_wire/Wire.h",
+    "src/include/dawn_wire/WireClient.h",
+    "src/include/dawn_wire/WireServer.h",
     "src/include/dawn_wire/dawn_wire_export.h",
   ]
 }
@@ -797,9 +799,10 @@
   configs = [ ":dawn_internal" ]
   sources = get_target_outputs(":libdawn_wire_gen")
   sources += [
-    "src/dawn_wire/DawnWire.cpp",
+    "src/dawn_wire/WireClient.cpp",
     "src/dawn_wire/WireDeserializeAllocator.cpp",
     "src/dawn_wire/WireDeserializeAllocator.h",
+    "src/dawn_wire/WireServer.cpp",
     "src/dawn_wire/client/ApiObjects.h",
     "src/dawn_wire/client/ApiProcs.cpp",
     "src/dawn_wire/client/Buffer.cpp",
diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp
index ecb20c2..7e1e731 100644
--- a/examples/SampleUtils.cpp
+++ b/examples/SampleUtils.cpp
@@ -20,9 +20,11 @@
 #include "utils/TerribleCommandBuffer.h"
 
 #include <dawn/dawn.h>
-#include <dawn/dawncpp.h>
 #include <dawn/dawn_wsi.h>
+#include <dawn/dawncpp.h>
 #include <dawn_native/DawnNative.h>
+#include <dawn_wire/WireClient.h>
+#include <dawn_wire/WireServer.h>
 #include "GLFW/glfw3.h"
 
 #include <cstring>
@@ -61,8 +63,8 @@
 
 static GLFWwindow* window = nullptr;
 
-static dawn_wire::CommandHandler* wireServer = nullptr;
-static dawn_wire::CommandHandler* wireClient = nullptr;
+static dawn_wire::WireServer* wireServer = nullptr;
+static dawn_wire::WireClient* wireClient = nullptr;
 static utils::TerribleCommandBuffer* c2sBuf = nullptr;
 static utils::TerribleCommandBuffer* s2cBuf = nullptr;
 
@@ -101,12 +103,12 @@
                 c2sBuf = new utils::TerribleCommandBuffer();
                 s2cBuf = new utils::TerribleCommandBuffer();
 
-                wireServer = dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
+                wireServer = new dawn_wire::WireServer(backendDevice, backendProcs, s2cBuf);
                 c2sBuf->SetHandler(wireServer);
 
-                dawnDevice clientDevice;
-                dawnProcTable clientProcs;
-                wireClient = dawn_wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
+                wireClient = new dawn_wire::WireClient(c2sBuf);
+                dawnDevice clientDevice = wireClient->GetDevice();
+                dawnProcTable clientProcs = wireClient->GetProcs();
                 s2cBuf->SetHandler(wireClient);
 
                 procs = clientProcs;
diff --git a/src/dawn_wire/DawnWire.cpp b/src/dawn_wire/DawnWire.cpp
deleted file mode 100644
index 56792d0..0000000
--- a/src/dawn_wire/DawnWire.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2019 The Dawn Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#include "dawn_wire/client/Client.h"
-#include "dawn_wire/server/Server.h"
-
-namespace dawn_wire {
-    CommandHandler* NewClientDevice(dawnProcTable* procs,
-                                    dawnDevice* device,
-                                    CommandSerializer* serializer) {
-        return new client::Client(procs, device, serializer);
-    }
-
-    CommandHandler* NewServerCommandHandler(dawnDevice device,
-                                            const dawnProcTable& procs,
-                                            CommandSerializer* serializer) {
-        return new server::Server(device, procs, serializer);
-    }
-}  // namespace dawn_wire
diff --git a/src/dawn_wire/WireClient.cpp b/src/dawn_wire/WireClient.cpp
new file mode 100644
index 0000000..e56348d
--- /dev/null
+++ b/src/dawn_wire/WireClient.cpp
@@ -0,0 +1,39 @@
+// Copyright 2019 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "dawn_wire/WireClient.h"
+#include "dawn_wire/client/Client.h"
+
+namespace dawn_wire {
+
+    WireClient::WireClient(CommandSerializer* serializer) : mImpl(new client::Client(serializer)) {
+    }
+
+    WireClient::~WireClient() {
+        mImpl.reset();
+    }
+
+    dawnDevice WireClient::GetDevice() const {
+        return mImpl->GetDevice();
+    }
+
+    dawnProcTable WireClient::GetProcs() const {
+        return client::GetProcs();
+    }
+
+    const char* WireClient::HandleCommands(const char* commands, size_t size) {
+        return mImpl->HandleCommands(commands, size);
+    }
+
+}  // namespace dawn_wire
diff --git a/src/dawn_wire/WireServer.cpp b/src/dawn_wire/WireServer.cpp
new file mode 100644
index 0000000..2c7ce1c
--- /dev/null
+++ b/src/dawn_wire/WireServer.cpp
@@ -0,0 +1,34 @@
+// Copyright 2019 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "dawn_wire/WireServer.h"
+#include "dawn_wire/server/Server.h"
+
+namespace dawn_wire {
+
+    WireServer::WireServer(dawnDevice device,
+                           const dawnProcTable& procs,
+                           CommandSerializer* serializer)
+        : mImpl(new server::Server(device, procs, serializer)) {
+    }
+
+    WireServer::~WireServer() {
+        mImpl.reset();
+    }
+
+    const char* WireServer::HandleCommands(const char* commands, size_t size) {
+        return mImpl->HandleCommands(commands, size);
+    }
+
+}  // namespace dawn_wire
diff --git a/src/dawn_wire/client/Client.cpp b/src/dawn_wire/client/Client.cpp
index ecd332e..ca2fe94 100644
--- a/src/dawn_wire/client/Client.cpp
+++ b/src/dawn_wire/client/Client.cpp
@@ -17,12 +17,10 @@
 
 namespace dawn_wire { namespace client {
 
-    Client::Client(dawnProcTable* procs, dawnDevice* device, CommandSerializer* serializer)
+    Client::Client(CommandSerializer* serializer)
         : ClientBase(),
           mDevice(DeviceAllocator().New(this)->object.get()),
           mSerializer(serializer) {
-        *device = reinterpret_cast<dawnDeviceImpl*>(mDevice);
-        *procs = client::GetProcs();
     }
 
     Client::~Client() {
diff --git a/src/dawn_wire/client/Client.h b/src/dawn_wire/client/Client.h
index 3f8a703..99f382c 100644
--- a/src/dawn_wire/client/Client.h
+++ b/src/dawn_wire/client/Client.h
@@ -25,9 +25,9 @@
 
     class Device;
 
-    class Client : public ClientBase, public CommandHandler {
+    class Client : public ClientBase {
       public:
-        Client(dawnProcTable* procs, dawnDevice* device, CommandSerializer* serializer);
+        Client(CommandSerializer* serializer);
         ~Client();
 
         const char* HandleCommands(const char* commands, size_t size);
@@ -36,6 +36,10 @@
             return mSerializer->GetCmdSpace(size);
         }
 
+        dawnDevice GetDevice() const {
+            return reinterpret_cast<dawnDeviceImpl*>(mDevice);
+        }
+
       private:
 #include "dawn_wire/client/ClientPrototypes_autogen.inl"
 
diff --git a/src/dawn_wire/server/Server.h b/src/dawn_wire/server/Server.h
index bc7b99d..aeb8107 100644
--- a/src/dawn_wire/server/Server.h
+++ b/src/dawn_wire/server/Server.h
@@ -35,7 +35,7 @@
         uint64_t value;
     };
 
-    class Server : public ServerBase, public CommandHandler {
+    class Server : public ServerBase {
       public:
         Server(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer);
         ~Server();
diff --git a/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp b/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
index 9160b29..91c91a9 100644
--- a/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
+++ b/src/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
@@ -15,7 +15,7 @@
 #include "common/Assert.h"
 #include "dawn/dawncpp.h"
 #include "dawn_native/DawnNative.h"
-#include "dawn_wire/Wire.h"
+#include "dawn_wire/WireServer.h"
 
 #include <vector>
 
@@ -61,8 +61,8 @@
     ASSERT(nullDevice.Get() != nullptr);
 
     DevNull devNull;
-    std::unique_ptr<dawn_wire::CommandHandler> wireServer(
-        dawn_wire::NewServerCommandHandler(nullDevice.Get(), procs, &devNull));
+    std::unique_ptr<dawn_wire::WireServer> wireServer(
+        new dawn_wire::WireServer(nullDevice.Get(), procs, &devNull));
 
     wireServer->HandleCommands(reinterpret_cast<const char*>(data), size);
 
diff --git a/src/include/dawn_wire/Wire.h b/src/include/dawn_wire/Wire.h
index f9cdd6e..b5ee54d 100644
--- a/src/include/dawn_wire/Wire.h
+++ b/src/include/dawn_wire/Wire.h
@@ -35,13 +35,6 @@
         virtual const char* HandleCommands(const char* commands, size_t size) = 0;
     };
 
-    DAWN_WIRE_EXPORT CommandHandler* NewClientDevice(dawnProcTable* procs,
-                                                     dawnDevice* device,
-                                                     CommandSerializer* serializer);
-    DAWN_WIRE_EXPORT CommandHandler* NewServerCommandHandler(dawnDevice device,
-                                                             const dawnProcTable& procs,
-                                                             CommandSerializer* serializer);
-
 }  // namespace dawn_wire
 
 #endif  // DAWNWIRE_WIRE_H_
diff --git a/src/include/dawn_wire/WireClient.h b/src/include/dawn_wire/WireClient.h
new file mode 100644
index 0000000..941ad51
--- /dev/null
+++ b/src/include/dawn_wire/WireClient.h
@@ -0,0 +1,43 @@
+// Copyright 2019 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef DAWNWIRE_WIRECLIENT_H_
+#define DAWNWIRE_WIRECLIENT_H_
+
+#include <memory>
+
+#include "dawn_wire/Wire.h"
+
+namespace dawn_wire {
+
+    namespace client {
+        class Client;
+    }
+
+    class DAWN_WIRE_EXPORT WireClient : public CommandHandler {
+      public:
+        WireClient(CommandSerializer* serializer);
+        ~WireClient();
+
+        dawnDevice GetDevice() const;
+        dawnProcTable GetProcs() const;
+        const char* HandleCommands(const char* commands, size_t size) override final;
+
+      private:
+        std::unique_ptr<client::Client> mImpl;
+    };
+
+}  // namespace dawn_wire
+
+#endif  // DAWNWIRE_WIRECLIENT_H_
diff --git a/src/include/dawn_wire/WireServer.h b/src/include/dawn_wire/WireServer.h
new file mode 100644
index 0000000..47a7056
--- /dev/null
+++ b/src/include/dawn_wire/WireServer.h
@@ -0,0 +1,41 @@
+// Copyright 2019 The Dawn Authors
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef DAWNWIRE_WIRESERVER_H_
+#define DAWNWIRE_WIRESERVER_H_
+
+#include <memory>
+
+#include "dawn_wire/Wire.h"
+
+namespace dawn_wire {
+
+    namespace server {
+        class Server;
+    }
+
+    class DAWN_WIRE_EXPORT WireServer : public CommandHandler {
+      public:
+        WireServer(dawnDevice device, const dawnProcTable& procs, CommandSerializer* serializer);
+        ~WireServer();
+
+        const char* HandleCommands(const char* commands, size_t size) override final;
+
+      private:
+        std::unique_ptr<server::Server> mImpl;
+    };
+
+}  // namespace dawn_wire
+
+#endif  // DAWNWIRE_WIRESERVER_H_
diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp
index 0637495..c643047 100644
--- a/src/tests/DawnTest.cpp
+++ b/src/tests/DawnTest.cpp
@@ -19,7 +19,8 @@
 #include "common/Math.h"
 #include "common/Platform.h"
 #include "dawn_native/DawnNative.h"
-#include "dawn_wire/Wire.h"
+#include "dawn_wire/WireClient.h"
+#include "dawn_wire/WireServer.h"
 #include "utils/BackendBinding.h"
 #include "utils/DawnHelpers.h"
 #include "utils/SystemUtils.h"
@@ -192,13 +193,12 @@
         mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>();
         mS2cBuf = std::make_unique<utils::TerribleCommandBuffer>();
 
-        mWireServer.reset(
-            dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, mS2cBuf.get()));
+        mWireServer.reset(new dawn_wire::WireServer(backendDevice, backendProcs, mS2cBuf.get()));
         mC2sBuf->SetHandler(mWireServer.get());
 
-        dawnDevice clientDevice;
-        dawnProcTable clientProcs;
-        mWireClient.reset(dawn_wire::NewClientDevice(&clientProcs, &clientDevice, mC2sBuf.get()));
+        mWireClient.reset(new dawn_wire::WireClient(mC2sBuf.get()));
+        dawnDevice clientDevice = mWireClient->GetDevice();
+        dawnProcTable clientProcs = mWireClient->GetProcs();
         mS2cBuf->SetHandler(mWireClient.get());
 
         procs = clientProcs;
diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h
index b77777e..7bce5ec 100644
--- a/src/tests/DawnTest.h
+++ b/src/tests/DawnTest.h
@@ -72,7 +72,8 @@
 }
 
 namespace dawn_wire {
-    class CommandHandler;
+    class WireClient;
+    class WireServer;
 }  // namespace dawn_wire
 
 class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
@@ -129,8 +130,8 @@
 
   private:
     // Things used to set up testing through the Wire.
-    std::unique_ptr<dawn_wire::CommandHandler> mWireServer;
-    std::unique_ptr<dawn_wire::CommandHandler> mWireClient;
+    std::unique_ptr<dawn_wire::WireServer> mWireServer;
+    std::unique_ptr<dawn_wire::WireClient> mWireClient;
     std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
     std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
     void FlushWire();
diff --git a/src/tests/unittests/WireTests.cpp b/src/tests/unittests/WireTests.cpp
index 9d59a42..72532b0 100644
--- a/src/tests/unittests/WireTests.cpp
+++ b/src/tests/unittests/WireTests.cpp
@@ -17,13 +17,13 @@
 
 #include "common/Assert.h"
 #include "common/Constants.h"
-#include "dawn_wire/Wire.h"
+#include "dawn_wire/WireClient.h"
+#include "dawn_wire/WireServer.h"
 #include "utils/TerribleCommandBuffer.h"
 
 #include <memory>
 
 using namespace testing;
-using namespace dawn_wire;
 
 // Definition of a "Lambda predicate matcher" for GMock to allow checking deep structures
 // are passed correctly by the wire.
@@ -156,11 +156,12 @@
             mS2cBuf = std::make_unique<utils::TerribleCommandBuffer>();
             mC2sBuf = std::make_unique<utils::TerribleCommandBuffer>(mWireServer.get());
 
-            mWireServer.reset(NewServerCommandHandler(mockDevice, mockProcs, mS2cBuf.get()));
+            mWireServer.reset(new dawn_wire::WireServer(mockDevice, mockProcs, mS2cBuf.get()));
             mC2sBuf->SetHandler(mWireServer.get());
 
-            dawnProcTable clientProcs;
-            mWireClient.reset(NewClientDevice(&clientProcs, &device, mC2sBuf.get()));
+            mWireClient.reset(new dawn_wire::WireClient(mC2sBuf.get()));
+            dawnProcTable clientProcs = mWireClient->GetProcs();
+            device = mWireClient->GetDevice();
             dawnSetProcs(&clientProcs);
             mS2cBuf->SetHandler(mWireClient.get());
 
@@ -197,8 +198,8 @@
     private:
         bool mIgnoreSetCallbackCalls = false;
 
-        std::unique_ptr<CommandHandler> mWireServer;
-        std::unique_ptr<CommandHandler> mWireClient;
+        std::unique_ptr<dawn_wire::WireServer> mWireServer;
+        std::unique_ptr<dawn_wire::WireClient> mWireClient;
         std::unique_ptr<utils::TerribleCommandBuffer> mS2cBuf;
         std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
 };