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

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

Issue 9447084: Refactor Pickle Read methods to use higher performance PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile (racing with incoming CLs) Created 8 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/proxy/serialized_flash_menu.h ('k') | ppapi/proxy/serialized_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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/serialized_flash_menu.h" 5 #include "ppapi/proxy/serialized_flash_menu.h"
6 6
7 #include "ipc/ipc_message.h" 7 #include "ipc/ipc_message.h"
8 #include "ppapi/c/private/ppb_flash_menu.h" 8 #include "ppapi/c/private/ppb_flash_menu.h"
9 #include "ppapi/proxy/ppapi_param_traits.h" 9 #include "ppapi/proxy/ppapi_param_traits.h"
10 10
11 namespace ppapi { 11 namespace ppapi {
12 namespace proxy { 12 namespace proxy {
13 13
14 namespace { 14 namespace {
15 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are 15 // Maximum depth of submenus allowed (e.g., 1 indicates that submenus are
16 // allowed, but not sub-submenus). 16 // allowed, but not sub-submenus).
17 const int kMaxMenuDepth = 2; 17 const int kMaxMenuDepth = 2;
18 18
19 bool CheckMenu(int depth, const PP_Flash_Menu* menu); 19 bool CheckMenu(int depth, const PP_Flash_Menu* menu);
20 void FreeMenu(const PP_Flash_Menu* menu); 20 void FreeMenu(const PP_Flash_Menu* menu);
21 void WriteMenu(IPC::Message* m, const PP_Flash_Menu* menu); 21 void WriteMenu(IPC::Message* m, const PP_Flash_Menu* menu);
22 PP_Flash_Menu* ReadMenu(int depth, const IPC::Message* m, void** iter); 22 PP_Flash_Menu* ReadMenu(int depth, const IPC::Message* m, PickleIterator* iter);
23 23
24 bool CheckMenuItem(int depth, const PP_Flash_MenuItem* item) { 24 bool CheckMenuItem(int depth, const PP_Flash_MenuItem* item) {
25 if (item->type == PP_FLASH_MENUITEM_TYPE_SUBMENU) 25 if (item->type == PP_FLASH_MENUITEM_TYPE_SUBMENU)
26 return CheckMenu(depth, item->submenu); 26 return CheckMenu(depth, item->submenu);
27 return true; 27 return true;
28 } 28 }
29 29
30 bool CheckMenu(int depth, const PP_Flash_Menu* menu) { 30 bool CheckMenu(int depth, const PP_Flash_Menu* menu) {
31 if (depth > kMaxMenuDepth || !menu) 31 if (depth > kMaxMenuDepth || !menu)
32 return false; 32 return false;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (menu->items) { 70 if (menu->items) {
71 for (uint32_t i = 0; i < menu->count; ++i) 71 for (uint32_t i = 0; i < menu->count; ++i)
72 FreeMenuItem(menu->items + i); 72 FreeMenuItem(menu->items + i);
73 delete [] menu->items; 73 delete [] menu->items;
74 } 74 }
75 delete menu; 75 delete menu;
76 } 76 }
77 77
78 bool ReadMenuItem(int depth, 78 bool ReadMenuItem(int depth,
79 const IPC::Message* m, 79 const IPC::Message* m,
80 void** iter, 80 PickleIterator* iter,
81 PP_Flash_MenuItem* menu_item) { 81 PP_Flash_MenuItem* menu_item) {
82 uint32_t type; 82 uint32_t type;
83 if (!m->ReadUInt32(iter, &type)) 83 if (!m->ReadUInt32(iter, &type))
84 return false; 84 return false;
85 if (type > PP_FLASH_MENUITEM_TYPE_SUBMENU) 85 if (type > PP_FLASH_MENUITEM_TYPE_SUBMENU)
86 return false; 86 return false;
87 menu_item->type = static_cast<PP_Flash_MenuItem_Type>(type); 87 menu_item->type = static_cast<PP_Flash_MenuItem_Type>(type);
88 std::string name; 88 std::string name;
89 if (!m->ReadString(iter, &name)) 89 if (!m->ReadString(iter, &name))
90 return false; 90 return false;
91 menu_item->name = new char[name.size() + 1]; 91 menu_item->name = new char[name.size() + 1];
92 std::copy(name.begin(), name.end(), menu_item->name); 92 std::copy(name.begin(), name.end(), menu_item->name);
93 menu_item->name[name.size()] = 0; 93 menu_item->name[name.size()] = 0;
94 if (!m->ReadInt(iter, &menu_item->id)) 94 if (!m->ReadInt(iter, &menu_item->id))
95 return false; 95 return false;
96 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->enabled)) 96 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->enabled))
97 return false; 97 return false;
98 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->checked)) 98 if (!IPC::ParamTraits<PP_Bool>::Read(m, iter, &menu_item->checked))
99 return false; 99 return false;
100 if (type == PP_FLASH_MENUITEM_TYPE_SUBMENU) { 100 if (type == PP_FLASH_MENUITEM_TYPE_SUBMENU) {
101 menu_item->submenu = ReadMenu(depth, m, iter); 101 menu_item->submenu = ReadMenu(depth, m, iter);
102 if (!menu_item->submenu) 102 if (!menu_item->submenu)
103 return false; 103 return false;
104 } 104 }
105 return true; 105 return true;
106 } 106 }
107 107
108 PP_Flash_Menu* ReadMenu(int depth, const IPC::Message* m, void** iter) { 108 PP_Flash_Menu* ReadMenu(int depth,
109 const IPC::Message* m,
110 PickleIterator* iter) {
109 if (depth > kMaxMenuDepth) 111 if (depth > kMaxMenuDepth)
110 return NULL; 112 return NULL;
111 ++depth; 113 ++depth;
112 114
113 PP_Flash_Menu* menu = new PP_Flash_Menu; 115 PP_Flash_Menu* menu = new PP_Flash_Menu;
114 menu->items = NULL; 116 menu->items = NULL;
115 117
116 if (!m->ReadUInt32(iter, &menu->count)) { 118 if (!m->ReadUInt32(iter, &menu->count)) {
117 FreeMenu(menu); 119 FreeMenu(menu);
118 return NULL; 120 return NULL;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 pp_menu_ = menu; 153 pp_menu_ = menu;
152 own_menu_ = false; 154 own_menu_ = false;
153 return true; 155 return true;
154 } 156 }
155 157
156 158
157 void SerializedFlashMenu::WriteToMessage(IPC::Message* m) const { 159 void SerializedFlashMenu::WriteToMessage(IPC::Message* m) const {
158 WriteMenu(m, pp_menu_); 160 WriteMenu(m, pp_menu_);
159 } 161 }
160 162
161 bool SerializedFlashMenu::ReadFromMessage(const IPC::Message* m, void** iter) { 163 bool SerializedFlashMenu::ReadFromMessage(const IPC::Message* m,
164 PickleIterator* iter) {
162 DCHECK(!pp_menu_); 165 DCHECK(!pp_menu_);
163 pp_menu_ = ReadMenu(0, m, iter); 166 pp_menu_ = ReadMenu(0, m, iter);
164 if (!pp_menu_) 167 if (!pp_menu_)
165 return false; 168 return false;
166 169
167 own_menu_ = true; 170 own_menu_ = true;
168 return true; 171 return true;
169 } 172 }
170 173
171 } // namespace proxy 174 } // namespace proxy
172 } // namespace ppapi 175 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/serialized_flash_menu.h ('k') | ppapi/proxy/serialized_var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698