| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL
_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL
_H_ |
| 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL
_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_IMPL
_H_ |
| 7 | 7 |
| 8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 11 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 14 | 14 |
| 15 FORWARD_DECLARE_TEST(MediaRouterActionUnitTest, IconPressedState); | 15 FORWARD_DECLARE_TEST(MediaRouterActionUnitTest, IconPressedState); |
| 16 | 16 |
| 17 class MediaRouterAction; | 17 class MediaRouterAction; |
| 18 class MediaRouterActionController; |
| 18 | 19 |
| 19 namespace media_router { | 20 namespace media_router { |
| 20 | 21 |
| 21 // A desktop implementation of MediaRouterDialogController. | 22 // A desktop implementation of MediaRouterDialogController. |
| 22 // This class is not thread safe and must be called on the UI thread. | 23 // This class is not thread safe and must be called on the UI thread. |
| 23 class MediaRouterDialogControllerImpl : | 24 class MediaRouterDialogControllerImpl : |
| 24 public content::WebContentsUserData<MediaRouterDialogControllerImpl>, | 25 public content::WebContentsUserData<MediaRouterDialogControllerImpl>, |
| 25 public MediaRouterDialogController { | 26 public MediaRouterDialogController { |
| 26 public: | 27 public: |
| 27 ~MediaRouterDialogControllerImpl() override; | 28 ~MediaRouterDialogControllerImpl() override; |
| 28 | 29 |
| 29 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( | 30 static MediaRouterDialogControllerImpl* GetOrCreateForWebContents( |
| 30 content::WebContents* web_contents); | 31 content::WebContents* web_contents); |
| 31 | 32 |
| 32 // Returns the media router dialog WebContents. | 33 // Returns the media router dialog WebContents. |
| 33 // Returns nullptr if there is no dialog. | 34 // Returns nullptr if there is no dialog. |
| 34 content::WebContents* GetMediaRouterDialog() const; | 35 content::WebContents* GetMediaRouterDialog() const; |
| 35 | 36 |
| 36 // Sets the action to notify when a dialog gets shown or hidden. | 37 // Sets the action to notify when a dialog gets shown or hidden. |
| 37 void SetMediaRouterAction(const base::WeakPtr<MediaRouterAction>& action); | 38 void SetMediaRouterAction(const base::WeakPtr<MediaRouterAction>& action); |
| 38 | 39 |
| 39 // MediaRouterDialogController: | 40 // MediaRouterDialogController: |
| 40 bool IsShowingMediaRouterDialog() const override; | 41 bool IsShowingMediaRouterDialog() const override; |
| 41 | 42 |
| 42 void UpdateMaxDialogSize(); | 43 void UpdateMaxDialogSize(); |
| 43 | 44 |
| 45 MediaRouterAction* action() { return action_.get(); } |
| 46 |
| 44 private: | 47 private: |
| 45 class DialogWebContentsObserver; | 48 class DialogWebContentsObserver; |
| 46 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; | 49 friend class content::WebContentsUserData<MediaRouterDialogControllerImpl>; |
| 47 FRIEND_TEST_ALL_PREFIXES(::MediaRouterActionUnitTest, IconPressedState); | 50 FRIEND_TEST_ALL_PREFIXES(::MediaRouterActionUnitTest, IconPressedState); |
| 48 | 51 |
| 49 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an | 52 // Use MediaRouterDialogControllerImpl::CreateForWebContents() to create an |
| 50 // instance. | 53 // instance. |
| 51 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); | 54 explicit MediaRouterDialogControllerImpl(content::WebContents* web_contents); |
| 52 | 55 |
| 53 // MediaRouterDialogController: | 56 // MediaRouterDialogController: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 68 | 71 |
| 69 // |action_| refers to the MediaRouterAction on the toolbar, rather than | 72 // |action_| refers to the MediaRouterAction on the toolbar, rather than |
| 70 // overflow menu. A MediaRouterAction is always created for the toolbar | 73 // overflow menu. A MediaRouterAction is always created for the toolbar |
| 71 // first. Any subsequent creations for the overflow menu will not be set as | 74 // first. Any subsequent creations for the overflow menu will not be set as |
| 72 // |action_|. | 75 // |action_|. |
| 73 // The lifetime of |action_| is dependent on the creation and destruction of | 76 // The lifetime of |action_| is dependent on the creation and destruction of |
| 74 // a browser window. The overflow menu's MediaRouterAction is only created | 77 // a browser window. The overflow menu's MediaRouterAction is only created |
| 75 // when the overflow menu is opened and destroyed when the menu is closed. | 78 // when the overflow menu is opened and destroyed when the menu is closed. |
| 76 base::WeakPtr<MediaRouterAction> action_; | 79 base::WeakPtr<MediaRouterAction> action_; |
| 77 | 80 |
| 81 // |action_controller_| is responsible for showing and hiding the toolbar |
| 82 // action. It's owned by MediaRouterUIService, which outlives |this|. |
| 83 MediaRouterActionController* action_controller_; |
| 84 |
| 78 base::WeakPtrFactory<MediaRouterDialogControllerImpl> weak_ptr_factory_; | 85 base::WeakPtrFactory<MediaRouterDialogControllerImpl> weak_ptr_factory_; |
| 79 | 86 |
| 80 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); | 87 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogControllerImpl); |
| 81 }; | 88 }; |
| 82 | 89 |
| 83 } // namespace media_router | 90 } // namespace media_router |
| 84 | 91 |
| 85 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I
MPL_H_ | 92 #endif // CHROME_BROWSER_UI_WEBUI_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_I
MPL_H_ |
| OLD | NEW |