Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: ppapi/native_client/tests/nacl_browser/browser_startup_time/hello_world.cc

Issue 10914053: Relocating files in the nacl repo that belong in chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/native_client/tests/nacl_browser/browser_startup_time/hello_world.cc
diff --git a/ppapi/native_client/tests/nacl_browser/browser_startup_time/hello_world.cc b/ppapi/native_client/tests/nacl_browser/browser_startup_time/hello_world.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d7b408e1425e21adb2b2f863b4e0d51045000825
--- /dev/null
+++ b/ppapi/native_client/tests/nacl_browser/browser_startup_time/hello_world.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// A basic PPAPI-based hello world. Used to measure the size and startup
+// time of a really small program.
+
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/var.h"
+
+namespace {
+// The expected string sent by the browser.
+const char* const kHelloString = "hello";
+
+// The string sent back to the browser upon receipt of a message
+// containing "hello".
+const char* const kReplyString = "hello from NaCl";
+} // namespace
+
+namespace hello_world {
+class HelloWorldInstance : public pp::Instance {
+ public:
+ explicit HelloWorldInstance(PP_Instance instance) : pp::Instance(instance) {}
+ virtual ~HelloWorldInstance() {}
+ virtual void HandleMessage(const pp::Var& var_message);
+};
+
+void HelloWorldInstance::HandleMessage(const pp::Var& var_message) {
+ if (!var_message.is_string()) {
+ return;
+ }
+ std::string message = var_message.AsString();
+ pp::Var var_reply;
+ if (message == kHelloString)
+ var_reply = pp::Var(kReplyString);
+ PostMessage(var_reply);
+}
+
+class HelloWorldModule : public pp::Module {
+ public:
+ HelloWorldModule() : pp::Module() {}
+ virtual ~HelloWorldModule() {}
+
+ virtual pp::Instance* CreateInstance(PP_Instance instance) {
+ return new HelloWorldInstance(instance);
+ }
+};
+} // namespace hello_world
+
+namespace pp {
+/// Factory function called by the browser when the module is first loaded.
+/// The browser keeps a singleton of this module. It calls the
+/// CreateInstance() method on the object you return to make instances. There
+/// is one instance per <embed> tag on the page. This is the main binding
+/// point for your NaCl module with the browser.
+/// @return new HelloWorldModule.
+/// @note The browser is responsible for deleting returned @a Module.
+Module* CreateModule() {
+ return new hello_world::HelloWorldModule();
+}
+} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698