OLD | NEW |
---|---|
1 // Copyright (c) 2012 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 "chrome/browser/extensions/extension_toolbar_model.h" | 5 #include "chrome/browser/extensions/extension_toolbar_model.h" |
6 | 6 |
7 #include "chrome/browser/extensions/extension_browser_event_router.h" | 7 #include "chrome/browser/extensions/extension_browser_event_router.h" |
8 #include "chrome/browser/extensions/extension_prefs.h" | 8 #include "chrome/browser/extensions/extension_prefs.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
11 #include "chrome/browser/extensions/extension_tab_util.h" | 11 #include "chrome/browser/extensions/extension_tab_util.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "chrome/common/extensions/extension_switch_utils.h" | |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 | 24 |
24 using extensions::Extension; | 25 using extensions::Extension; |
25 using extensions::ExtensionList; | 26 using extensions::ExtensionList; |
26 | 27 |
27 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) | 28 ExtensionToolbarModel::ExtensionToolbarModel(ExtensionService* service) |
28 : service_(service), | 29 : service_(service), |
(...skipping 25 matching lines...) Expand all Loading... | |
54 observers_.RemoveObserver(observer); | 55 observers_.RemoveObserver(observer); |
55 } | 56 } |
56 | 57 |
57 void ExtensionToolbarModel::MoveBrowserAction(const Extension* extension, | 58 void ExtensionToolbarModel::MoveBrowserAction(const Extension* extension, |
58 int index) { | 59 int index) { |
59 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 60 ExtensionList::iterator pos = std::find(begin(), end(), extension); |
60 if (pos == end()) { | 61 if (pos == end()) { |
61 NOTREACHED(); | 62 NOTREACHED(); |
62 return; | 63 return; |
63 } | 64 } |
64 toolitems_.erase(pos); | 65 toolbar_items_.erase(pos); |
65 | 66 |
66 int i = 0; | 67 int i = 0; |
67 bool inserted = false; | 68 bool inserted = false; |
68 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++i) { | 69 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter, ++i) { |
69 if (i == index) { | 70 if (i == index) { |
70 toolitems_.insert(iter, make_scoped_refptr(extension)); | 71 toolbar_items_.insert(iter, make_scoped_refptr(extension)); |
71 inserted = true; | 72 inserted = true; |
72 break; | 73 break; |
73 } | 74 } |
74 } | 75 } |
75 | 76 |
76 if (!inserted) { | 77 if (!inserted) { |
77 DCHECK_EQ(index, static_cast<int>(toolitems_.size())); | 78 DCHECK_EQ(index, static_cast<int>(toolbar_items_.size())); |
78 index = toolitems_.size(); | 79 index = toolbar_items_.size(); |
79 | 80 |
80 toolitems_.push_back(make_scoped_refptr(extension)); | 81 toolbar_items_.push_back(make_scoped_refptr(extension)); |
81 } | 82 } |
82 | 83 |
83 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); | 84 FOR_EACH_OBSERVER(Observer, observers_, BrowserActionMoved(extension, index)); |
84 | 85 |
85 UpdatePrefs(); | 86 UpdatePrefs(); |
86 } | 87 } |
87 | 88 |
88 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( | 89 ExtensionToolbarModel::Action ExtensionToolbarModel::ExecuteBrowserAction( |
89 const Extension* extension, | 90 const Extension* extension, |
90 Browser* browser, | 91 Browser* browser, |
(...skipping 29 matching lines...) Expand all Loading... | |
120 void ExtensionToolbarModel::SetVisibleIconCount(int count) { | 121 void ExtensionToolbarModel::SetVisibleIconCount(int count) { |
121 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; | 122 visible_icon_count_ = count == static_cast<int>(size()) ? -1 : count; |
122 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); | 123 prefs_->SetInteger(prefs::kExtensionToolbarSize, visible_icon_count_); |
123 } | 124 } |
124 | 125 |
125 void ExtensionToolbarModel::Observe( | 126 void ExtensionToolbarModel::Observe( |
126 int type, | 127 int type, |
127 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
128 const content::NotificationDetails& details) { | 129 const content::NotificationDetails& details) { |
129 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { | 130 if (type == chrome::NOTIFICATION_EXTENSIONS_READY) { |
130 InitializeExtensionList(); | 131 InitializeExtensionLists(); |
131 return; | 132 return; |
132 } | 133 } |
133 | 134 |
134 if (!service_->is_ready()) | 135 if (!service_->is_ready()) |
135 return; | 136 return; |
136 | 137 |
137 const Extension* extension = NULL; | 138 const Extension* extension = NULL; |
138 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 139 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
139 extension = content::Details<extensions::UnloadedExtensionInfo>( | 140 extension = content::Details<extensions::UnloadedExtensionInfo>( |
140 details)->extension; | 141 details)->extension; |
141 } else { | 142 } else { |
142 extension = content::Details<const Extension>(details).ptr(); | 143 extension = content::Details<const Extension>(details).ptr(); |
143 } | 144 } |
144 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { | 145 if (type == chrome::NOTIFICATION_EXTENSION_LOADED) { |
145 // We don't want to add the same extension twice. It may have already been | 146 // We don't want to add the same extension twice. It may have already been |
146 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user | 147 // added by EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED below, if the user |
147 // hides the browser action and then disables and enables the extension. | 148 // hides the browser action and then disables and enables the extension. |
148 for (size_t i = 0; i < toolitems_.size(); i++) { | 149 for (size_t i = 0; i < toolbar_items_.size(); i++) { |
149 if (toolitems_[i].get() == extension) | 150 if (toolbar_items_[i].get() == extension) |
150 return; // Already exists. | 151 return; // Already exists. |
151 } | 152 } |
152 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 153 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
153 AddExtension(extension); | 154 AddExtension(extension); |
154 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 155 } else if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { |
155 RemoveExtension(extension); | 156 RemoveExtension(extension); |
156 } else if ( | 157 } else if ( |
157 type == | 158 type == |
158 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { | 159 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED) { |
159 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 160 if (service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
160 AddExtension(extension); | 161 AddExtension(extension); |
161 else | 162 else |
162 RemoveExtension(extension); | 163 RemoveExtension(extension); |
163 } else { | 164 } else { |
164 NOTREACHED() << "Received unexpected notification"; | 165 NOTREACHED() << "Received unexpected notification"; |
165 } | 166 } |
166 } | 167 } |
167 | 168 |
168 void ExtensionToolbarModel::AddExtension(const Extension* extension) { | 169 void ExtensionToolbarModel::AddExtension(const Extension* extension) { |
169 // We only care about extensions with browser actions. | 170 // We only care about extensions with browser actions. |
170 if (!extension->browser_action()) | 171 if (!extension->browser_action()) |
171 return; | 172 return; |
172 | 173 |
173 if (extension->id() == last_extension_removed_ && | 174 if (extension->id() == last_extension_removed_ && |
174 last_extension_removed_index_ < toolitems_.size()) { | 175 last_extension_removed_index_ < toolbar_items_.size()) { |
175 toolitems_.insert(begin() + last_extension_removed_index_, | 176 toolbar_items_.insert(begin() + last_extension_removed_index_, |
176 make_scoped_refptr(extension)); | 177 make_scoped_refptr(extension)); |
177 FOR_EACH_OBSERVER(Observer, observers_, | 178 FOR_EACH_OBSERVER(Observer, observers_, |
178 BrowserActionAdded(extension, last_extension_removed_index_)); | 179 BrowserActionAdded(extension, last_extension_removed_index_)); |
179 } else { | 180 } else { |
180 toolitems_.push_back(make_scoped_refptr(extension)); | 181 toolbar_items_.push_back(make_scoped_refptr(extension)); |
181 FOR_EACH_OBSERVER(Observer, observers_, | 182 FOR_EACH_OBSERVER(Observer, observers_, |
182 BrowserActionAdded(extension, toolitems_.size() - 1)); | 183 BrowserActionAdded(extension, toolbar_items_.size() - 1)); |
183 } | 184 } |
184 | 185 |
185 last_extension_removed_ = ""; | 186 last_extension_removed_ = ""; |
186 last_extension_removed_index_ = -1; | 187 last_extension_removed_index_ = -1; |
187 | 188 |
188 UpdatePrefs(); | 189 UpdatePrefs(); |
189 } | 190 } |
190 | 191 |
191 void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { | 192 void ExtensionToolbarModel::RemoveExtension(const Extension* extension) { |
192 ExtensionList::iterator pos = std::find(begin(), end(), extension); | 193 ExtensionList::iterator pos = std::find(begin(), end(), extension); |
193 if (pos == end()) { | 194 if (pos == end()) { |
194 return; | 195 return; |
195 } | 196 } |
196 | 197 |
197 last_extension_removed_ = extension->id(); | 198 last_extension_removed_ = extension->id(); |
198 last_extension_removed_index_ = pos - begin(); | 199 last_extension_removed_index_ = pos - begin(); |
199 | 200 |
200 toolitems_.erase(pos); | 201 toolbar_items_.erase(pos); |
201 FOR_EACH_OBSERVER(Observer, observers_, | 202 FOR_EACH_OBSERVER(Observer, observers_, |
202 BrowserActionRemoved(extension)); | 203 BrowserActionRemoved(extension)); |
203 | 204 |
204 UpdatePrefs(); | 205 UpdatePrefs(); |
205 } | 206 } |
206 | 207 |
207 // Combine the currently enabled extensions that have browser actions (which | 208 // Combine the currently enabled extensions that have browser actions (which |
208 // we get from the ExtensionService) with the ordering we get from the | 209 // we get from the ExtensionService) with the ordering we get from the |
209 // pref service. For robustness we use a somewhat inefficient process: | 210 // pref service. For robustness we use a somewhat inefficient process: |
210 // 1. Create a vector of extensions sorted by their pref values. This vector may | 211 // 1. Create a vector of extensions sorted by their pref values. This vector may |
211 // have holes. | 212 // have holes. |
212 // 2. Create a vector of extensions that did not have a pref value. | 213 // 2. Create a vector of extensions that did not have a pref value. |
213 // 3. Remove holes from the sorted vector and append the unsorted vector. | 214 // 3. Remove holes from the sorted vector and append the unsorted vector. |
214 void ExtensionToolbarModel::InitializeExtensionList() { | 215 void ExtensionToolbarModel::InitializeExtensionLists() { |
215 DCHECK(service_->is_ready()); | 216 DCHECK(service_->is_ready()); |
216 | 217 |
217 std::vector<std::string> pref_order = service_->extension_prefs()-> | 218 if (extensions::switch_utils::IsActionBoxEnabled()) |
218 GetToolbarOrder(); | 219 PopulateForActionBoxMode(); |
220 else | |
221 PopulateForNonActionBoxMode(); | |
222 | |
223 UpdatePrefs(); | |
224 | |
225 extensions_initialized_ = true; | |
226 FOR_EACH_OBSERVER(Observer, observers_, ModelLoaded()); | |
227 } | |
228 | |
229 void ExtensionToolbarModel::PopulateForActionBoxMode() { | |
Peter Kasting
2012/07/21 01:55:13
This function never calls GetBrowserActionVisibili
yefimt
2012/07/23 23:47:52
No, Aaron advised that just using toolbar and acti
| |
230 const VectorOfStrings toolbar_order = | |
231 service_->extension_prefs()->GetToolbarOrder(); | |
232 VectorOfStrings action_box_order = | |
233 service_->extension_prefs()->GetActionBoxOrder(); | |
234 | |
235 // Create the lists. | |
Peter Kasting
2012/07/21 01:55:13
Nit: This comment is misleading, because we don't
yefimt
2012/07/23 23:47:52
Comment - done.
I dont think GetActionBoxOrder() s
| |
236 for (ExtensionSet::const_iterator iter = service_->extensions()->begin(); | |
237 iter != service_->extensions()->end(); ++iter) { | |
238 const Extension* extension = *iter; | |
239 if (!extension->browser_action()) | |
240 continue; | |
241 | |
242 VectorOfStrings::const_iterator toolbar_pos = | |
243 std::find(toolbar_order.begin(), toolbar_order.end(), extension->id()); | |
244 VectorOfStrings::const_iterator action_box_pos = | |
245 std::find(action_box_order.begin(), action_box_order.end(), | |
246 extension->id()); | |
Peter Kasting
2012/07/21 01:55:13
Nit: Indent even with first arg in line just above
yefimt
2012/07/23 23:47:52
Done.
| |
247 if ((toolbar_pos == toolbar_order.end()) && | |
248 (action_box_pos == action_box_order.end())) | |
249 action_box_order.push_back(extension->id()); | |
250 } | |
251 | |
252 FillExtensionList(action_box_order, &action_box_menu_items_); | |
253 FillExtensionList(toolbar_order, &toolbar_items_); | |
254 | |
255 // Inform observers. | |
256 for (size_t i = 0; i < toolbar_items_.size(); i++) { | |
Peter Kasting
2012/07/21 01:55:13
This loop seems wrong for a couple of reasons.
(1
yefimt
2012/07/23 23:47:52
Yes an extension guarantied to be in the one list
| |
257 FOR_EACH_OBSERVER(Observer, observers_, | |
258 BrowserActionAdded(action_box_menu_items_[i], i)); | |
Peter Kasting
2012/07/21 01:55:13
Maybe not in scope for this change, but it seems l
yefimt
2012/07/23 23:47:52
I see your point. I'll keep it in mind when get to
| |
259 FOR_EACH_OBSERVER(Observer, observers_, | |
260 BrowserActionAdded(toolbar_items_[i], i)); | |
261 } | |
262 } | |
263 | |
264 void ExtensionToolbarModel::PopulateForNonActionBoxMode() { | |
265 const VectorOfStrings pref_order = | |
266 service_->extension_prefs()->GetToolbarOrder(); | |
219 // Items that have a pref for their position. | 267 // Items that have a pref for their position. |
220 ExtensionList sorted; | 268 ExtensionList sorted; |
221 sorted.resize(pref_order.size(), NULL); | 269 sorted.resize(pref_order.size(), NULL); |
222 // The items that don't have a pref for their position. | 270 // The items that don't have a pref for their position. |
223 ExtensionList unsorted; | 271 ExtensionList unsorted; |
224 | 272 |
225 // Create the lists. | 273 // Create the lists. |
226 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); | 274 for (ExtensionSet::const_iterator it = service_->extensions()->begin(); |
227 it != service_->extensions()->end(); ++it) { | 275 it != service_->extensions()->end(); ++it) { |
228 const Extension* extension = *it; | 276 const Extension* extension = *it; |
229 if (!extension->browser_action()) | 277 if (!extension->browser_action()) |
Peter Kasting
2012/07/21 01:55:13
Nit: Can combine with the next condition by adding
yefimt
2012/07/23 23:47:52
I thought it is more readable this way and second
| |
230 continue; | 278 continue; |
231 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) | 279 if (!service_->extension_prefs()->GetBrowserActionVisibility(extension)) |
232 continue; | 280 continue; |
233 | 281 |
234 std::vector<std::string>::iterator pos = | 282 AddToProperList(extension, pref_order, &sorted, &unsorted); |
235 std::find(pref_order.begin(), pref_order.end(), extension->id()); | |
236 if (pos != pref_order.end()) { | |
237 int index = std::distance(pref_order.begin(), pos); | |
238 sorted[index] = extension; | |
239 } else { | |
240 unsorted.push_back(make_scoped_refptr(extension)); | |
241 } | |
242 } | 283 } |
243 | 284 |
244 // Merge the lists. | 285 MergeLists(sorted, unsorted, &toolbar_items_); |
Peter Kasting
2012/07/21 01:55:13
Nit: This function is only called once, and is sho
yefimt
2012/07/23 23:47:52
Done.
yefimt
2012/07/23 23:47:52
Done.
| |
245 toolitems_.reserve(sorted.size() + unsorted.size()); | 286 |
246 for (ExtensionList::iterator iter = sorted.begin(); | 287 // Inform observers. |
288 for (size_t i = 0; i < toolbar_items_.size(); i++) { | |
289 FOR_EACH_OBSERVER(Observer, observers_, | |
290 BrowserActionAdded(toolbar_items_[i], i)); | |
291 } | |
292 } | |
293 | |
294 void ExtensionToolbarModel::AddToProperList(const Extension* extension, | |
295 const VectorOfStrings& order, | |
296 ExtensionList* sorted, | |
297 ExtensionList* unsorted) { | |
Peter Kasting
2012/07/21 01:55:13
Nit: I suggest:
DCHECK_EQ(order.size(), sorted-
yefimt
2012/07/23 23:47:52
Done.
| |
298 VectorOfStrings::const_iterator pos = | |
299 std::find(order.begin(), order.end(), extension->id()); | |
300 if (pos != order.end()) { | |
Peter Kasting
2012/07/21 01:55:13
Nit: No {} needed
yefimt
2012/07/23 23:47:52
Done.
| |
301 (*sorted)[pos - order.begin()] = extension; | |
302 } else { | |
303 unsorted->push_back(make_scoped_refptr(extension)); | |
304 } | |
305 } | |
306 | |
307 void ExtensionToolbarModel::MergeLists(const ExtensionList& sorted, | |
308 const ExtensionList& unsorted, | |
309 ExtensionList* result_list) { | |
310 result_list->reserve(sorted.size() + unsorted.size()); | |
311 for (ExtensionList::const_iterator iter = sorted.begin(); | |
247 iter != sorted.end(); ++iter) { | 312 iter != sorted.end(); ++iter) { |
248 if (*iter != NULL) | 313 if (*iter != NULL) |
Peter Kasting
2012/07/21 01:55:13
Is this check actually necessary? It seems like i
yefimt
2012/07/23 23:47:52
I think you are right, I cannot see how it could b
Aaron Boodman
2012/07/23 23:57:51
This can happen due to sync. The order is synced a
yefimt
2012/07/24 00:14:49
OK, restored original code
Peter Kasting
2012/07/24 04:27:29
Thanks, that's good to know! Yefim, can you make
| |
249 toolitems_.push_back(*iter); | 314 result_list->push_back(*iter); |
Peter Kasting
2012/07/21 01:55:13
This seems to assume |result_list| was empty on en
yefimt
2012/07/23 23:47:52
Done.
| |
250 } | 315 } |
251 toolitems_.insert(toolitems_.end(), unsorted.begin(), unsorted.end()); | 316 result_list->insert(result_list->end(), unsorted.begin(), unsorted.end()); |
317 } | |
252 | 318 |
253 // Inform observers. | 319 void ExtensionToolbarModel::FillExtensionList(const VectorOfStrings& order, |
254 for (size_t i = 0; i < toolitems_.size(); i++) { | 320 ExtensionList* result_list) { |
255 FOR_EACH_OBSERVER(Observer, observers_, | 321 result_list->clear(); |
256 BrowserActionAdded(toolitems_[i], i)); | 322 result_list->reserve(order.size()); |
323 for (size_t i = 0; i < order.size(); ++i) { | |
324 const extensions::Extension* extension = | |
325 service_->GetExtensionById(order[i], false); | |
326 if (!extension) | |
Peter Kasting
2012/07/21 01:55:13
Can this happen? This seems like another case tha
yefimt
2012/07/23 23:47:52
I think it could happen. Extensions order coming f
| |
327 return; | |
328 result_list->push_back(extension); | |
257 } | 329 } |
258 | |
259 UpdatePrefs(); | |
260 | |
261 extensions_initialized_ = true; | |
262 FOR_EACH_OBSERVER(Observer, observers_, ModelLoaded()); | |
263 } | 330 } |
264 | 331 |
265 void ExtensionToolbarModel::UpdatePrefs() { | 332 void ExtensionToolbarModel::UpdatePrefs() { |
266 if (!service_->extension_prefs()) | 333 if (!service_->extension_prefs()) |
267 return; | 334 return; |
268 | 335 |
269 std::vector<std::string> ids; | 336 VectorOfStrings toolbar_ids; |
270 ids.reserve(toolitems_.size()); | 337 toolbar_ids.reserve(toolbar_items_.size()); |
271 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter) | 338 for (ExtensionList::iterator iter = begin(); iter != end(); ++iter) |
Peter Kasting
2012/07/21 01:55:13
Nit: I think this can be a const_iterator (and bel
yefimt
2012/07/23 23:47:52
Done.
| |
272 ids.push_back((*iter)->id()); | 339 toolbar_ids.push_back((*iter)->id()); |
273 service_->extension_prefs()->SetToolbarOrder(ids); | 340 service_->extension_prefs()->SetToolbarOrder(toolbar_ids); |
274 } | |
275 | 341 |
276 const Extension* ExtensionToolbarModel::GetExtensionByIndex(int index) const { | 342 VectorOfStrings action_box_ids; |
277 return toolitems_[index]; | 343 action_box_ids.reserve(action_box_menu_items_.size()); |
344 for (size_t i = 0; i < action_box_menu_items_.size(); ++i) | |
Peter Kasting
2012/07/21 01:55:13
Nit: Is there a reason you use an iterator above a
yefimt
2012/07/23 23:47:52
Done.
| |
345 action_box_ids.push_back(action_box_menu_items_[i]->id()); | |
346 service_->extension_prefs()->SetActionBoxOrder(action_box_ids); | |
278 } | 347 } |
279 | 348 |
280 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { | 349 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { |
281 int original_index = 0, i = 0; | 350 int original_index = 0, i = 0; |
282 for (ExtensionList::iterator iter = begin(); iter != end(); | 351 for (ExtensionList::iterator iter = begin(); iter != end(); |
283 ++iter, ++original_index) { | 352 ++iter, ++original_index) { |
284 if (service_->IsIncognitoEnabled((*iter)->id())) { | 353 if (service_->IsIncognitoEnabled((*iter)->id())) { |
285 if (incognito_index == i) | 354 if (incognito_index == i) |
286 break; | 355 break; |
287 ++i; | 356 ++i; |
288 } | 357 } |
289 } | 358 } |
290 return original_index; | 359 return original_index; |
291 } | 360 } |
292 | 361 |
293 int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { | 362 int ExtensionToolbarModel::OriginalIndexToIncognito(int original_index) { |
294 int incognito_index = 0, i = 0; | 363 int incognito_index = 0, i = 0; |
295 for (ExtensionList::iterator iter = begin(); iter != end(); | 364 for (ExtensionList::iterator iter = begin(); iter != end(); |
296 ++iter, ++i) { | 365 ++iter, ++i) { |
297 if (original_index == i) | 366 if (original_index == i) |
298 break; | 367 break; |
299 if (service_->IsIncognitoEnabled((*iter)->id())) | 368 if (service_->IsIncognitoEnabled((*iter)->id())) |
300 ++incognito_index; | 369 ++incognito_index; |
301 } | 370 } |
302 return incognito_index; | 371 return incognito_index; |
303 } | 372 } |
OLD | NEW |