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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_model.cc

Issue 2260343002: Revert of Show the Cast toolbar icon ephemerally when Cast is in use (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 320 }
321 321
322 return extension_action_manager_->GetBrowserAction(*extension) && 322 return extension_action_manager_->GetBrowserAction(*extension) &&
323 extension_action_api_->GetBrowserActionVisibility(extension->id()); 323 extension_action_api_->GetBrowserActionVisibility(extension->id());
324 } 324 }
325 325
326 void ToolbarActionsModel::AddExtension(const extensions::Extension* extension) { 326 void ToolbarActionsModel::AddExtension(const extensions::Extension* extension) {
327 if (!ShouldAddExtension(extension)) 327 if (!ShouldAddExtension(extension))
328 return; 328 return;
329 329
330 AddItem(ToolbarItem(extension->id(), EXTENSION_ACTION)); 330 AddItem(ToolbarItem(extension->id(), EXTENSION_ACTION),
331 extensions::Manifest::IsComponentLocation(extension->location()));
331 } 332 }
332 333
333 void ToolbarActionsModel::AddItem(const ToolbarItem& item) { 334 void ToolbarActionsModel::AddItem(const ToolbarItem& item, bool is_component) {
334 // We only use AddItem() once the system is initialized. 335 // We only use AddItem() once the system is initialized.
335 DCHECK(actions_initialized_); 336 DCHECK(actions_initialized_);
336 337
337 // 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.
338 bool is_new_extension = !base::ContainsValue(last_known_positions_, item.id); 339 bool is_new_extension = !base::ContainsValue(last_known_positions_, item.id);
339 340
340 // 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
341 // extensions go at their previous position. 342 // extensions go at their previous position.
342 size_t new_index = 0; 343 size_t new_index = 0;
343 if (is_new_extension) { 344 if (is_new_extension) {
344 new_index = visible_icon_count(); 345 new_index = is_component ? 0 : visible_icon_count();
345 // 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
346 // 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
347 // as new_index + 1, because last_known_positions_ can include disabled 348 // as new_index + 1, because last_known_positions_ can include disabled
348 // extensions.) 349 // extensions.)
349 int new_last_known_index = 350 int new_last_known_index =
350 new_index == 0 ? 0 : std::find(last_known_positions_.begin(), 351 new_index == 0 ? 0 : std::find(last_known_positions_.begin(),
351 last_known_positions_.end(), 352 last_known_positions_.end(),
352 toolbar_items_[new_index - 1].id) - 353 toolbar_items_[new_index - 1].id) -
353 last_known_positions_.begin() + 1; 354 last_known_positions_.begin() + 1;
354 // In theory, the extension before this one should always 355 // In theory, the extension before this one should always
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 bool ToolbarActionsModel::HasComponentAction( 625 bool ToolbarActionsModel::HasComponentAction(
625 const std::string& action_id) const { 626 const std::string& action_id) const {
626 DCHECK(use_redesign_); 627 DCHECK(use_redesign_);
627 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION)); 628 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION));
628 } 629 }
629 630
630 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) { 631 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) {
631 DCHECK(use_redesign_); 632 DCHECK(use_redesign_);
632 ToolbarItem component_item(action_id, COMPONENT_ACTION); 633 ToolbarItem component_item(action_id, COMPONENT_ACTION);
633 DCHECK(!HasItem(component_item)); 634 DCHECK(!HasItem(component_item));
634 AddItem(component_item); 635 AddItem(component_item, true);
635 } 636 }
636 637
637 void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) { 638 void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) {
638 DCHECK(use_redesign_); 639 DCHECK(use_redesign_);
639 ToolbarItem component_item(action_id, COMPONENT_ACTION); 640 ToolbarItem component_item(action_id, COMPONENT_ACTION);
640 DCHECK(HasItem(component_item)); 641 DCHECK(HasItem(component_item));
641 RemoveItem(component_item); 642 RemoveItem(component_item);
642 RemovePref(component_item); 643 RemovePref(component_item);
643 } 644 }
644 645
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 prefs_->GetInteger(extensions::pref_names::kToolbarSize); 837 prefs_->GetInteger(extensions::pref_names::kToolbarSize);
837 if (saved_icon_count != visible_icon_count_) 838 if (saved_icon_count != visible_icon_count_)
838 SetVisibleIconCount(saved_icon_count); 839 SetVisibleIconCount(saved_icon_count);
839 } 840 }
840 } 841 }
841 842
842 const extensions::Extension* ToolbarActionsModel::GetExtensionById( 843 const extensions::Extension* ToolbarActionsModel::GetExtensionById(
843 const std::string& id) const { 844 const std::string& id) const {
844 return extension_registry_->enabled_extensions().GetByID(id); 845 return extension_registry_->enabled_extensions().GetByID(id);
845 } 846 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_actions_model.h ('k') | chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698