| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/core/contents/blimp_contents_manager.h" | 5 #include "blimp/client/core/contents/blimp_contents_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "blimp/client/core/contents/tab_control_feature.h" | 10 #include "blimp/client/core/contents/tab_control_feature.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 NavigationFeature* nav_feature, | 49 NavigationFeature* nav_feature, |
| 50 TabControlFeature* tab_control_feature) | 50 TabControlFeature* tab_control_feature) |
| 51 : ime_feature_(ime_feature), | 51 : ime_feature_(ime_feature), |
| 52 navigation_feature_(nav_feature), | 52 navigation_feature_(nav_feature), |
| 53 tab_control_feature_(tab_control_feature), | 53 tab_control_feature_(tab_control_feature), |
| 54 weak_ptr_factory_(this) {} | 54 weak_ptr_factory_(this) {} |
| 55 | 55 |
| 56 BlimpContentsManager::~BlimpContentsManager() {} | 56 BlimpContentsManager::~BlimpContentsManager() {} |
| 57 | 57 |
| 58 std::unique_ptr<BlimpContentsImpl> BlimpContentsManager::CreateBlimpContents() { | 58 std::unique_ptr<BlimpContentsImpl> BlimpContentsManager::CreateBlimpContents() { |
| 59 if (tab_exists_) return nullptr; |
| 60 tab_exists_ = true; |
| 61 |
| 59 int id = CreateBlimpContentsId(); | 62 int id = CreateBlimpContentsId(); |
| 60 | 63 |
| 61 std::unique_ptr<BlimpContentsImpl> new_contents = | 64 std::unique_ptr<BlimpContentsImpl> new_contents = |
| 62 base::MakeUnique<BlimpContentsImpl>(id, ime_feature_, navigation_feature_, | 65 base::MakeUnique<BlimpContentsImpl>(id, ime_feature_, navigation_feature_, |
| 63 tab_control_feature_); | 66 tab_control_feature_); |
| 64 | 67 |
| 65 // Create an observer entry for the contents. | 68 // Create an observer entry for the contents. |
| 66 std::unique_ptr<BlimpContentsDeletionObserver> observer = | 69 std::unique_ptr<BlimpContentsDeletionObserver> observer = |
| 67 base::MakeUnique<BlimpContentsDeletionObserver>(this, new_contents.get()); | 70 base::MakeUnique<BlimpContentsDeletionObserver>(this, new_contents.get()); |
| 68 observer_map_.insert( | 71 observer_map_.insert( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 93 // dummy tab id. Need to return real case id when Blimp supports multiple | 96 // dummy tab id. Need to return real case id when Blimp supports multiple |
| 94 // tabs. | 97 // tabs. |
| 95 return kDummyTabId; | 98 return kDummyTabId; |
| 96 } | 99 } |
| 97 | 100 |
| 98 void BlimpContentsManager::EraseObserverFromMap(int id) { | 101 void BlimpContentsManager::EraseObserverFromMap(int id) { |
| 99 observer_map_.erase(id); | 102 observer_map_.erase(id); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void BlimpContentsManager::OnContentsDestroyed(BlimpContents* contents) { | 105 void BlimpContentsManager::OnContentsDestroyed(BlimpContents* contents) { |
| 106 DCHECK(tab_exists_); |
| 107 tab_exists_ = false; |
| 108 |
| 103 int id = static_cast<BlimpContentsImpl*>(contents)->id(); | 109 int id = static_cast<BlimpContentsImpl*>(contents)->id(); |
| 104 | 110 |
| 105 // Notify the engine that we've destroyed the BlimpContents. | 111 // Notify the engine that we've destroyed the BlimpContents. |
| 106 tab_control_feature_->CloseTab(id); | 112 tab_control_feature_->CloseTab(id); |
| 107 | 113 |
| 108 // Destroy the observer entry from the observer_map_. | 114 // Destroy the observer entry from the observer_map_. |
| 109 DCHECK(base::ThreadTaskRunnerHandle::Get()); | 115 DCHECK(base::ThreadTaskRunnerHandle::Get()); |
| 110 base::ThreadTaskRunnerHandle::Get()->PostTask( | 116 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 111 FROM_HERE, base::Bind(&BlimpContentsManager::EraseObserverFromMap, | 117 FROM_HERE, base::Bind(&BlimpContentsManager::EraseObserverFromMap, |
| 112 this->GetWeakPtr(), id)); | 118 this->GetWeakPtr(), id)); |
| 113 } | 119 } |
| 114 | 120 |
| 115 base::WeakPtr<BlimpContentsManager> BlimpContentsManager::GetWeakPtr() { | 121 base::WeakPtr<BlimpContentsManager> BlimpContentsManager::GetWeakPtr() { |
| 116 return weak_ptr_factory_.GetWeakPtr(); | 122 return weak_ptr_factory_.GetWeakPtr(); |
| 117 } | 123 } |
| 118 | 124 |
| 119 } // namespace client | 125 } // namespace client |
| 120 } // namespace blimp | 126 } // namespace blimp |
| OLD | NEW |