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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/cpp/dev/string_wrapper_dev.h"
6
7 #include "ppapi/cpp/logging.h"
8 #include "ppapi/cpp/var.h"
9
10 namespace pp {
11 namespace internal {
12
13 StringWrapper::StringWrapper(PP_Var* storage, NotOwned)
14 : storage_(storage, NOT_OWNED) {
15 // TODO(yzshen): consider what if the value is not correct.
16 PP_DCHECK(storage_->type == PP_VARTYPE_UNDEFINED);
17 }
18
19 StringWrapper::StringWrapper(const std::string& value) {
20 *storage_ = Var(value).Detach();
21 }
22
23 StringWrapper::StringWrapper(const StringWrapper& other) {
24 // Add one ref.
25 *storage_ = Var(*other.storage_).Detach();
26 }
27
28 StringWrapper::~StringWrapper() {
29 Var auto_release(PASS_REF, *storage_);
30 *storage_ = PP_MakeUndefined();
31 }
32
33 StringWrapper& StringWrapper::operator=(const StringWrapper& other) {
34 return operator=(*other.storage_);
35 }
36
37 StringWrapper& StringWrapper::operator=(const PP_Var& other) {
38 if (storage_.get() == &other)
39 return *this;
40
41 Var auto_release(PASS_REF, *storage_);
42 // Add one ref.
43 *storage_ = Var(other).Detach();
44 return *this;
45 }
46
47 bool StringWrapper::is_set() const {
48 PP_DCHECK(storage_->type == PP_VARTYPE_STRING ||
49 storage_->type == PP_VARTYPE_UNDEFINED);
50 return storage_->type == PP_VARTYPE_STRING;
51 }
52
53 void StringWrapper::unset() {
54 Var auto_release(PASS_REF, *storage_);
55 *storage_ = PP_MakeUndefined();
56 }
57
58 std::string StringWrapper::get() const {
59 Var var(*storage_);
60 if (var.is_string()) {
61 return var.AsString();
62 } else {
63 PP_NOTREACHED();
64 return std::string();
65 }
66 }
67
68 void StringWrapper::set(const std::string& value) {
69 Var auto_release(PASS_REF, *storage_);
70 *storage_ = Var(value).Detach();
71 }
72
73 } // namespace internal
74 } // namespace pp
OLDNEW
« 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