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

Side by Side Diff: ppapi/proxy/raw_var_data.cc

Issue 1649623002: Update ppapi to not use linked_ptr or ScopedVector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mark RawVarDataGraph as DISALLOW_COPY_AND_ASSIGN Created 4 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/proxy/raw_var_data.h ('k') | ppapi/shared_impl/resource_tracker.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/proxy/raw_var_data.h" 5 #include "ppapi/proxy/raw_var_data.h"
6 6
7 #include <stack> 7 #include <stack>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 26 matching lines...) Expand all
37 PP_Var var; 37 PP_Var var;
38 size_t data_index; 38 size_t data_index;
39 }; 39 };
40 40
41 // For a given PP_Var, returns the RawVarData associated with it, or creates a 41 // For a given PP_Var, returns the RawVarData associated with it, or creates a
42 // new one if there is no existing one. The data is appended to |data| if it 42 // new one if there is no existing one. The data is appended to |data| if it
43 // is newly created. The index into |data| pointing to the result is returned. 43 // is newly created. The index into |data| pointing to the result is returned.
44 // |visited_map| keeps track of RawVarDatas that have already been created. 44 // |visited_map| keeps track of RawVarDatas that have already been created.
45 size_t GetOrCreateRawVarData(const PP_Var& var, 45 size_t GetOrCreateRawVarData(const PP_Var& var,
46 base::hash_map<int64_t, size_t>* visited_map, 46 base::hash_map<int64_t, size_t>* visited_map,
47 ScopedVector<RawVarData>* data) { 47 std::vector<scoped_ptr<RawVarData>>* data) {
48 if (VarTracker::IsVarTypeRefcounted(var.type)) { 48 if (VarTracker::IsVarTypeRefcounted(var.type)) {
49 base::hash_map<int64_t, size_t>::iterator it = visited_map->find( 49 base::hash_map<int64_t, size_t>::iterator it = visited_map->find(
50 var.value.as_id); 50 var.value.as_id);
51 if (it != visited_map->end()) { 51 if (it != visited_map->end()) {
52 return it->second; 52 return it->second;
53 } else { 53 } else {
54 data->push_back(RawVarData::Create(var.type)); 54 data->push_back(make_scoped_ptr(RawVarData::Create(var.type)));
55 (*visited_map)[var.value.as_id] = data->size() - 1; 55 (*visited_map)[var.value.as_id] = data->size() - 1;
56 } 56 }
57 } else { 57 } else {
58 data->push_back(RawVarData::Create(var.type)); 58 data->push_back(make_scoped_ptr(RawVarData::Create(var.type)));
59 } 59 }
60 return data->size() - 1; 60 return data->size() - 1;
61 } 61 }
62 62
63 bool CanHaveChildren(PP_Var var) { 63 bool CanHaveChildren(PP_Var var) {
64 return var.type == PP_VARTYPE_ARRAY || var.type == PP_VARTYPE_DICTIONARY; 64 return var.type == PP_VARTYPE_ARRAY || var.type == PP_VARTYPE_DICTIONARY;
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
(...skipping 20 matching lines...) Expand all
89 // Map of |var.value.as_id| to a RawVarData index in RawVarDataGraph. 89 // Map of |var.value.as_id| to a RawVarData index in RawVarDataGraph.
90 base::hash_map<int64_t, size_t> visited_map; 90 base::hash_map<int64_t, size_t> visited_map;
91 base::hash_set<int64_t> parent_ids; 91 base::hash_set<int64_t> parent_ids;
92 92
93 std::stack<StackEntry> stack; 93 std::stack<StackEntry> stack;
94 stack.push(StackEntry(var, GetOrCreateRawVarData(var, &visited_map, 94 stack.push(StackEntry(var, GetOrCreateRawVarData(var, &visited_map,
95 &graph->data_))); 95 &graph->data_)));
96 96
97 while (!stack.empty()) { 97 while (!stack.empty()) {
98 PP_Var current_var = stack.top().var; 98 PP_Var current_var = stack.top().var;
99 RawVarData* current_var_data = graph->data_[stack.top().data_index]; 99 RawVarData* current_var_data = graph->data_[stack.top().data_index].get();
100 100
101 if (current_var_data->initialized()) { 101 if (current_var_data->initialized()) {
102 stack.pop(); 102 stack.pop();
103 if (CanHaveChildren(current_var)) 103 if (CanHaveChildren(current_var))
104 parent_ids.erase(current_var.value.as_id); 104 parent_ids.erase(current_var.value.as_id);
105 continue; 105 continue;
106 } 106 }
107 107
108 if (CanHaveChildren(current_var)) 108 if (CanHaveChildren(current_var))
109 parent_ids.insert(current_var.value.as_id); 109 parent_ids.insert(current_var.value.as_id);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 base::PickleIterator* iter) { 188 base::PickleIterator* iter) {
189 scoped_ptr<RawVarDataGraph> result(new RawVarDataGraph); 189 scoped_ptr<RawVarDataGraph> result(new RawVarDataGraph);
190 uint32_t size = 0; 190 uint32_t size = 0;
191 if (!iter->ReadUInt32(&size)) 191 if (!iter->ReadUInt32(&size))
192 return scoped_ptr<RawVarDataGraph>(); 192 return scoped_ptr<RawVarDataGraph>();
193 for (uint32_t i = 0; i < size; ++i) { 193 for (uint32_t i = 0; i < size; ++i) {
194 int32_t type; 194 int32_t type;
195 if (!iter->ReadInt(&type)) 195 if (!iter->ReadInt(&type))
196 return scoped_ptr<RawVarDataGraph>(); 196 return scoped_ptr<RawVarDataGraph>();
197 PP_VarType var_type = static_cast<PP_VarType>(type); 197 PP_VarType var_type = static_cast<PP_VarType>(type);
198 result->data_.push_back(RawVarData::Create(var_type)); 198 result->data_.push_back(make_scoped_ptr(RawVarData::Create(var_type)));
199 if (!result->data_.back()->Read(var_type, m, iter)) 199 if (!result->data_.back()->Read(var_type, m, iter))
200 return scoped_ptr<RawVarDataGraph>(); 200 return scoped_ptr<RawVarDataGraph>();
201 } 201 }
202 return result; 202 return result;
203 } 203 }
204 204
205 std::vector<SerializedHandle*> RawVarDataGraph::GetHandles() { 205 std::vector<SerializedHandle*> RawVarDataGraph::GetHandles() {
206 std::vector<SerializedHandle*> result; 206 std::vector<SerializedHandle*> result;
207 for (size_t i = 0; i < data_.size(); ++i) { 207 for (size_t i = 0; i < data_.size(); ++i) {
208 SerializedHandle* handle = data_[i]->GetHandle(); 208 SerializedHandle* handle = data_[i]->GetHandle();
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 if (!IPC::ReadParam(m, iter, creation_message_.get())) 741 if (!IPC::ReadParam(m, iter, creation_message_.get()))
742 return false; 742 return false;
743 } else { 743 } else {
744 creation_message_.reset(); 744 creation_message_.reset();
745 } 745 }
746 return true; 746 return true;
747 } 747 }
748 748
749 } // namespace proxy 749 } // namespace proxy
750 } // namespace ppapi 750 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/raw_var_data.h ('k') | ppapi/shared_impl/resource_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698