Index: chrome/browser/tabs/tab_mru_list_manager.cc |
diff --git a/chrome/browser/tabs/tab_mru_list_manager.cc b/chrome/browser/tabs/tab_mru_list_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..661d98c3b34703d0865f370c7c2be646fc2fb5b9 |
--- /dev/null |
+++ b/chrome/browser/tabs/tab_mru_list_manager.cc |
@@ -0,0 +1,85 @@ |
+// 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/tabs/tab_mru_list_manager.h" |
+ |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+// TabMRUListManager, public: |
+ |
+TabMRUListManager::~TabMRUListManager() { |
+ tabs_mru_list_.clear(); |
+} |
+ |
+void TabMRUListManager::ActivateContents(TabContentsWrapper* new_contents) { |
+ if (!new_contents) |
+ return; |
+ |
+ // 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); |
+ } else { |
+ tabs_mru_list_.push_front(new_contents); |
+ } |
+} |
+ |
+void TabMRUListManager::AppendContents(TabContentsWrapper* new_contents) { |
+ if (!new_contents) |
+ return; |
+ |
+ // 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); |
+ // Append only if the content are not present in the list. |
+ // This will avoid duplicates. |
+ if (it == tabs_mru_list_.end()) { |
+ tabs_mru_list_.push_back(new_contents); |
+ } |
+} |
+ |
+void TabMRUListManager::ClearContents() { |
+ tabs_mru_list_.clear(); |
+} |
+ |
+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; |
+} |
+ |
+void TabMRUListManager::RemoveContents(TabContentsWrapper* removed_contents) { |
+ // Remove the contents if found in MRU List |
+ std::list<TabContentsWrapper*>::iterator it = |
+ std::find(tabs_mru_list_.begin(), |
+ tabs_mru_list_.end(), |
+ removed_contents); |
+ if (it != tabs_mru_list_.end()) { |
+ tabs_mru_list_.erase(it); |
+ } |
+} |
+ |
+void TabMRUListManager::ReplaceContents( |
+ TabContentsWrapper* old_contents, TabContentsWrapper* new_contents) { |
+ // 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); |
+ } |
+} |