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..0b8872ba2499226e441186192ec8d949cc9d1e2c |
--- /dev/null |
+++ b/chrome/browser/ui/tabs/tab_mru_list_manager.cc |
@@ -0,0 +1,90 @@ |
+// 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() { |
+} |
+ |
+TabMRUListManager::~TabMRUListManager() { |
+ tabs_mru_list_.clear(); |
+} |
+ |
+void TabMRUListManager::TabInsertedAt(TabContentsWrapper* contents, |
+ int index, |
+ bool foreground) { |
+ tabs_mru_list_.push_front(contents); |
sky
2012/05/29 19:48:28
You only want to add to the front if foreground is
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
|
+} |
+ |
+void TabMRUListManager::TabClosingAt(TabStripModel* tab_strip_model, |
+ TabContentsWrapper* contents, |
+ int index) { |
+ // Remove the index if found in MRU List |
sky
2012/05/29 19:48:28
You shouldn't need to override this. Instead put l
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
|
+ 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::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); |
+ tabs_mru_list_.erase(it); |
sky
2012/05/29 19:48:28
You should always push_front, right?
NaveenBobbili (Motorola)
2012/06/05 05:34:16
This case would arrive if the tab is manually acti
|
+ } |
+} |
+ |
+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); |
+ tabs_mru_list_.erase(it); |
+ } else { |
+ tabs_mru_list_.push_back(new_contents); |
sky
2012/05/29 19:48:28
This should be NOTREACHED
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
|
+ } |
+} |
+ |
+void TabMRUListManager::TabStripEmpty() { |
+ tabs_mru_list_.clear(); |
+} |
+ |
+// Public Methods |
+TabContentsWrapper* TabMRUListManager::GetNextMRUTab() { |
+ std::list<TabContentsWrapper*>::iterator it = tabs_mru_list_.begin(); |
+ // Advance to second element in MRU list if there are more than one tabs open. |
+ if (tabs_mru_list_.size() > 1) { |
+ std::advance(it, 1); |
+ } |
+ return *it; |
sky
2012/05/29 19:48:28
This will crash if empty.
NaveenBobbili (Motorola)
2012/06/05 05:34:16
Done.
|
+} |