File: resizing_host_observer.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 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 (109 lines) | stat: -rw-r--r-- 4,021 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_HOST_RESIZING_HOST_OBSERVER_H_
#define REMOTING_HOST_RESIZING_HOST_OBSERVER_H_

#include <stddef.h>

#include <map>
#include <memory>
#include <set>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "remoting/host/base/screen_controls.h"
#include "remoting/host/base/screen_resolution.h"

namespace base {
class TickClock;
}

namespace remoting {

class DesktopDisplayInfo;
class DesktopDisplayInfoMonitor;
class DesktopResizer;

// TODO(alexeypa): Rename this class to reflect that it is not
// HostStatusObserver any more.

// Uses the specified DesktopResizer to match host desktop size to the client
// view size as closely as is possible. When the connection closes, restores
// the original desktop size if restore is true.
class ResizingHostObserver : public ScreenControls {
 public:
  explicit ResizingHostObserver(std::unique_ptr<DesktopResizer> desktop_resizer,
                                bool restore);

  ResizingHostObserver(const ResizingHostObserver&) = delete;
  ResizingHostObserver& operator=(const ResizingHostObserver&) = delete;

  ~ResizingHostObserver() override;

  void RegisterForDisplayChanges(DesktopDisplayInfoMonitor& monitor);

  // ScreenControls interface.
  void SetScreenResolution(const ScreenResolution& resolution,
                           std::optional<webrtc::ScreenId> screen_id) override;
  void SetVideoLayout(const protocol::VideoLayout& video_layout) override;

  // Allows tests to provide display-info updates.
  void SetDisplayInfoForTesting(const DesktopDisplayInfo& display_info);

  // Provide a replacement for base::TimeTicks::Now so that this class can be
  // unit-tested in a timely manner. This function will be called exactly
  // once for each call to SetScreenResolution.
  void SetClockForTesting(const base::TickClock* clock);

 private:
  // Restores the given monitor's original resolution, and removes it from the
  // stored list.
  void RestoreScreenResolution(webrtc::ScreenId screen_id);

  // Restores every monitor's resolution.
  void RestoreAllScreenResolutions();

  // Stores the original resolution for the monitor |screen_id|. This does not
  // overwrite any previously stored value, so the recorded resolutions are
  // always the first ones for each monitor.
  void RecordOriginalResolution(ScreenResolution resolution,
                                webrtc::ScreenId screen_id);

  void OnDisplayInfoChanged(const DesktopDisplayInfo& display_info);

  std::unique_ptr<DesktopResizer> desktop_resizer_;

  // List of per-monitor original resolutions to be restored.
  std::map<webrtc::ScreenId, ScreenResolution> original_resolutions_;

  // List of current monitor IDs, populated from OnDisplayInfoChanged().
  // Requests to change a resolution should be dropped if there is no
  // monitor matching the requested ID. Requests without any ID should be
  // applied to the single monitor if there is only one.
  std::set<webrtc::ScreenId> current_monitor_ids_;

  // Whether monitors should be restored when this object is destroyed.
  bool restore_;

  // If SetScreenResolution() is called without any screen_id, and the
  // video-layout is still empty, the requested resolution is stored here so it
  // can be applied when the next video-layout is received. This is needed
  // because, on Windows, DesktopSessionAgent::Start() calls
  // SetScreenResolution() immediately after creating this object.
  ScreenResolution pending_resolution_request_;

  // State to manage rate-limiting of desktop resizes.
  base::OneShotTimer deferred_resize_timer_;
  base::TimeTicks previous_resize_time_;
  raw_ptr<const base::TickClock> clock_;

  base::WeakPtrFactory<ResizingHostObserver> weak_factory_{this};
};

}  // namespace remoting

#endif  // REMOTING_HOST_RESIZING_HOST_OBSERVER_H_