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/compositor/blimp_compositor_dependencies.h" | 10 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
11 #include "blimp/client/core/contents/blimp_contents_impl.h" | 11 #include "blimp/client/core/contents/blimp_contents_impl.h" |
12 #include "blimp/client/core/contents/navigation_feature.h" | 12 #include "blimp/client/core/contents/navigation_feature.h" |
13 #include "blimp/client/core/contents/tab_control_feature.h" | 13 #include "blimp/client/core/contents/tab_control_feature.h" |
14 #include "blimp/client/core/render_widget/render_widget_feature.h" | 14 #include "blimp/client/core/render_widget/render_widget_feature.h" |
15 #include "blimp/client/public/contents/blimp_contents_observer.h" | 15 #include "blimp/client/public/contents/blimp_contents_observer.h" |
16 | 16 |
17 namespace { | |
18 const int kDummyTabId = 0; | |
19 } | |
20 | |
21 namespace blimp { | 17 namespace blimp { |
22 namespace client { | 18 namespace client { |
23 | 19 |
24 class BlimpContentsManager::BlimpContentsDeletionObserver | 20 class BlimpContentsManager::BlimpContentsDeletionObserver |
25 : public BlimpContentsObserver { | 21 : public BlimpContentsObserver { |
26 public: | 22 public: |
27 BlimpContentsDeletionObserver(BlimpContentsManager* blimp_contents_manager, | 23 BlimpContentsDeletionObserver(BlimpContentsManager* blimp_contents_manager, |
28 BlimpContentsImpl* blimp_contents); | 24 BlimpContentsImpl* blimp_contents); |
29 | 25 |
30 void OnContentsDestroyed() override; | 26 void OnContentsDestroyed() override; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // If the BlimpContents that the observer tracks is empty, it means | 91 // If the BlimpContents that the observer tracks is empty, it means |
96 // OnContentsDestroyed was called on this observer, but the task to erase | 92 // OnContentsDestroyed was called on this observer, but the task to erase |
97 // the observer from the map hasn't been run. | 93 // the observer from the map hasn't been run. |
98 if (observer->blimp_contents()) | 94 if (observer->blimp_contents()) |
99 return static_cast<BlimpContentsImpl*>(observer->blimp_contents()); | 95 return static_cast<BlimpContentsImpl*>(observer->blimp_contents()); |
100 | 96 |
101 return nullptr; | 97 return nullptr; |
102 } | 98 } |
103 | 99 |
104 int BlimpContentsManager::CreateBlimpContentsId() { | 100 int BlimpContentsManager::CreateBlimpContentsId() { |
105 // TODO(mlliu): currently, Blimp only supports a single tab, so returning a | 101 return next_blimp_contents_id_++; |
106 // dummy tab id. Need to return real case id when Blimp supports multiple | |
107 // tabs. | |
108 return kDummyTabId; | |
109 } | 102 } |
110 | 103 |
111 void BlimpContentsManager::EraseObserverFromMap(int id) { | 104 void BlimpContentsManager::EraseObserverFromMap(int id) { |
112 observer_map_.erase(id); | 105 observer_map_.erase(id); |
113 } | 106 } |
114 | 107 |
115 void BlimpContentsManager::OnContentsDestroyed(BlimpContents* contents) { | 108 void BlimpContentsManager::OnContentsDestroyed(BlimpContents* contents) { |
116 DCHECK(tab_exists_); | 109 DCHECK(tab_exists_); |
117 tab_exists_ = false; | 110 tab_exists_ = false; |
118 | 111 |
119 int id = static_cast<BlimpContentsImpl*>(contents)->id(); | 112 int id = static_cast<BlimpContentsImpl*>(contents)->id(); |
120 | 113 |
121 // Notify the engine that we've destroyed the BlimpContents. | 114 // Notify the engine that we've destroyed the BlimpContents. |
122 tab_control_feature_->CloseTab(id); | 115 tab_control_feature_->CloseTab(id); |
123 | 116 |
124 // Destroy the observer entry from the observer_map_. | 117 // Destroy the observer entry from the observer_map_. |
125 DCHECK(base::ThreadTaskRunnerHandle::Get()); | 118 DCHECK(base::ThreadTaskRunnerHandle::Get()); |
126 base::ThreadTaskRunnerHandle::Get()->PostTask( | 119 base::ThreadTaskRunnerHandle::Get()->PostTask( |
127 FROM_HERE, base::Bind(&BlimpContentsManager::EraseObserverFromMap, | 120 FROM_HERE, base::Bind(&BlimpContentsManager::EraseObserverFromMap, |
128 this->GetWeakPtr(), id)); | 121 this->GetWeakPtr(), id)); |
129 } | 122 } |
130 | 123 |
131 base::WeakPtr<BlimpContentsManager> BlimpContentsManager::GetWeakPtr() { | 124 base::WeakPtr<BlimpContentsManager> BlimpContentsManager::GetWeakPtr() { |
132 return weak_ptr_factory_.GetWeakPtr(); | 125 return weak_ptr_factory_.GetWeakPtr(); |
133 } | 126 } |
134 | 127 |
135 } // namespace client | 128 } // namespace client |
136 } // namespace blimp | 129 } // namespace blimp |
OLD | NEW |