summaryrefslogtreecommitdiffstats
path: root/chrome/browser/media/router/presentation_session_messages_observer.h
blob: 62c95127fb058f23f69c66283cc9cd6b4842550c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SESSION_MESSAGES_OBSERVER_H_
#define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SESSION_MESSAGES_OBSERVER_H_

#include "base/macros.h"
#include "base/memory/scoped_vector.h"
#include "chrome/browser/media/router/media_route.h"
#include "content/public/browser/presentation_service_delegate.h"
#include "content/public/browser/presentation_session.h"

namespace media_router {

class MediaRouter;

// Observes messages originating from the MediaSink connected to a MediaRoute
// that represents a presentation.
// Messages are received from MediaRouter via |OnMessagesReceived|, where
// |message_cb_| will be invoked.
class PresentationSessionMessagesObserver {
 public:
  // |message_cb|: The callback to invoke whenever messages are received.
  // |route_id|: ID of MediaRoute to listen for messages.
  PresentationSessionMessagesObserver(
      const content::PresentationSessionMessageCallback& message_cb,
      const MediaRoute::Id& route_id,
      MediaRouter* router);
  ~PresentationSessionMessagesObserver();

  // Invoked by |router_| whenever messages are received. Invokes |message_cb_|
  // with |messages|.
  // |messages| is guaranteed to be non-empty.
  // If |pass_ownership| is true, then this observer may reuse buffers from the
  // contents of |messages| without copying.
  void OnMessagesReceived(
      const ScopedVector<content::PresentationSessionMessage>& messages,
      bool pass_ownership);

  const MediaRoute::Id& route_id() const { return route_id_; }

 private:
  content::PresentationSessionMessageCallback message_cb_;
  const MediaRoute::Id route_id_;
  MediaRouter* const router_;

  DISALLOW_COPY_AND_ASSIGN(PresentationSessionMessagesObserver);
};

}  // namespace media_router

#endif  // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SESSION_MESSAGES_OBSERVER_H_