ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / content / public / browser / presentation_service_delegate.h
blob01b0fda17495d30e7f1866760f8747beacd88ee3
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/presentation_session.h"
15 #include "content/public/browser/presentation_session_message.h"
17 namespace content {
19 class PresentationScreenAvailabilityListener;
21 using SessionStateChangedCallback =
22 base::Callback<void(const PresentationSessionInfo&,
23 PresentationSessionState)>;
25 // An interface implemented by embedders to handle presentation API calls
26 // forwarded from PresentationServiceImpl.
27 class CONTENT_EXPORT PresentationServiceDelegate {
28 public:
29 // Observer interface to listen for changes to PresentationServiceDelegate.
30 class CONTENT_EXPORT Observer {
31 public:
32 // Called when the PresentationServiceDelegate is being destroyed.
33 virtual void OnDelegateDestroyed() = 0;
35 // Called when the default presentation has been started outside of a
36 // Presentation API context (e.g., browser action). This will not be called
37 // if the session was created as a result of Presentation API's
38 // StartSession()/JoinSession().
39 virtual void OnDefaultPresentationStarted(
40 const PresentationSessionInfo& session) = 0;
42 protected:
43 virtual ~Observer() {}
46 using PresentationSessionSuccessCallback =
47 base::Callback<void(const PresentationSessionInfo&)>;
48 using PresentationSessionErrorCallback =
49 base::Callback<void(const PresentationError&)>;
50 using PresentationSessionMessageCallback = base::Callback<void(
51 scoped_ptr<ScopedVector<PresentationSessionMessage>>)>;
52 using SendMessageCallback = base::Callback<void(bool)>;
54 virtual ~PresentationServiceDelegate() {}
56 // Registers an observer associated with frame with |render_process_id|
57 // and |render_frame_id| with this class to listen for updates.
58 // This class does not own the observer.
59 // It is an error to add an observer if there is already an observer for that
60 // frame.
61 virtual void AddObserver(int render_process_id,
62 int render_frame_id,
63 Observer* observer) = 0;
65 // Unregisters the observer associated with the frame with |render_process_id|
66 // and |render_frame_id|.
67 // The observer will no longer receive updates.
68 virtual void RemoveObserver(int render_process_id, int render_frame_id) = 0;
70 // Registers |listener| to continuously listen for
71 // availability updates for a presentation URL, originated from the frame
72 // given by |render_process_id| and |render_frame_id|.
73 // This class does not own |listener|.
74 // Returns true on success.
75 // This call will return false if a listener with the same presentation URL
76 // from the same frame is already registered.
77 virtual bool AddScreenAvailabilityListener(
78 int render_process_id,
79 int render_frame_id,
80 PresentationScreenAvailabilityListener* listener) = 0;
82 // Unregisters |listener| originated from the frame given by
83 // |render_process_id| and |render_frame_id| from this class. The listener
84 // will no longer receive availability updates.
85 virtual void RemoveScreenAvailabilityListener(
86 int render_process_id,
87 int render_frame_id,
88 PresentationScreenAvailabilityListener* listener) = 0;
90 // Resets the presentation state for the frame given by |render_process_id|
91 // and |render_frame_id|.
92 // This unregisters all listeners associated with the given frame, and clears
93 // the default presentation URL and ID set for the frame.
94 virtual void Reset(
95 int render_process_id,
96 int render_frame_id) = 0;
98 // Sets the default presentation URL for frame given by |render_process_id|
99 // and |render_frame_id|.
100 // If |default_presentation_url| is empty, the default presentation URL will
101 // be cleared.
102 virtual void SetDefaultPresentationUrl(
103 int render_process_id,
104 int render_frame_id,
105 const std::string& default_presentation_url) = 0;
107 // Starts a new presentation session. The presentation id of the session will
108 // be the default presentation ID if any or a generated one otherwise.
109 // Typically, the embedder will allow the user to select a screen to show
110 // |presentation_url|.
111 // |render_process_id|, |render_frame_id|: ID of originating frame.
112 // |presentation_url|: URL of the presentation.
113 // |success_cb|: Invoked with session info, if presentation session started
114 // successfully.
115 // |error_cb|: Invoked with error reason, if presentation session did not
116 // start.
117 virtual void StartSession(
118 int render_process_id,
119 int render_frame_id,
120 const std::string& presentation_url,
121 const PresentationSessionSuccessCallback& success_cb,
122 const PresentationSessionErrorCallback& error_cb) = 0;
124 // Joins an existing presentation session. Unlike StartSession(), this
125 // does not bring a screen list UI.
126 // |render_process_id|, |render_frame_id|: ID for originating frame.
127 // |presentation_url|: URL of the presentation.
128 // |presentation_id|: The ID of the presentation to join.
129 // |success_cb|: Invoked with session info, if presentation session joined
130 // successfully.
131 // |error_cb|: Invoked with error reason, if joining failed.
132 virtual void JoinSession(
133 int render_process_id,
134 int render_frame_id,
135 const std::string& presentation_url,
136 const std::string& presentation_id,
137 const PresentationSessionSuccessCallback& success_cb,
138 const PresentationSessionErrorCallback& error_cb) = 0;
140 // Close an existing presentation session.
141 // |render_process_id|, |render_frame_id|: ID for originating frame.
142 // |presentation_id|: The ID of the presentation to close.
143 virtual void CloseSession(int render_process_id,
144 int render_frame_id,
145 const std::string& presentation_id) = 0;
147 // Gets the next batch of messages from all presentation sessions in the frame
148 // |render_process_id|, |render_frame_id|: ID for originating frame.
149 // |message_cb|: Invoked with a non-empty list of messages.
150 virtual void ListenForSessionMessages(
151 int render_process_id,
152 int render_frame_id,
153 const PresentationSessionMessageCallback& message_cb) = 0;
155 // Sends a message (string or binary data) to a presentation session.
156 // |render_process_id|, |render_frame_id|: ID of originating frame.
157 // |message_request|: Contains Presentation URL, ID and message to be sent
158 // and delegate is responsible for deallocating the message_request.
159 // |send_message_cb|: Invoked after handling the send message request.
160 virtual void SendMessage(
161 int render_process_id,
162 int render_frame_id,
163 scoped_ptr<PresentationSessionMessage> message_request,
164 const SendMessageCallback& send_message_cb) = 0;
166 // Continuously listen for presentation session state changes for a frame.
167 // |render_process_id|, |render_frame_id|: ID of frame.
168 // |state_changed_cb|: Invoked with the session and its new state whenever
169 // there is a state change.
170 virtual void ListenForSessionStateChange(
171 int render_process_id,
172 int render_frame_id,
173 const SessionStateChangedCallback& state_changed_cb) = 0;
176 } // namespace content
178 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_