[tracing] Add browser-side discardable memory reporting
[chromium-blink-merge.git] / content / renderer / presentation / presentation_dispatcher.h
blob4642a644ba19899a626ce3a0db05f8e070d277cf
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_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/linked_ptr.h"
10 #include "content/common/content_export.h"
11 #include "content/common/presentation/presentation_service.mojom.h"
12 #include "content/public/renderer/render_frame_observer.h"
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentationClient.h"
15 namespace blink {
16 class WebString;
17 } // namespace blink
19 namespace content {
21 // PresentationDispatcher is a delegate for Presentation API messages used by
22 // Blink. It forwards the calls to the Mojo PresentationService.
23 class CONTENT_EXPORT PresentationDispatcher
24 : public RenderFrameObserver,
25 public NON_EXPORTED_BASE(blink::WebPresentationClient),
26 public NON_EXPORTED_BASE(presentation::PresentationServiceClient) {
27 public:
28 explicit PresentationDispatcher(RenderFrame* render_frame);
29 ~PresentationDispatcher() override;
31 private:
32 // WebPresentationClient implementation.
33 virtual void setController(
34 blink::WebPresentationController* controller);
35 virtual void updateAvailableChangeWatched(bool watched);
36 virtual void startSession(
37 const blink::WebString& presentationUrl,
38 const blink::WebString& presentationId,
39 blink::WebPresentationSessionClientCallbacks* callback);
40 virtual void joinSession(
41 const blink::WebString& presentationUrl,
42 const blink::WebString& presentationId,
43 blink::WebPresentationSessionClientCallbacks* callback);
44 virtual void sendString(
45 const blink::WebString& presentationUrl,
46 const blink::WebString& presentationId,
47 const blink::WebString& message);
48 virtual void sendArrayBuffer(
49 const blink::WebString& presentationUrl,
50 const blink::WebString& presentationId,
51 const uint8* data,
52 size_t length);
53 virtual void sendBlobData(
54 const blink::WebString& presentationUrl,
55 const blink::WebString& presentationId,
56 const uint8* data,
57 size_t length);
58 virtual void closeSession(
59 const blink::WebString& presentationUrl,
60 const blink::WebString& presentationId);
62 // RenderFrameObserver implementation.
63 void DidChangeDefaultPresentation() override;
64 void DidCommitProvisionalLoad(
65 bool is_new_navigation,
66 bool is_same_page_navigation) override;
68 // presentation::PresentationServiceClient
69 void OnScreenAvailabilityUpdated(bool available) override;
71 void OnSessionCreated(
72 blink::WebPresentationSessionClientCallbacks* callback,
73 presentation::PresentationSessionInfoPtr session_info,
74 presentation::PresentationErrorPtr error);
75 void OnDefaultSessionStarted(
76 presentation::PresentationSessionInfoPtr session_info);
77 void OnSessionStateChange(
78 presentation::PresentationSessionInfoPtr session_info,
79 presentation::PresentationSessionState session_state);
80 void OnSessionMessagesReceived(
81 mojo::Array<presentation::SessionMessagePtr> messages);
82 void DoSendMessage(const presentation::SessionMessage& session_message);
83 void HandleSendMessageRequests(bool success);
85 void ConnectToPresentationServiceIfNeeded();
87 // Used as a weak reference. Can be null since lifetime is bound to the frame.
88 blink::WebPresentationController* controller_;
89 presentation::PresentationServicePtr presentation_service_;
90 mojo::Binding<presentation::PresentationServiceClient> binding_;
92 // Message requests are queued here and only one message at a time is sent
93 // over mojo channel.
94 using MessageRequestQueue =
95 std::queue<linked_ptr<presentation::SessionMessage>>;
96 MessageRequestQueue message_request_queue_;
98 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher);
101 } // namespace content
103 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_