Chromium Code Reviews| Index: chrome/browser/ui/tabs/tab_mru_list_manager.cc |
| diff --git a/chrome/browser/ui/tabs/tab_mru_list_manager.cc b/chrome/browser/ui/tabs/tab_mru_list_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9247a2eff765cbf1a8c365db9feb2b02aed39899 |
| --- /dev/null |
| +++ b/chrome/browser/ui/tabs/tab_mru_list_manager.cc |
| @@ -0,0 +1,88 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/tabs/tab_mru_list_manager.h" |
| + |
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// TabMRUListManager, public: |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// TabMRUListManager, TabStripModelObserver implementation: |
| + |
| +TabMRUListManager::TabMRUListManager(TabStripModel* tab_strip_model) |
| + : tab_strip_model_(tab_strip_model) { |
| + if (tab_strip_model_) |
|
sky
2012/06/11 18:21:51
When would the model ever be NULL?
NaveenBobbili (Motorola)
2012/06/13 06:07:32
Protection code. Unit tests would need this check.
|
| + tab_strip_model_->AddObserver(this); |
| +} |
| + |
| +TabMRUListManager::~TabMRUListManager() { |
| + tabs_mru_list_.clear(); |
| + if (tab_strip_model_) |
| + tab_strip_model_->RemoveObserver(this); |
| +} |
| + |
| +void TabMRUListManager::TabInsertedAt(TabContentsWrapper* contents, |
| + int index, |
| + bool foreground) { |
| + if (foreground) |
| + tabs_mru_list_.push_front(contents); |
| + else |
| + tabs_mru_list_.push_back(contents); |
| +} |
| + |
| +void TabMRUListManager::TabDetachedAt(TabContentsWrapper* contents, |
| + int index) { |
| + // Remove the index if found in MRU List |
| + std::list<TabContentsWrapper*>::iterator it = |
| + std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), contents); |
| + if (it != tabs_mru_list_.end()) { |
| + tabs_mru_list_.erase(it); |
| + } |
| +} |
| + |
| +void TabMRUListManager::ActiveTabChanged(TabContentsWrapper* old_contents, |
| + TabContentsWrapper* new_contents, |
| + int index, |
| + bool user_gesture) { |
| + // Bring the activated tab content to the front of the list |
| + std::list<TabContentsWrapper*>::iterator it = |
| + std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), new_contents); |
| + if (it != tabs_mru_list_.end()) { |
| + tabs_mru_list_.push_front(*it); |
|
sky
2012/06/11 18:21:51
Why is the push conditional?
NaveenBobbili (Motorola)
2012/06/13 06:07:32
ActiveTabChanged should ideally be called after Ta
|
| + tabs_mru_list_.erase(it); |
| + } |
| +} |
| + |
| +void TabMRUListManager::TabReplacedAt(TabStripModel* tab_strip_model, |
| + TabContentsWrapper* old_contents, |
| + TabContentsWrapper* new_contents, |
| + int index) { |
| + // Replace the tab contents accordingly in the list. If the tab contents are |
| + // not found add to the end of the list. |
| + std::list<TabContentsWrapper*>::iterator it = |
| + std::find(tabs_mru_list_.begin(), tabs_mru_list_.end(), old_contents); |
| + if (it != tabs_mru_list_.end()) { |
| + tabs_mru_list_.insert(it,new_contents); |
|
sky
2012/06/11 18:21:51
space after ','
NaveenBobbili (Motorola)
2012/06/13 06:07:32
Done.
|
| + tabs_mru_list_.erase(it); |
| + } else { |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void TabMRUListManager::TabStripEmpty() { |
| + tabs_mru_list_.clear(); |
| +} |
| + |
| +// Public Methods |
|
sky
2012/06/11 18:21:51
remove this comment.
NaveenBobbili (Motorola)
2012/06/13 06:07:32
Done.
|
| +TabContentsWrapper* TabMRUListManager::GetNextMRUTab() { |
|
sky
2012/06/11 18:21:51
Order should match header.
NaveenBobbili (Motorola)
2012/06/13 06:07:32
Done.
|
| + // Only if there are more than one open tab we can switch. |
| + if (tabs_mru_list_.size() < 2) |
| + return NULL; |
| + |
| + std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin(); |
| + std::advance(it, 1); |
| + return *it; |
| +} |