| 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 #ifndef BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ | |
| 6 #define BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "blimp/client/core/contents/blimp_contents_impl.h" | |
| 13 #include "ui/gfx/native_widget_types.h" | |
| 14 | |
| 15 namespace blimp { | |
| 16 namespace client { | |
| 17 | |
| 18 class BlimpCompositorDependencies; | |
| 19 class BlimpContents; | |
| 20 class BlimpContentsImpl; | |
| 21 class ImeFeature; | |
| 22 class NavigationFeature; | |
| 23 class RenderWidgetFeature; | |
| 24 class TabControlFeature; | |
| 25 | |
| 26 // BlimpContentsManager does the real work of creating BlimpContentsImpl, and | |
| 27 // then passes the ownership to the caller. It also owns the observers to | |
| 28 // monitor the life time of the contents it creates. | |
| 29 class BlimpContentsManager { | |
| 30 public: | |
| 31 explicit BlimpContentsManager( | |
| 32 BlimpCompositorDependencies* blimp_compositor_dependencies, | |
| 33 ImeFeature* ime_feature, | |
| 34 NavigationFeature* nav_feature, | |
| 35 RenderWidgetFeature* render_widget_feature, | |
| 36 TabControlFeature* tab_control_feature); | |
| 37 ~BlimpContentsManager(); | |
| 38 | |
| 39 // Builds a BlimpContentsImpl and notifies the engine. | |
| 40 // TODO(mlliu): Currently we want to have a single BlimpContents. If there is | |
| 41 // an existing contents, return nullptr (http://crbug.com/642558). | |
| 42 std::unique_ptr<BlimpContentsImpl> CreateBlimpContents( | |
| 43 gfx::NativeWindow window); | |
| 44 | |
| 45 // The caller can query the contents through its id. | |
| 46 BlimpContentsImpl* GetBlimpContents(int id); | |
| 47 | |
| 48 // Returns a vector of the currently active BlimpContentsImpls. There is no | |
| 49 // guarantee for the lifetime of these pointers after this stack frame. | |
| 50 std::vector<BlimpContentsImpl*> GetAllActiveBlimpContents(); | |
| 51 | |
| 52 private: | |
| 53 class BlimpContentsDeletionObserver; | |
| 54 friend class BlimpContentsDeletionObserver; | |
| 55 | |
| 56 // When creating the BlimpContentsImpl, an id is created for the content. | |
| 57 int CreateBlimpContentsId(); | |
| 58 | |
| 59 // When a BlimpContentsImpl is destroyed, its observer will pass the contents | |
| 60 // pointer to the manager. The contents pointer is used to retrieve its id, | |
| 61 // which in turn is used to destroy the observer entry from the observer_map_ | |
| 62 // and close the tab. | |
| 63 void OnContentsDestroyed(BlimpContents* contents); | |
| 64 | |
| 65 // Destroy the observer entry from the observer_map_ when a BlimpContentsImpl | |
| 66 // is destroyed. | |
| 67 void EraseObserverFromMap(int id); | |
| 68 base::WeakPtr<BlimpContentsManager> GetWeakPtr(); | |
| 69 | |
| 70 // The ID to use whenever a new BlimpContentsImpl is created. Incremented | |
| 71 // after each use. | |
| 72 int next_blimp_contents_id_ = 0; | |
| 73 | |
| 74 // BlimpContentsManager owns the BlimpContentsDeletionObserver for the | |
| 75 // contents it creates, with the content id being the key to help manage the | |
| 76 // lifetime of the observers. | |
| 77 std::map<int, std::unique_ptr<BlimpContentsDeletionObserver>> observer_map_; | |
| 78 | |
| 79 BlimpCompositorDependencies* blimp_compositor_dependencies_; | |
| 80 ImeFeature* ime_feature_; | |
| 81 NavigationFeature* navigation_feature_; | |
| 82 RenderWidgetFeature* render_widget_feature_; | |
| 83 TabControlFeature* tab_control_feature_; | |
| 84 | |
| 85 // TODO(mlliu): Currently we want to have a single BlimpContents. Remove this | |
| 86 // when it supports multiple tabs (http://crbug.com/642558). | |
| 87 bool tab_exists_ = false; | |
| 88 | |
| 89 base::WeakPtrFactory<BlimpContentsManager> weak_ptr_factory_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(BlimpContentsManager); | |
| 92 }; | |
| 93 | |
| 94 } // namespace client | |
| 95 } // namespace blimp | |
| 96 | |
| 97 #endif // BLIMP_CLIENT_CORE_CONTENTS_BLIMP_CONTENTS_MANAGER_H_ | |
| OLD | NEW |