Fix compile breakage from r336003.
[chromium-blink-merge.git] / content / public / browser / presentation_service_delegate.h
blob0d5b35bc2329e186d2209f3ee3d2b96855606310
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 // An interface implemented by embedders to handle presentation API calls
22 // forwarded from PresentationServiceImpl.
23 class CONTENT_EXPORT PresentationServiceDelegate {
24 public:
25 // Observer interface to listen for changes to PresentationServiceDelegate.
26 class CONTENT_EXPORT Observer {
27 public:
28 // Called when the PresentationServiceDelegate is being destroyed.
29 virtual void OnDelegateDestroyed() = 0;
31 // Called when the default presentation has been started outside of a
32 // Presentation API context (e.g., browser action). This will not be called
33 // if the session was created as a result of Presentation API's
34 // StartSession()/JoinSession().
35 virtual void OnDefaultPresentationStarted(
36 const PresentationSessionInfo& session) = 0;
38 protected:
39 virtual ~Observer() {}
42 using PresentationSessionSuccessCallback =
43 base::Callback<void(const PresentationSessionInfo&)>;
44 using PresentationSessionErrorCallback =
45 base::Callback<void(const PresentationError&)>;
46 using PresentationSessionMessageCallback = base::Callback<void(
47 scoped_ptr<ScopedVector<PresentationSessionMessage>>)>;
48 using SendMessageCallback = base::Closure;
50 virtual ~PresentationServiceDelegate() {}
52 // Registers an observer associated with frame with |render_process_id|
53 // and |render_frame_id| with this class to listen for updates.
54 // This class does not own the observer.
55 // It is an error to add an observer if there is already an observer for that
56 // frame.
57 virtual void AddObserver(int render_process_id,
58 int render_frame_id,
59 Observer* observer) = 0;
61 // Unregisters the observer associated with the frame with |render_process_id|
62 // and |render_frame_id|.
63 // The observer will no longer receive updates.
64 virtual void RemoveObserver(int render_process_id, int render_frame_id) = 0;
66 // Registers |listener| to continuously listen for
67 // availability updates for a presentation URL, originated from the frame
68 // given by |render_process_id| and |render_frame_id|.
69 // This class does not own |listener|.
70 // Returns true on success.
71 // This call will return false if a listener with the same presentation URL
72 // from the same frame is already registered.
73 virtual bool AddScreenAvailabilityListener(
74 int render_process_id,
75 int render_frame_id,
76 PresentationScreenAvailabilityListener* listener) = 0;
78 // Unregisters |listener| originated from the frame given by
79 // |render_process_id| and |render_frame_id| from this class. The listener
80 // will no longer receive availability updates.
81 virtual void RemoveScreenAvailabilityListener(
82 int render_process_id,
83 int render_frame_id,
84 PresentationScreenAvailabilityListener* listener) = 0;
86 // Resets the presentation state for the frame given by |render_process_id|
87 // and |render_frame_id|.
88 // This unregisters all listeners associated with the given frame, and clears
89 // the default presentation URL and ID set for the frame.
90 virtual void Reset(
91 int render_process_id,
92 int render_frame_id) = 0;
94 // Sets the default presentation URL and ID for frame given by
95 // |render_process_id| and |render_frame_id|.
96 // If |default_presentation_url| is empty, the default presentation URL will
97 // be cleared.
98 virtual void SetDefaultPresentationUrl(
99 int render_process_id,
100 int render_frame_id,
101 const std::string& default_presentation_url,
102 const std::string& default_presentation_id) = 0;
104 // Starts a new presentation session.
105 // Typically, the embedder will allow the user to select a screen to show
106 // |presentation_url|.
107 // |render_process_id|, |render_frame_id|: ID of originating frame.
108 // |presentation_url|: URL of the presentation.
109 // |presentation_id|: The caller may provide an non-empty string to be used
110 // as the ID of the presentation. If empty, the default presentation ID
111 // will be used. If both are empty, the embedder will automatically generate
112 // one.
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 std::string& presentation_id,
122 const PresentationSessionSuccessCallback& success_cb,
123 const PresentationSessionErrorCallback& error_cb) = 0;
125 // Joins an existing presentation session. Unlike StartSession(), this
126 // does not bring a screen list UI.
127 // |render_process_id|, |render_frame_id|: ID for originating frame.
128 // |presentation_url|: URL of the presentation.
129 // |presentation_id|: The ID of the presentation to join.
130 // |success_cb|: Invoked with session info, if presentation session joined
131 // successfully.
132 // |error_cb|: Invoked with error reason, if joining failed.
133 virtual void JoinSession(
134 int render_process_id,
135 int render_frame_id,
136 const std::string& presentation_url,
137 const std::string& presentation_id,
138 const PresentationSessionSuccessCallback& success_cb,
139 const PresentationSessionErrorCallback& error_cb) = 0;
141 // Close an existing presentation session.
142 // |render_process_id|, |render_frame_id|: ID for originating frame.
143 // |presentation_id|: The ID of the presentation to close.
144 virtual void CloseSession(int render_process_id,
145 int render_frame_id,
146 const std::string& presentation_id) = 0;
148 // Gets the next batch of messages from all presentation sessions in the frame
149 // |render_process_id|, |render_frame_id|: ID for originating frame.
150 // |message_cb|: Invoked with a non-empty list of messages.
151 virtual void ListenForSessionMessages(
152 int render_process_id,
153 int render_frame_id,
154 const PresentationSessionMessageCallback& message_cb) = 0;
156 // Sends a message (string or binary data) to a presentation session.
157 // |render_process_id|, |render_frame_id|: ID of originating frame.
158 // |message_request|: Contains Presentation URL, ID and message to be sent
159 // and delegate is responsible for deallocating the message_request.
160 // |send_message_cb|: Invoked after handling the send message request.
161 virtual void SendMessage(
162 int render_process_id,
163 int render_frame_id,
164 scoped_ptr<PresentationSessionMessage> message_request,
165 const SendMessageCallback& send_message_cb) = 0;
168 } // namespace content
170 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_