| 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/ui/toolbar/toolbar_actions_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 | 329 |
| 330 AddItem(ToolbarItem(extension->id(), EXTENSION_ACTION), | 330 AddItem(ToolbarItem(extension->id(), EXTENSION_ACTION), |
| 331 extensions::Manifest::IsComponentLocation(extension->location())); | 331 extensions::Manifest::IsComponentLocation(extension->location())); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void ToolbarActionsModel::AddItem(const ToolbarItem& item, bool is_component) { | 334 void ToolbarActionsModel::AddItem(const ToolbarItem& item, bool is_component) { |
| 335 // We only use AddItem() once the system is initialized. | 335 // We only use AddItem() once the system is initialized. |
| 336 DCHECK(actions_initialized_); | 336 DCHECK(actions_initialized_); |
| 337 | 337 |
| 338 // See if we have a last known good position for this extension. | 338 // See if we have a last known good position for this extension. |
| 339 bool is_new_extension = | 339 bool is_new_extension = !base::ContainsValue(last_known_positions_, item.id); |
| 340 !ContainsValue(last_known_positions_, item.id); | |
| 341 | 340 |
| 342 // New extensions go at the right (end) of the visible extensions. Other | 341 // New extensions go at the right (end) of the visible extensions. Other |
| 343 // extensions go at their previous position. | 342 // extensions go at their previous position. |
| 344 size_t new_index = 0; | 343 size_t new_index = 0; |
| 345 if (is_new_extension) { | 344 if (is_new_extension) { |
| 346 new_index = is_component ? 0 : visible_icon_count(); | 345 new_index = is_component ? 0 : visible_icon_count(); |
| 347 // For the last-known position, we use the index of the extension that is | 346 // For the last-known position, we use the index of the extension that is |
| 348 // just before this extension, plus one. (Note that this isn't the same | 347 // just before this extension, plus one. (Note that this isn't the same |
| 349 // as new_index + 1, because last_known_positions_ can include disabled | 348 // as new_index + 1, because last_known_positions_ can include disabled |
| 350 // extensions.) | 349 // extensions.) |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // BrowserActionsVisible is when the redesign has been enabled. | 612 // BrowserActionsVisible is when the redesign has been enabled. |
| 614 UMA_HISTOGRAM_COUNTS_100("Toolbar.ActionsModel.ToolbarActionsVisible", | 613 UMA_HISTOGRAM_COUNTS_100("Toolbar.ActionsModel.ToolbarActionsVisible", |
| 615 visible_icon_count_ == -1 | 614 visible_icon_count_ == -1 |
| 616 ? base::HistogramBase::kSampleType_MAX | 615 ? base::HistogramBase::kSampleType_MAX |
| 617 : visible_icon_count_); | 616 : visible_icon_count_); |
| 618 } | 617 } |
| 619 } | 618 } |
| 620 } | 619 } |
| 621 | 620 |
| 622 bool ToolbarActionsModel::HasItem(const ToolbarItem& item) const { | 621 bool ToolbarActionsModel::HasItem(const ToolbarItem& item) const { |
| 623 return ContainsValue(toolbar_items_, item); | 622 return base::ContainsValue(toolbar_items_, item); |
| 624 } | 623 } |
| 625 | 624 |
| 626 bool ToolbarActionsModel::HasComponentAction( | 625 bool ToolbarActionsModel::HasComponentAction( |
| 627 const std::string& action_id) const { | 626 const std::string& action_id) const { |
| 628 DCHECK(use_redesign_); | 627 DCHECK(use_redesign_); |
| 629 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION)); | 628 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION)); |
| 630 } | 629 } |
| 631 | 630 |
| 632 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) { | 631 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) { |
| 633 DCHECK(use_redesign_); | 632 DCHECK(use_redesign_); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 void ToolbarActionsModel::OnActionToolbarPrefChange() { | 735 void ToolbarActionsModel::OnActionToolbarPrefChange() { |
| 737 // If extensions are not ready, defer to later Populate() call. | 736 // If extensions are not ready, defer to later Populate() call. |
| 738 if (!actions_initialized_) | 737 if (!actions_initialized_) |
| 739 return; | 738 return; |
| 740 | 739 |
| 741 // Recalculate |last_known_positions_| to be |pref_positions| followed by | 740 // Recalculate |last_known_positions_| to be |pref_positions| followed by |
| 742 // ones that are only in |last_known_positions_|. | 741 // ones that are only in |last_known_positions_|. |
| 743 std::vector<std::string> pref_positions = extension_prefs_->GetToolbarOrder(); | 742 std::vector<std::string> pref_positions = extension_prefs_->GetToolbarOrder(); |
| 744 size_t pref_position_size = pref_positions.size(); | 743 size_t pref_position_size = pref_positions.size(); |
| 745 for (size_t i = 0; i < last_known_positions_.size(); ++i) { | 744 for (size_t i = 0; i < last_known_positions_.size(); ++i) { |
| 746 if (!ContainsValue(pref_positions, last_known_positions_[i])) { | 745 if (!base::ContainsValue(pref_positions, last_known_positions_[i])) { |
| 747 pref_positions.push_back(last_known_positions_[i]); | 746 pref_positions.push_back(last_known_positions_[i]); |
| 748 } | 747 } |
| 749 } | 748 } |
| 750 last_known_positions_.swap(pref_positions); | 749 last_known_positions_.swap(pref_positions); |
| 751 | 750 |
| 752 // Loop over the updated list of last known positions, moving any extensions | 751 // Loop over the updated list of last known positions, moving any extensions |
| 753 // that are in the wrong place. | 752 // that are in the wrong place. |
| 754 auto desired_pos = toolbar_items_.begin(); | 753 auto desired_pos = toolbar_items_.begin(); |
| 755 for (const std::string& id : last_known_positions_) { | 754 for (const std::string& id : last_known_positions_) { |
| 756 auto current_pos = std::find_if( | 755 auto current_pos = std::find_if( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 prefs_->GetInteger(extensions::pref_names::kToolbarSize); | 837 prefs_->GetInteger(extensions::pref_names::kToolbarSize); |
| 839 if (saved_icon_count != visible_icon_count_) | 838 if (saved_icon_count != visible_icon_count_) |
| 840 SetVisibleIconCount(saved_icon_count); | 839 SetVisibleIconCount(saved_icon_count); |
| 841 } | 840 } |
| 842 } | 841 } |
| 843 | 842 |
| 844 const extensions::Extension* ToolbarActionsModel::GetExtensionById( | 843 const extensions::Extension* ToolbarActionsModel::GetExtensionById( |
| 845 const std::string& id) const { | 844 const std::string& id) const { |
| 846 return extension_registry_->enabled_extensions().GetByID(id); | 845 return extension_registry_->enabled_extensions().GetByID(id); |
| 847 } | 846 } |
| OLD | NEW |