Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3611)

Side by Side Diff: chrome/browser/media/router/media_router_dialog_controller.h

Issue 1243173003: [MediaRouter] Moved the code useful for Android to MediaRouterDialogController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@build-media-router-android
Patch Set: Fixed the unit test Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread_checker.h"
9 #include "chrome/browser/media/router/create_presentation_session_request.h" 11 #include "chrome/browser/media/router/create_presentation_session_request.h"
12 #include "content/public/browser/web_contents_observer.h"
10 13
11 namespace content { 14 namespace content {
12 class WebContents; 15 class WebContents;
13 } // namespace content 16 } // namespace content
14 17
15 namespace media_router { 18 namespace media_router {
16 19
17 // An implementation of this interface is tied to a WebContents known as the 20 // An abstract base class for Media Router dialog controllers. Tied to a
18 // initiator, and is lazily created when a Media Router dialog needs to be 21 // WebContents known as the |initiator|, and is lazily created when a Media
19 // shown. The MediaRouterDialogController allows creating, querying, and 22 // Router dialog needs to be shown. The MediaRouterDialogController allows
20 // removing a Media Router dialog modal to the initiator WebContents. 23 // showing and closing a Media Router dialog modal to the initiator WebContents.
21 // This class is not thread safe and must be called on the UI thread. 24 // This class is not thread safe and must be called on the UI thread.
22 class MediaRouterDialogController { 25 class MediaRouterDialogController {
23 public: 26 public:
24 virtual ~MediaRouterDialogController() = default; 27 virtual ~MediaRouterDialogController();
25 28
26 // Gets a reference to the MediaRouterDialogController associated with 29 // Gets a reference to the MediaRouterDialogController associated with
27 // |web_contents|, creating one if it does not exist. The returned pointer is 30 // |web_contents|, creating one if it does not exist. The returned pointer is
28 // guaranteed to be non-null. 31 // guaranteed to be non-null.
29 static MediaRouterDialogController* GetOrCreateForWebContents( 32 static MediaRouterDialogController* GetOrCreateForWebContents(
30 content::WebContents* web_contents); 33 content::WebContents* web_contents);
31 34
32 // Creates a Media Router modal dialog using the initiator and parameters 35 // Shows the media router dialog modal to |initiator_| and the parameters
33 // specified in |request|. If the dialog already exists, brings the dialog 36 // specified in |request|.
34 // to the front, but does not change the dialog with |request|. 37 // Creates the dialog if it did not exist prior to this call, returns true.
35 // Returns WebContents for the media router dialog if a dialog was created. 38 // If the dialog already exists, brings it to the front but doesn't change the
36 // Otherwise returns false and |request| is deleted. 39 // dialog with |request|, returns false and |request| is deleted.
37 virtual bool ShowMediaRouterDialogForPresentation( 40 bool ShowMediaRouterDialogForPresentation(
38 scoped_ptr<CreatePresentationSessionRequest> request) = 0; 41 scoped_ptr<CreatePresentationSessionRequest> request);
42
43 // Shows the media router dialog modal to |initiator_|.
44 // Creates the dialog if it did not exist prior to this call, returns true.
45 // If the dialog already exists, brings it to the front, returns false.
46 virtual bool ShowMediaRouterDialog();
47
48 // Hides the media router dialog.
49 // It is a no-op to call this function if there is currently no dialog.
50 void HideMediaRouterDialog();
51
52 protected:
53 // Use MediaRouterDialogController::GetOrCreateForWebContents() to create an
54 // instance.
55 explicit MediaRouterDialogController(content::WebContents* initiator);
56
57 void ActivateInitiatorWebContents();
58
59 scoped_ptr<CreatePresentationSessionRequest> PassPresentationRequest();
60
61 content::WebContents* initiator() const { return initiator_; }
62
63 // Resets the state of the controller. Must be called from the overrides.
64 virtual void Reset();
65 // Creates a new media router dialog modal to |initiator_|.
66 virtual void CreateMediaRouterDialog() = 0;
67 // Closes the media router dialog if it exists.
68 virtual void CloseMediaRouterDialog() = 0;
69 // Indicates if the media router dialog already exists.
70 virtual bool IsShowingMediaRouterDialog() const = 0;
71
72 base::ThreadChecker thread_checker_;
73
74 private:
75 class InitiatorWebContentsObserver;
76
77 // An observer for the |initiator_| that closes the dialog when |initiator_|
78 // is destroyed or navigated.
79 scoped_ptr<InitiatorWebContentsObserver> initiator_observer_;
80 content::WebContents* const initiator_;
81
82 // Data for dialogs created at the request of the Presentation API.
83 // Passed from the caller via ShowMediaRouterDialogForPresentation to the
84 // dialog when it is initialized.
85 scoped_ptr<CreatePresentationSessionRequest> presentation_request_;
86
87 DISALLOW_COPY_AND_ASSIGN(MediaRouterDialogController);
39 }; 88 };
40 89
41 } // namespace media_router 90 } // namespace media_router
42 91
43 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_ 92 #endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_ROUTER_DIALOG_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698