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

Unified Diff: ppapi/cpp/dev/string_wrapper_dev.cc

Issue 60173003: Draft: apps APIs in Pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « ppapi/cpp/dev/string_wrapper_dev.h ('k') | ppapi/cpp/dev/struct_wrapper_base_dev.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/dev/string_wrapper_dev.cc
diff --git a/ppapi/cpp/dev/string_wrapper_dev.cc b/ppapi/cpp/dev/string_wrapper_dev.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e26e259797c23b94e011453aa20e7b484881bf42
--- /dev/null
+++ b/ppapi/cpp/dev/string_wrapper_dev.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2013 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.
+
+#include "ppapi/cpp/dev/string_wrapper_dev.h"
+
+#include "ppapi/cpp/logging.h"
+#include "ppapi/cpp/var.h"
+
+namespace pp {
+namespace internal {
+
+StringWrapper::StringWrapper(PP_Var* storage, NotOwned)
+ : storage_(storage, NOT_OWNED) {
+ // TODO(yzshen): consider what if the value is not correct.
+ PP_DCHECK(storage_->type == PP_VARTYPE_UNDEFINED);
+}
+
+StringWrapper::StringWrapper(const std::string& value) {
+ *storage_ = Var(value).Detach();
+}
+
+StringWrapper::StringWrapper(const StringWrapper& other) {
+ // Add one ref.
+ *storage_ = Var(*other.storage_).Detach();
+}
+
+StringWrapper::~StringWrapper() {
+ Var auto_release(PASS_REF, *storage_);
+ *storage_ = PP_MakeUndefined();
+}
+
+StringWrapper& StringWrapper::operator=(const StringWrapper& other) {
+ return operator=(*other.storage_);
+}
+
+StringWrapper& StringWrapper::operator=(const PP_Var& other) {
+ if (storage_.get() == &other)
+ return *this;
+
+ Var auto_release(PASS_REF, *storage_);
+ // Add one ref.
+ *storage_ = Var(other).Detach();
+ return *this;
+}
+
+bool StringWrapper::is_set() const {
+ PP_DCHECK(storage_->type == PP_VARTYPE_STRING ||
+ storage_->type == PP_VARTYPE_UNDEFINED);
+ return storage_->type == PP_VARTYPE_STRING;
+}
+
+void StringWrapper::unset() {
+ Var auto_release(PASS_REF, *storage_);
+ *storage_ = PP_MakeUndefined();
+}
+
+std::string StringWrapper::get() const {
+ Var var(*storage_);
+ if (var.is_string()) {
+ return var.AsString();
+ } else {
+ PP_NOTREACHED();
+ return std::string();
+ }
+}
+
+void StringWrapper::set(const std::string& value) {
+ Var auto_release(PASS_REF, *storage_);
+ *storage_ = Var(value).Detach();
+}
+
+} // namespace internal
+} // namespace pp
« no previous file with comments | « ppapi/cpp/dev/string_wrapper_dev.h ('k') | ppapi/cpp/dev/struct_wrapper_base_dev.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698