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 #ifndef BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ | 5 #ifndef BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ |
| 6 #define BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ | 6 #define BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ |
| 7 | 7 |
| 8 #include "blimp/client/core/contents/blimp_contents_impl.h" | 8 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 9 | 9 |
| 10 namespace blimp { | 10 namespace blimp { |
| 11 namespace client { | 11 namespace client { |
| 12 | 12 |
| 13 class TabControlFeature; | |
| 14 | |
| 13 // BlimpContentsManager does the real work of creating BlimpContentsImpl, and | 15 // BlimpContentsManager does the real work of creating BlimpContentsImpl, and |
| 14 // then passes the ownership to the caller. It also owns the observers to | 16 // then passes the ownership to the caller. It also owns the observers to |
| 15 // monitor the life time of the contents it creates. | 17 // monitor the life time of the contents it creates. |
| 16 class BlimpContentsManager { | 18 class BlimpContentsManager { |
| 17 public: | 19 public: |
| 18 BlimpContentsManager(); | 20 explicit BlimpContentsManager(TabControlFeature* tab_control_feature); |
| 19 ~BlimpContentsManager(); | 21 ~BlimpContentsManager(); |
| 20 | 22 |
| 23 // Create a new BlimpContentsImpl, owns it, and create a tab for it. | |
|
David Trainor- moved to gerrit
2016/08/19 20:55:05
This comment is a bit confusing. This class doesn
Menglin
2016/08/19 21:33:02
Done.
| |
| 21 std::unique_ptr<BlimpContentsImpl> CreateBlimpContents(); | 24 std::unique_ptr<BlimpContentsImpl> CreateBlimpContents(); |
| 22 | 25 |
| 23 // The caller can query the contents through its id. | 26 // The caller can query the contents through its id. |
| 24 BlimpContentsImpl* GetBlimpContents(int id); | 27 BlimpContentsImpl* GetBlimpContents(int id); |
| 25 | 28 |
| 26 private: | 29 private: |
| 27 class BlimpContentsDeletionObserver; | 30 class BlimpContentsDeletionObserver; |
| 28 friend class BlimpContentsDeletionObserver; | 31 friend class BlimpContentsDeletionObserver; |
| 29 | 32 |
| 30 // When creating the BlimpContentsImpl, an id is created for the content. | 33 // When creating the BlimpContentsImpl, an id is created for the content. |
| 31 int CreateBlimpContentsId(); | 34 int CreateBlimpContentsId(); |
| 32 | 35 |
| 33 // When a BlimpContentsImpl is destroyed, its observer is able to retrieve the | 36 // When a BlimpContentsImpl is destroyed, its observer will pass the contents |
| 34 // id, and use this to destroy the observer entry from the observer_map_. | 37 // pointer to the manager. The contents pointer is used to retrieve its id, |
| 38 // which in turn is used to destroy the observer entry from the observer_map_ | |
| 39 // and close the tab. | |
| 40 void OnContentsDestroyed(BlimpContents* contents); | |
| 41 | |
| 42 // Destroy the observer entry from the observer_map_ when a BlimpContentsImpl | |
| 43 // is destroyed. | |
| 35 void EraseObserverFromMap(int id); | 44 void EraseObserverFromMap(int id); |
| 36 base::WeakPtr<BlimpContentsManager> GetWeakPtr(); | 45 base::WeakPtr<BlimpContentsManager> GetWeakPtr(); |
| 37 | 46 |
| 38 // BlimpContentsManager owns the BlimpContentsDeletionObserver for the | 47 // BlimpContentsManager owns the BlimpContentsDeletionObserver for the |
| 39 // contents it creates, with the content id being the key to help manage the | 48 // contents it creates, with the content id being the key to help manage the |
| 40 // lifetime of the observers. | 49 // lifetime of the observers. |
| 41 std::map<int, std::unique_ptr<BlimpContentsDeletionObserver>> observer_map_; | 50 std::map<int, std::unique_ptr<BlimpContentsDeletionObserver>> observer_map_; |
| 42 | 51 |
| 52 TabControlFeature* tab_control_feature_ = nullptr; | |
| 53 | |
| 43 base::WeakPtrFactory<BlimpContentsManager> weak_ptr_factory_; | 54 base::WeakPtrFactory<BlimpContentsManager> weak_ptr_factory_; |
| 44 | 55 |
| 45 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManager); | 56 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManager); |
| 46 }; | 57 }; |
| 47 | 58 |
| 48 } // namespace client | 59 } // namespace client |
| 49 } // namespace blimp | 60 } // namespace blimp |
| 50 | 61 |
| 51 #endif // BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ | 62 #endif // BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ |
| OLD | NEW |