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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/metrics/histogram_base.h" | 10 #include "base/metrics/histogram_base.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 for (ExtensionList::const_iterator iter_ext = toolbar_items_.begin(); | 249 for (ExtensionList::const_iterator iter_ext = toolbar_items_.begin(); |
250 iter_ext < toolbar_items_.end(); ++iter_ext) { | 250 iter_ext < toolbar_items_.end(); ++iter_ext) { |
251 if ((*iter_ext)->id().compare(*iter_id) == 0) { | 251 if ((*iter_ext)->id().compare(*iter_id) == 0) { |
252 // This extension is visible, update the index value. | 252 // This extension is visible, update the index value. |
253 ++new_index; | 253 ++new_index; |
254 break; | 254 break; |
255 } | 255 } |
256 } | 256 } |
257 } | 257 } |
258 | 258 |
259 return -1; | 259 return toolbar_items_.size(); // Is this correct? Or maybe |new_index|? |
Peter Kasting
2014/07/03 01:18:50
This line needs review.
Finnur
2014/07/03 12:17:54
It is definitely wrong to return |new_index| becau
Peter Kasting
2014/07/07 19:15:29
Done.
| |
260 } | 260 } |
261 | 261 |
262 void ExtensionToolbarModel::AddExtension(const Extension* extension) { | 262 void ExtensionToolbarModel::AddExtension(const Extension* extension) { |
263 // We only care about extensions with browser actions. | 263 // We only care about extensions with browser actions. |
264 if (!ExtensionActionManager::Get(profile_)->GetBrowserAction(*extension)) | 264 if (!ExtensionActionManager::Get(profile_)->GetBrowserAction(*extension)) |
265 return; | 265 return; |
266 | 266 |
267 size_t new_index = -1; | 267 size_t new_index = toolbar_items_.size(); |
268 | 268 |
269 // See if we have a last known good position for this extension. | 269 // See if we have a last known good position for this extension. |
270 ExtensionIdList::iterator last_pos = std::find(last_known_positions_.begin(), | 270 ExtensionIdList::iterator last_pos = std::find(last_known_positions_.begin(), |
271 last_known_positions_.end(), | 271 last_known_positions_.end(), |
272 extension->id()); | 272 extension->id()); |
273 if (last_pos != last_known_positions_.end()) { | 273 if (last_pos != last_known_positions_.end()) { |
274 new_index = FindNewPositionFromLastKnownGood(extension); | 274 new_index = FindNewPositionFromLastKnownGood(extension); |
275 if (new_index != toolbar_items_.size()) { | 275 if (new_index != toolbar_items_.size()) { |
276 toolbar_items_.insert(toolbar_items_.begin() + new_index, | 276 toolbar_items_.insert(toolbar_items_.begin() + new_index, |
277 make_scoped_refptr(extension)); | 277 make_scoped_refptr(extension)); |
278 } else { | 278 } else { |
279 toolbar_items_.push_back(make_scoped_refptr(extension)); | 279 toolbar_items_.push_back(make_scoped_refptr(extension)); |
280 } | 280 } |
281 } else { | 281 } else { |
282 // This is a never before seen extension, that was added to the end. Make | 282 // This is a never before seen extension, that was added to the end. Make |
283 // sure to reflect that. | 283 // sure to reflect that. (|new_index| was set above.) |
284 toolbar_items_.push_back(make_scoped_refptr(extension)); | 284 toolbar_items_.push_back(make_scoped_refptr(extension)); |
285 last_known_positions_.push_back(extension->id()); | 285 last_known_positions_.push_back(extension->id()); |
286 new_index = toolbar_items_.size() - 1; | |
Finnur
2014/07/03 12:17:54
This removal is not correct, I believe. |new_index
Peter Kasting
2014/07/07 19:15:29
I think you're misreading the code.
Note that in
Finnur
2014/07/08 10:48:24
Sure. But I must still be misreading the CL becaus
Peter Kasting
2014/07/08 19:21:25
Now I'm the one confused. I'm not changing the pu
Finnur
2014/07/08 23:31:20
My apologies. I was trying to get a review in (to
| |
287 UpdatePrefs(); | 286 UpdatePrefs(); |
288 } | 287 } |
289 | 288 |
290 // If we're currently highlighting, then even though we add a browser action | 289 // If we're currently highlighting, then even though we add a browser action |
291 // to the full list (|toolbar_items_|, there won't be another *visible* | 290 // to the full list (|toolbar_items_|, there won't be another *visible* |
292 // browser action, which was what the observers care about. | 291 // browser action, which was what the observers care about. |
293 if (!is_highlighting_) { | 292 if (!is_highlighting_) { |
294 FOR_EACH_OBSERVER(Observer, observers_, | 293 FOR_EACH_OBSERVER(Observer, observers_, |
295 BrowserActionAdded(extension, new_index)); | 294 BrowserActionAdded(extension, new_index)); |
296 } | 295 } |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 is_highlighting_ = false; | 581 is_highlighting_ = false; |
583 if (old_visible_icon_count_ != visible_icon_count_) { | 582 if (old_visible_icon_count_ != visible_icon_count_) { |
584 SetVisibleIconCount(old_visible_icon_count_); | 583 SetVisibleIconCount(old_visible_icon_count_); |
585 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); | 584 FOR_EACH_OBSERVER(Observer, observers_, VisibleCountChanged()); |
586 } | 585 } |
587 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); | 586 FOR_EACH_OBSERVER(Observer, observers_, HighlightModeChanged(false)); |
588 } | 587 } |
589 } | 588 } |
590 | 589 |
591 } // namespace extensions | 590 } // namespace extensions |
OLD | NEW |