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

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

Issue 2332693003: Show media router toolbar icon ephemerally for active local routes and issues (Closed)
Patch Set: Address Devlin's comments Created 4 years, 3 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()));
332 } 331 }
333 332
334 void ToolbarActionsModel::AddItem(const ToolbarItem& item, bool is_component) { 333 void ToolbarActionsModel::AddItem(const ToolbarItem& item) {
335 // We only use AddItem() once the system is initialized. 334 // We only use AddItem() once the system is initialized.
336 DCHECK(actions_initialized_); 335 DCHECK(actions_initialized_);
337 336
338 // See if we have a last known good position for this extension. 337 // See if we have a last known good position for this extension.
339 bool is_new_extension = !base::ContainsValue(last_known_positions_, item.id); 338 bool is_new_extension = !base::ContainsValue(last_known_positions_, item.id);
340 339
341 // New extensions go at the right (end) of the visible extensions. Other 340 // New extensions go at the right (end) of the visible extensions. Other
342 // extensions go at their previous position. 341 // extensions go at their previous position.
343 size_t new_index = 0; 342 size_t new_index = 0;
344 if (is_new_extension) { 343 if (is_new_extension) {
345 new_index = is_component ? 0 : visible_icon_count(); 344 new_index = visible_icon_count();
346 // For the last-known position, we use the index of the extension that is 345 // For the last-known position, we use the index of the extension that is
347 // just before this extension, plus one. (Note that this isn't the same 346 // just before this extension, plus one. (Note that this isn't the same
348 // as new_index + 1, because last_known_positions_ can include disabled 347 // as new_index + 1, because last_known_positions_ can include disabled
349 // extensions.) 348 // extensions.)
350 int new_last_known_index = 349 int new_last_known_index =
351 new_index == 0 ? 0 : std::find(last_known_positions_.begin(), 350 new_index == 0 ? 0 : std::find(last_known_positions_.begin(),
352 last_known_positions_.end(), 351 last_known_positions_.end(),
353 toolbar_items_[new_index - 1].id) - 352 toolbar_items_[new_index - 1].id) -
354 last_known_positions_.begin() + 1; 353 last_known_positions_.begin() + 1;
355 // In theory, the extension before this one should always 354 // In theory, the extension before this one should always
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 bool ToolbarActionsModel::HasComponentAction( 624 bool ToolbarActionsModel::HasComponentAction(
626 const std::string& action_id) const { 625 const std::string& action_id) const {
627 DCHECK(use_redesign_); 626 DCHECK(use_redesign_);
628 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION)); 627 return HasItem(ToolbarItem(action_id, COMPONENT_ACTION));
629 } 628 }
630 629
631 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) { 630 void ToolbarActionsModel::AddComponentAction(const std::string& action_id) {
632 DCHECK(use_redesign_); 631 DCHECK(use_redesign_);
633 ToolbarItem component_item(action_id, COMPONENT_ACTION); 632 ToolbarItem component_item(action_id, COMPONENT_ACTION);
634 DCHECK(!HasItem(component_item)); 633 DCHECK(!HasItem(component_item));
635 AddItem(component_item, true); 634 AddItem(component_item);
636 } 635 }
637 636
638 void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) { 637 void ToolbarActionsModel::RemoveComponentAction(const std::string& action_id) {
639 DCHECK(use_redesign_); 638 DCHECK(use_redesign_);
640 ToolbarItem component_item(action_id, COMPONENT_ACTION); 639 ToolbarItem component_item(action_id, COMPONENT_ACTION);
641 DCHECK(HasItem(component_item)); 640 DCHECK(HasItem(component_item));
642 RemoveItem(component_item); 641 RemoveItem(component_item);
643 RemovePref(component_item); 642 RemovePref(component_item);
644 } 643 }
645 644
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 prefs_->GetInteger(extensions::pref_names::kToolbarSize); 836 prefs_->GetInteger(extensions::pref_names::kToolbarSize);
838 if (saved_icon_count != visible_icon_count_) 837 if (saved_icon_count != visible_icon_count_)
839 SetVisibleIconCount(saved_icon_count); 838 SetVisibleIconCount(saved_icon_count);
840 } 839 }
841 } 840 }
842 841
843 const extensions::Extension* ToolbarActionsModel::GetExtensionById( 842 const extensions::Extension* ToolbarActionsModel::GetExtensionById(
844 const std::string& id) const { 843 const std::string& id) const {
845 return extension_registry_->enabled_extensions().GetByID(id); 844 return extension_registry_->enabled_extensions().GetByID(id);
846 } 845 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698