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

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.cc

Issue 508513002: Remove implicit conversions from scoped_refptr to T* in chrome/browser/extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Two more Created 6 years, 4 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
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ExtensionIdList::const_iterator pos = 436 ExtensionIdList::const_iterator pos =
437 std::find(positions.begin(), positions.end(), extension->id()); 437 std::find(positions.begin(), positions.end(), extension->id());
438 if (pos != positions.end()) 438 if (pos != positions.end())
439 sorted[pos - positions.begin()] = extension; 439 sorted[pos - positions.begin()] = extension;
440 else 440 else
441 unsorted.push_back(make_scoped_refptr(extension)); 441 unsorted.push_back(make_scoped_refptr(extension));
442 } 442 }
443 443
444 size_t items_count = toolbar_items_.size(); 444 size_t items_count = toolbar_items_.size();
445 for (size_t i = 0; i < items_count; i++) { 445 for (size_t i = 0; i < items_count; i++) {
446 const Extension* extension = toolbar_items_.back(); 446 const Extension* extension = toolbar_items_.back().get();
447 // By popping the extension here (before calling BrowserActionRemoved), 447 // By popping the extension here (before calling BrowserActionRemoved),
448 // we will not shrink visible count by one after BrowserActionRemoved 448 // we will not shrink visible count by one after BrowserActionRemoved
449 // calls SetVisibleCount. 449 // calls SetVisibleCount.
450 toolbar_items_.pop_back(); 450 toolbar_items_.pop_back();
451 FOR_EACH_OBSERVER( 451 FOR_EACH_OBSERVER(
452 Observer, observers_, ToolbarExtensionRemoved(extension)); 452 Observer, observers_, ToolbarExtensionRemoved(extension));
453 } 453 }
454 DCHECK(toolbar_items_.empty()); 454 DCHECK(toolbar_items_.empty());
455 455
456 // Merge the lists. 456 // Merge the lists.
457 toolbar_items_.reserve(sorted.size() + unsorted.size()); 457 toolbar_items_.reserve(sorted.size() + unsorted.size());
458 458
459 for (ExtensionList::const_iterator iter = sorted.begin(); 459 for (ExtensionList::const_iterator iter = sorted.begin();
460 iter != sorted.end(); ++iter) { 460 iter != sorted.end(); ++iter) {
461 // It's possible for the extension order to contain items that aren't 461 // It's possible for the extension order to contain items that aren't
462 // actually loaded on this machine. For example, when extension sync is on, 462 // actually loaded on this machine. For example, when extension sync is on,
463 // we sync the extension order as-is but double-check with the user before 463 // we sync the extension order as-is but double-check with the user before
464 // syncing NPAPI-containing extensions, so if one of those is not actually 464 // syncing NPAPI-containing extensions, so if one of those is not actually
465 // synced, we'll get a NULL in the list. This sort of case can also happen 465 // synced, we'll get a NULL in the list. This sort of case can also happen
466 // if some error prevents an extension from loading. 466 // if some error prevents an extension from loading.
467 if (iter->get() != NULL) { 467 if (iter->get() != NULL) {
468 toolbar_items_.push_back(*iter); 468 toolbar_items_.push_back(*iter);
469 FOR_EACH_OBSERVER( 469 FOR_EACH_OBSERVER(
470 Observer, observers_, ToolbarExtensionAdded( 470 Observer,
471 *iter, toolbar_items_.size() - 1)); 471 observers_,
472 ToolbarExtensionAdded(iter->get(), toolbar_items_.size() - 1));
472 } 473 }
473 } 474 }
474 for (ExtensionList::const_iterator iter = unsorted.begin(); 475 for (ExtensionList::const_iterator iter = unsorted.begin();
475 iter != unsorted.end(); ++iter) { 476 iter != unsorted.end(); ++iter) {
476 if (iter->get() != NULL) { 477 if (iter->get() != NULL) {
477 toolbar_items_.push_back(*iter); 478 toolbar_items_.push_back(*iter);
478 FOR_EACH_OBSERVER( 479 FOR_EACH_OBSERVER(
479 Observer, observers_, ToolbarExtensionAdded( 480 Observer,
480 *iter, toolbar_items_.size() - 1)); 481 observers_,
482 ToolbarExtensionAdded(iter->get(), toolbar_items_.size() - 1));
481 } 483 }
482 } 484 }
483 485
484 UMA_HISTOGRAM_COUNTS_100( 486 UMA_HISTOGRAM_COUNTS_100(
485 "ExtensionToolbarModel.BrowserActionsPermanentlyHidden", hidden); 487 "ExtensionToolbarModel.BrowserActionsPermanentlyHidden", hidden);
486 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsCount", 488 UMA_HISTOGRAM_COUNTS_100("ExtensionToolbarModel.BrowserActionsCount",
487 toolbar_items_.size()); 489 toolbar_items_.size());
488 490
489 if (!toolbar_items_.empty()) { 491 if (!toolbar_items_.empty()) {
490 // Visible count can be -1, meaning: 'show all'. Since UMA converts negative 492 // Visible count can be -1, meaning: 'show all'. Since UMA converts negative
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 registrar_.Add(this, 535 registrar_.Add(this,
534 NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED, 536 NOTIFICATION_EXTENSION_BROWSER_ACTION_VISIBILITY_CHANGED,
535 content::Source<ExtensionPrefs>(extension_prefs_)); 537 content::Source<ExtensionPrefs>(extension_prefs_));
536 } 538 }
537 } 539 }
538 } 540 }
539 } 541 }
540 542
541 void ExtensionToolbarModel::MaybeUpdateVisibilityPrefs() { 543 void ExtensionToolbarModel::MaybeUpdateVisibilityPrefs() {
542 for (size_t i = 0u; i < toolbar_items_.size(); ++i) 544 for (size_t i = 0u; i < toolbar_items_.size(); ++i)
543 MaybeUpdateVisibilityPref(toolbar_items_[i], i); 545 MaybeUpdateVisibilityPref(toolbar_items_[i].get(), i);
544 } 546 }
545 547
546 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) { 548 int ExtensionToolbarModel::IncognitoIndexToOriginal(int incognito_index) {
547 int original_index = 0, i = 0; 549 int original_index = 0, i = 0;
548 for (ExtensionList::iterator iter = toolbar_items_.begin(); 550 for (ExtensionList::iterator iter = toolbar_items_.begin();
549 iter != toolbar_items_.end(); 551 iter != toolbar_items_.end();
550 ++iter, ++original_index) { 552 ++iter, ++original_index) {
551 if (util::IsIncognitoEnabled((*iter)->id(), profile_)) { 553 if (util::IsIncognitoEnabled((*iter)->id(), profile_)) {
552 if (incognito_index == i) 554 if (incognito_index == i)
553 break; 555 break;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 if (visible_icon_count_ == -1) 631 if (visible_icon_count_ == -1)
630 return; // May have been set to max by SetVisibleIconCount. 632 return; // May have been set to max by SetVisibleIconCount.
631 633
632 // Guillotine's Delight: Move an orange noble to the front of the line. 634 // Guillotine's Delight: Move an orange noble to the front of the line.
633 for (ExtensionIdList::const_iterator it = extension_ids.begin(); 635 for (ExtensionIdList::const_iterator it = extension_ids.begin();
634 it != extension_ids.end(); ++it) { 636 it != extension_ids.end(); ++it) {
635 for (ExtensionList::const_iterator extension = toolbar_items_.begin(); 637 for (ExtensionList::const_iterator extension = toolbar_items_.begin();
636 extension != toolbar_items_.end(); ++extension) { 638 extension != toolbar_items_.end(); ++extension) {
637 if ((*extension)->id() == (*it)) { 639 if ((*extension)->id() == (*it)) {
638 if (extension - toolbar_items_.begin() >= visible_icon_count_) 640 if (extension - toolbar_items_.begin() >= visible_icon_count_)
639 MoveExtensionIcon(*extension, 0); 641 MoveExtensionIcon(extension->get(), 0);
640 break; 642 break;
641 } 643 }
642 } 644 }
643 } 645 }
644 } 646 }
645 647
646 bool ExtensionToolbarModel::HighlightExtensions( 648 bool ExtensionToolbarModel::HighlightExtensions(
647 const ExtensionIdList& extension_ids) { 649 const ExtensionIdList& extension_ids) {
648 highlighted_items_.clear(); 650 highlighted_items_.clear();
649 651
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 FOR_EACH_OBSERVER(Observer, observers_, ToolbarHighlightModeChanged(false)); 693 FOR_EACH_OBSERVER(Observer, observers_, ToolbarHighlightModeChanged(false));
692 } 694 }
693 } 695 }
694 696
695 void ExtensionToolbarModel::SetVisibleIconCountForTest(size_t visible_icons) { 697 void ExtensionToolbarModel::SetVisibleIconCountForTest(size_t visible_icons) {
696 SetVisibleIconCount(visible_icons); 698 SetVisibleIconCount(visible_icons);
697 FOR_EACH_OBSERVER(Observer, observers_, ToolbarVisibleCountChanged()); 699 FOR_EACH_OBSERVER(Observer, observers_, ToolbarVisibleCountChanged());
698 } 700 }
699 701
700 } // namespace extensions 702 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698