Chromium Code Reviews| 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/public/contents/blimp_contents_observer.h" | 10 #include "blimp/client/public/contents/blimp_contents_observer.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 BlimpContentsManager::BlimpContentsDeletionObserver:: | 34 BlimpContentsManager::BlimpContentsDeletionObserver:: |
| 35 BlimpContentsDeletionObserver(BlimpContentsManager* blimp_contents_manager, | 35 BlimpContentsDeletionObserver(BlimpContentsManager* blimp_contents_manager, |
| 36 BlimpContentsImpl* blimp_contents) | 36 BlimpContentsImpl* blimp_contents) |
| 37 : BlimpContentsObserver(blimp_contents), | 37 : BlimpContentsObserver(blimp_contents), |
| 38 blimp_contents_manager_(blimp_contents_manager) {} | 38 blimp_contents_manager_(blimp_contents_manager) {} |
| 39 | 39 |
| 40 void BlimpContentsManager::BlimpContentsDeletionObserver:: | 40 void BlimpContentsManager::BlimpContentsDeletionObserver:: |
| 41 OnContentsDestroyed() { | 41 OnContentsDestroyed() { |
| 42 BlimpContents* contents = blimp_contents(); | 42 BlimpContents* contents = blimp_contents(); |
|
David Trainor- moved to gerrit
2016/08/18 17:41:58
It might make sense to change this now. We don't
Menglin
2016/08/19 00:50:21
Done.
| |
| 43 int id = static_cast<BlimpContentsImpl*>(contents)->id(); | 43 int id = static_cast<BlimpContentsImpl*>(contents)->id(); |
| 44 DCHECK(base::ThreadTaskRunnerHandle::Get()); | 44 DCHECK(base::ThreadTaskRunnerHandle::Get()); |
| 45 base::ThreadTaskRunnerHandle::Get()->PostTask( | 45 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 46 FROM_HERE, base::Bind(&BlimpContentsManager::EraseObserverFromMap, | 46 FROM_HERE, base::Bind(&BlimpContentsManager::EraseObserverFromMap, |
| 47 blimp_contents_manager_->GetWeakPtr(), id)); | 47 blimp_contents_manager_->GetWeakPtr(), id)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 BlimpContentsManager::BlimpContentsManager() : weak_ptr_factory_(this) {} | 50 BlimpContentsManager::BlimpContentsManager() : weak_ptr_factory_(this) {} |
| 51 | 51 |
| 52 BlimpContentsManager::~BlimpContentsManager() {} | 52 BlimpContentsManager::~BlimpContentsManager() {} |
| 53 | 53 |
| 54 std::unique_ptr<BlimpContentsImpl> BlimpContentsManager::CreateBlimpContents() { | 54 std::unique_ptr<BlimpContentsImpl> BlimpContentsManager::CreateBlimpContents( |
|
David Trainor- moved to gerrit
2016/08/18 17:41:58
This class should also call tab_control_feature->C
Menglin
2016/08/19 00:50:21
Done.
| |
| 55 TabControlFeature* tab_control_feature) { | |
| 55 int id = CreateBlimpContentsId(); | 56 int id = CreateBlimpContentsId(); |
| 56 std::unique_ptr<BlimpContentsImpl> new_contents = | 57 std::unique_ptr<BlimpContentsImpl> new_contents = |
| 57 base::MakeUnique<BlimpContentsImpl>(id); | 58 base::MakeUnique<BlimpContentsImpl>(id, tab_control_feature); |
| 58 std::unique_ptr<BlimpContentsDeletionObserver> observer = | 59 std::unique_ptr<BlimpContentsDeletionObserver> observer = |
| 59 base::MakeUnique<BlimpContentsDeletionObserver>(this, new_contents.get()); | 60 base::MakeUnique<BlimpContentsDeletionObserver>(this, new_contents.get()); |
| 60 observer_map_.insert( | 61 observer_map_.insert( |
| 61 std::pair<int, std::unique_ptr<BlimpContentsDeletionObserver>>( | 62 std::pair<int, std::unique_ptr<BlimpContentsDeletionObserver>>( |
| 62 id, std::move(observer))); | 63 id, std::move(observer))); |
| 63 return new_contents; | 64 return new_contents; |
| 64 } | 65 } |
| 65 | 66 |
| 66 BlimpContentsImpl* BlimpContentsManager::GetBlimpContents(int id) { | 67 BlimpContentsImpl* BlimpContentsManager::GetBlimpContents(int id) { |
| 67 if (observer_map_.find(id) == observer_map_.end()) return nullptr; | 68 if (observer_map_.find(id) == observer_map_.end()) return nullptr; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 86 void BlimpContentsManager::EraseObserverFromMap(int id) { | 87 void BlimpContentsManager::EraseObserverFromMap(int id) { |
| 87 observer_map_.erase(id); | 88 observer_map_.erase(id); |
| 88 } | 89 } |
| 89 | 90 |
| 90 base::WeakPtr<BlimpContentsManager> BlimpContentsManager::GetWeakPtr() { | 91 base::WeakPtr<BlimpContentsManager> BlimpContentsManager::GetWeakPtr() { |
| 91 return weak_ptr_factory_.GetWeakPtr(); | 92 return weak_ptr_factory_.GetWeakPtr(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 } // namespace client | 95 } // namespace client |
| 95 } // namespace blimp | 96 } // namespace blimp |
| OLD | NEW |