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

Side by Side Diff: ppapi/shared_impl/dictionary_var.cc

Issue 12388083: Add PPB_VarArray_Dev support - part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/array_var.cc ('k') | ppapi/shared_impl/var.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/dictionary_var.h" 5 #include "ppapi/shared_impl/dictionary_var.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "ppapi/shared_impl/array_var.h"
9 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
10 #include "ppapi/shared_impl/var_tracker.h" 11 #include "ppapi/shared_impl/var_tracker.h"
11 12
12 namespace ppapi { 13 namespace ppapi {
13 14
14 DictionaryVar::DictionaryVar() { 15 DictionaryVar::DictionaryVar() {
15 } 16 }
16 17
17 DictionaryVar::~DictionaryVar() { 18 DictionaryVar::~DictionaryVar() {
18 } 19 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 StringVar* string_var = StringVar::FromPPVar(key); 75 StringVar* string_var = StringVar::FromPPVar(key);
75 if (!string_var) 76 if (!string_var)
76 return PP_FALSE; 77 return PP_FALSE;
77 78
78 bool result = 79 bool result =
79 key_value_map_.find(string_var->value()) != key_value_map_.end(); 80 key_value_map_.find(string_var->value()) != key_value_map_.end();
80 return PP_FromBool(result); 81 return PP_FromBool(result);
81 } 82 }
82 83
83 PP_Var DictionaryVar::GetKeys() const { 84 PP_Var DictionaryVar::GetKeys() const {
84 // TODO(yzshen): Implement once array PP_Var is supported. 85 scoped_refptr<ArrayVar> array_var(new ArrayVar());
85 return PP_MakeNull(); 86 array_var->elements().reserve(key_value_map_.size());
87
88 for (KeyValueMap::const_iterator iter = key_value_map_.begin();
89 iter != key_value_map_.end(); ++iter) {
90 array_var->elements().push_back(
91 ScopedPPVar(ScopedPPVar::PassRef(),
92 StringVar::StringToPPVar(iter->first)));
93 }
94 return array_var->GetPPVar();
86 } 95 }
87 96
88 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key, 97 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key,
89 const PP_Var& value) { 98 const PP_Var& value) {
90 if (!IsStringUTF8(utf8_key)) 99 if (!IsStringUTF8(utf8_key))
91 return false; 100 return false;
92 101
93 key_value_map_[utf8_key] = value; 102 key_value_map_[utf8_key] = value;
94 return true; 103 return true;
95 } 104 }
96 105
97 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) { 106 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) {
98 key_value_map_.erase(utf8_key); 107 key_value_map_.erase(utf8_key);
99 } 108 }
100 109
101 } // namespace ppapi 110 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/array_var.cc ('k') | ppapi/shared_impl/var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698