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

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

Issue 174213003: PPAPI: Use clang-format on ppapi/shared_impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove DEPS Created 6 years, 10 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
« no previous file with comments | « ppapi/shared_impl/dictionary_var.h ('k') | ppapi/shared_impl/dir_contents.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/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "ppapi/shared_impl/array_var.h" 9 #include "ppapi/shared_impl/array_var.h"
10 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
11 #include "ppapi/shared_impl/var_tracker.h" 11 #include "ppapi/shared_impl/var_tracker.h"
12 12
13 namespace ppapi { 13 namespace ppapi {
14 14
15 DictionaryVar::DictionaryVar() { 15 DictionaryVar::DictionaryVar() {}
16 }
17 16
18 DictionaryVar::~DictionaryVar() { 17 DictionaryVar::~DictionaryVar() {}
19 }
20 18
21 // static 19 // static
22 DictionaryVar* DictionaryVar::FromPPVar(const PP_Var& var) { 20 DictionaryVar* DictionaryVar::FromPPVar(const PP_Var& var) {
23 if (var.type != PP_VARTYPE_DICTIONARY) 21 if (var.type != PP_VARTYPE_DICTIONARY)
24 return NULL; 22 return NULL;
25 23
26 scoped_refptr<Var> var_object( 24 scoped_refptr<Var> var_object(
27 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); 25 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
28 if (!var_object.get()) 26 if (!var_object.get())
29 return NULL; 27 return NULL;
30 return var_object->AsDictionaryVar(); 28 return var_object->AsDictionaryVar();
31 } 29 }
32 30
33 DictionaryVar* DictionaryVar::AsDictionaryVar() { 31 DictionaryVar* DictionaryVar::AsDictionaryVar() { return this; }
34 return this;
35 }
36 32
37 PP_VarType DictionaryVar::GetType() const { 33 PP_VarType DictionaryVar::GetType() const { return PP_VARTYPE_DICTIONARY; }
38 return PP_VARTYPE_DICTIONARY;
39 }
40 34
41 PP_Var DictionaryVar::Get(const PP_Var& key) const { 35 PP_Var DictionaryVar::Get(const PP_Var& key) const {
42 StringVar* string_var = StringVar::FromPPVar(key); 36 StringVar* string_var = StringVar::FromPPVar(key);
43 if (!string_var) 37 if (!string_var)
44 return PP_MakeUndefined(); 38 return PP_MakeUndefined();
45 39
46 KeyValueMap::const_iterator iter = key_value_map_.find(string_var->value()); 40 KeyValueMap::const_iterator iter = key_value_map_.find(string_var->value());
47 if (iter != key_value_map_.end()) { 41 if (iter != key_value_map_.end()) {
48 if (PpapiGlobals::Get()->GetVarTracker()->AddRefVar(iter->second.get())) 42 if (PpapiGlobals::Get()->GetVarTracker()->AddRefVar(iter->second.get()))
49 return iter->second.get(); 43 return iter->second.get();
(...skipping 29 matching lines...) Expand all
79 bool result = 73 bool result =
80 key_value_map_.find(string_var->value()) != key_value_map_.end(); 74 key_value_map_.find(string_var->value()) != key_value_map_.end();
81 return PP_FromBool(result); 75 return PP_FromBool(result);
82 } 76 }
83 77
84 PP_Var DictionaryVar::GetKeys() const { 78 PP_Var DictionaryVar::GetKeys() const {
85 scoped_refptr<ArrayVar> array_var(new ArrayVar()); 79 scoped_refptr<ArrayVar> array_var(new ArrayVar());
86 array_var->elements().reserve(key_value_map_.size()); 80 array_var->elements().reserve(key_value_map_.size());
87 81
88 for (KeyValueMap::const_iterator iter = key_value_map_.begin(); 82 for (KeyValueMap::const_iterator iter = key_value_map_.begin();
89 iter != key_value_map_.end(); ++iter) { 83 iter != key_value_map_.end();
90 array_var->elements().push_back( 84 ++iter) {
91 ScopedPPVar(ScopedPPVar::PassRef(), 85 array_var->elements().push_back(ScopedPPVar(
92 StringVar::StringToPPVar(iter->first))); 86 ScopedPPVar::PassRef(), StringVar::StringToPPVar(iter->first)));
93 } 87 }
94 return array_var->GetPPVar(); 88 return array_var->GetPPVar();
95 } 89 }
96 90
97 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key, 91 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key,
98 const PP_Var& value) { 92 const PP_Var& value) {
99 if (!IsStringUTF8(utf8_key)) 93 if (!IsStringUTF8(utf8_key))
100 return false; 94 return false;
101 95
102 key_value_map_[utf8_key] = value; 96 key_value_map_[utf8_key] = value;
103 return true; 97 return true;
104 } 98 }
105 99
106 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) { 100 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) {
107 key_value_map_.erase(utf8_key); 101 key_value_map_.erase(utf8_key);
108 } 102 }
109 103
110 } // namespace ppapi 104 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/dictionary_var.h ('k') | ppapi/shared_impl/dir_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698