| OLD | NEW |
| (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 |
| OLD | NEW |