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

Unified Diff: blimp/engine/common/tab_manager.cc

Issue 2176733003: Add TabManager class, relocate Tab to common/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/engine/common/tab_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/engine/common/tab_manager.cc
diff --git a/blimp/engine/common/tab_manager.cc b/blimp/engine/common/tab_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97fa3e00566113dd994b3a3133c2eb1ac58074e9
--- /dev/null
+++ b/blimp/engine/common/tab_manager.cc
@@ -0,0 +1,59 @@
+// Copyright 2016 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 "blimp/engine/common/tab_manager.h"
+
+#include <utility>
+
+#include "base/macros.h"
+#include "base/stl_util.h"
+#include "blimp/engine/common/tab.h"
+
+namespace blimp {
+namespace engine {
+
+TabManager::TabManager() {}
+
+TabManager::~TabManager() {}
+
+void TabManager::Add(std::unique_ptr<Tab> tab) {
+ DCHECK(tab);
+ DCHECK(!ContainsKey(tabs_, tab->id()));
+
+ tabs_by_webcontents_[tab->web_contents()] = tab.get();
+ tabs_[tab->id()] = std::move(tab);
+}
+
+void TabManager::Remove(Tab* tab) {
+ DCHECK(tab);
+
+ if (!ContainsKey(tabs_, tab->id())) {
+ return;
+ }
+ tabs_by_webcontents_.erase(tabs_[tab->id()]->web_contents());
+ tabs_.erase(tab->id());
+}
+
+void TabManager::Clear() {
+ tabs_.clear();
+ tabs_by_webcontents_.clear();
+}
+
+Tab* TabManager::FindTabById(int tab_id) const {
+ return (tabs_.find(tab_id) != tabs_.end()) ? tabs_.find(tab_id)->second.get()
+ : nullptr;
+}
+
+Tab* TabManager::FindTabByWebContents(content::WebContents* contents) const {
+ return (tabs_by_webcontents_.find(contents) != tabs_by_webcontents_.end())
+ ? tabs_by_webcontents_.find(contents)->second
+ : nullptr;
+}
+
+Tab* TabManager::GetOnlyTab() const {
+ return (tabs_.size() == 1 ? tabs_.begin()->second.get() : nullptr);
+}
+
+} // namespace engine
+} // namespace blimp
« no previous file with comments | « blimp/engine/common/tab_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698