Index: third_party/grpc/examples/cpp/helloworld/greeter_server.cc |
diff --git a/third_party/WebKit/public/web/WebScopedUserGesture.h b/third_party/grpc/examples/cpp/helloworld/greeter_server.cc |
similarity index 50% |
copy from third_party/WebKit/public/web/WebScopedUserGesture.h |
copy to third_party/grpc/examples/cpp/helloworld/greeter_server.cc |
index a4e3903f3f4dc20439ba672f8492318d829aa197..9eab32c62b481ef45135797b64f4619ed3420399 100644 |
--- a/third_party/WebKit/public/web/WebScopedUserGesture.h |
+++ b/third_party/grpc/examples/cpp/helloworld/greeter_server.cc |
@@ -1,5 +1,7 @@ |
/* |
- * Copyright (C) 2011 Google Inc. All rights reserved. |
+ * |
+ * 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 |
@@ -26,45 +28,56 @@ |
* 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 WebScopedUserGesture_h |
-#define WebScopedUserGesture_h |
+#include <iostream> |
+#include <memory> |
+#include <string> |
-#include "../platform/WebPrivateOwnPtr.h" |
+#include <grpc++/grpc++.h> |
-namespace blink { |
+#include "helloworld.grpc.pb.h" |
-class UserGestureIndicator; |
-class WebUserGestureToken; |
+using grpc::Server; |
+using grpc::ServerBuilder; |
+using grpc::ServerContext; |
+using grpc::Status; |
+using helloworld::HelloRequest; |
+using helloworld::HelloReply; |
+using helloworld::Greeter; |
-// An instance of this class, while kept alive, will indicate that we are in |
-// the context of a known user gesture. To use, create one, perform whatever |
-// actions were done under color of a known user gesture, and then delete it. |
-// Usually this will be done on the stack. |
-// |
-// SECURITY WARNING: Do not create several instances of this class for the same |
-// user gesture. Doing so might enable malicious code to work around certain |
-// restrictions such as opening multiple windows. |
-// Instead, obtain the current WebUserGestureToken from the |
-// WebUserGestureIndicator, and use this token to create a |
-// WebScopedUserGesture. If the token was alrady consumed, the new |
-// WebScopedUserGesture will not indicate that we are in the context of a user |
-// gesture. |
-class WebScopedUserGesture { |
-public: |
- explicit WebScopedUserGesture(const WebUserGestureToken& token) { initializeWithToken(token); } |
- WebScopedUserGesture() { initialize(); } |
- ~WebScopedUserGesture() { reset(); } |
+// Logic and data behind the server's behavior. |
+class GreeterServiceImpl final : public Greeter::Service { |
+ Status SayHello(ServerContext* context, const HelloRequest* request, |
+ HelloReply* reply) override { |
+ std::string prefix("Hello "); |
+ reply->set_message(prefix + request->name()); |
+ return Status::OK; |
+ } |
+}; |
-private: |
- BLINK_EXPORT void initialize(); |
- BLINK_EXPORT void initializeWithToken(const WebUserGestureToken&); |
- BLINK_EXPORT void reset(); |
+void RunServer() { |
+ std::string server_address("0.0.0.0:50051"); |
+ GreeterServiceImpl service; |
- WebPrivateOwnPtr<UserGestureIndicator> m_indicator; |
-}; |
+ ServerBuilder builder; |
+ // Listen on the given address without any authentication mechanism. |
+ builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); |
+ // Register "service" as the instance through which we'll communicate with |
+ // clients. In this case it corresponds to an *synchronous* service. |
+ builder.RegisterService(&service); |
+ // Finally assemble the server. |
+ std::unique_ptr<Server> server(builder.BuildAndStart()); |
+ std::cout << "Server listening on " << server_address << std::endl; |
+ |
+ // Wait for the server to shutdown. Note that some other thread must be |
+ // responsible for shutting down the server for this call to ever return. |
+ server->Wait(); |
+} |
-} // namespace blink |
+int main(int argc, char** argv) { |
+ RunServer(); |
-#endif // WebScopedUserGesture_h |
+ return 0; |
+} |