File: cast_dialog_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (82 lines) | stat: -rw-r--r-- 3,500 bytes parent folder | download | duplicates (6)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_MEDIA_ROUTER_CAST_DIALOG_CONTROLLER_H_
#define CHROME_BROWSER_UI_MEDIA_ROUTER_CAST_DIALOG_CONTROLLER_H_

#include "base/functional/callback_forward.h"
#include "chrome/browser/ui/media_router/media_cast_mode.h"
#include "components/media_router/common/issue.h"
#include "components/media_router/common/media_route.h"
#include "components/media_router/common/media_sink.h"

namespace media_router {

class CastDialogModel;
class MediaRouteStarter;

// Controller component of the Cast dialog. Responsible for handling user input,
// updating the CastDialogModel, and notifying CastDialogView of updates.
class CastDialogController {
 public:
  class Observer {
   public:
    virtual ~Observer() = default;

    virtual void OnModelUpdated(const CastDialogModel& model) {}

    virtual void OnCastingStarted() {}

    // Notifies observers that the observed object is being destroyed. Observers
    // MUST NOT try to destroy the observed object in response - to manage the
    // lifetime of a CastDialogController, use RegisterDestructor() below.
    virtual void OnControllerDestroying() {}
  };

  virtual ~CastDialogController() = default;

  // |observer| is notified upon registration, and whenever there is a change to
  // the dialog model.
  virtual void AddObserver(Observer* observer) = 0;
  virtual void RemoveObserver(Observer* observer) = 0;

  // Starts Casting to the given sink. No-op if |sink_id| is invalid or the sink
  // doesn't support |cast_mode|.
  virtual void StartCasting(const MediaSink::Id& sink_id,
                            MediaCastMode cast_mode) = 0;

  // Stops casting by terminating the route given by |route_id|. No-op if the ID
  // is invalid.
  virtual void StopCasting(const MediaRoute::Id& route_id) = 0;

  // Removes the specified issue. No-op if the ID is invalid.
  virtual void ClearIssue(const Issue::Id& issue_id) = 0;

  // Freezes and unfreezes the route given by |route_id|. No-op if the ID is
  // invalid, if the route is not currently mirroring, or if the mirroring route
  // does not support freezing.
  virtual void FreezeRoute(const MediaRoute::Id& route_id) = 0;
  virtual void UnfreezeRoute(const MediaRoute::Id& route_id) = 0;

  // Returns the MediaRouteStarter that this dialog was going to use to create
  // the mirroring or presentation routes. The dialog box is relinquishing
  // ownership, and so will be unable to start casting after this point. It's
  // intended that this API should only be used to transfer ownership to some
  // new component that will want to start casting on this dialog box's behalf.
  virtual std::unique_ptr<MediaRouteStarter> TakeMediaRouteStarter() = 0;

  // Registers a callback for when the CastDialogController has given up
  // ownership of its MediaRouteStarter and is no longer safe to use. The
  // provided closure must destroy |this| or otherwise ensure it is never used
  // again. This method can only be called once.
  //
  // TODO(crbug.com/40253570): It's awkward that CastDialogController has
  // a state where it exists but is unsafe to use, and doubly awkward that we
  // have to paper over that with this callback. Can that be fixed?
  virtual void RegisterDestructor(base::OnceClosure destructor) = 0;
};

}  // namespace media_router

#endif  // CHROME_BROWSER_UI_MEDIA_ROUTER_CAST_DIALOG_CONTROLLER_H_