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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « blimp/engine/common/tab_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "blimp/engine/common/tab_manager.h"
6
7 #include <utility>
8
9 #include "base/macros.h"
10 #include "base/stl_util.h"
11 #include "blimp/engine/common/tab.h"
12
13 namespace blimp {
14 namespace engine {
15
16 TabManager::TabManager() {}
17
18 TabManager::~TabManager() {}
19
20 void TabManager::Add(std::unique_ptr<Tab> tab) {
21 DCHECK(tab);
22 DCHECK(!ContainsKey(tabs_, tab->id()));
23
24 tabs_by_webcontents_[tab->web_contents()] = tab.get();
25 tabs_[tab->id()] = std::move(tab);
26 }
27
28 void TabManager::Remove(Tab* tab) {
29 DCHECK(tab);
30
31 if (!ContainsKey(tabs_, tab->id())) {
32 return;
33 }
34 tabs_by_webcontents_.erase(tabs_[tab->id()]->web_contents());
35 tabs_.erase(tab->id());
36 }
37
38 void TabManager::Clear() {
39 tabs_.clear();
40 tabs_by_webcontents_.clear();
41 }
42
43 Tab* TabManager::FindTabById(int tab_id) const {
44 return (tabs_.find(tab_id) != tabs_.end()) ? tabs_.find(tab_id)->second.get()
45 : nullptr;
46 }
47
48 Tab* TabManager::FindTabByWebContents(content::WebContents* contents) const {
49 return (tabs_by_webcontents_.find(contents) != tabs_by_webcontents_.end())
50 ? tabs_by_webcontents_.find(contents)->second
51 : nullptr;
52 }
53
54 Tab* TabManager::GetOnlyTab() const {
55 return (tabs_.size() == 1 ? tabs_.begin()->second.get() : nullptr);
56 }
57
58 } // namespace engine
59 } // namespace blimp
OLDNEW
« 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