Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / host / desktop_session_win.h
blob933be24f0a65a1702b14d169b7cb010d4f2773ed
1 // Copyright (c) 2012 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 REMOTING_HOST_DESKTOP_SESSION_WIN_H_
6 #define REMOTING_HOST_DESKTOP_SESSION_WIN_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "base/timer/timer.h"
12 #include "base/win/scoped_handle.h"
13 #include "ipc/ipc_platform_file.h"
14 #include "remoting/host/desktop_session.h"
15 #include "remoting/host/win/wts_terminal_observer.h"
16 #include "remoting/host/worker_process_ipc_delegate.h"
18 namespace tracked_objects {
19 class Location;
20 } // namespace tracked_objects
22 namespace remoting {
24 class AutoThreadTaskRunner;
25 class DaemonProcess;
26 class DesktopSession;
27 class ScreenResolution;
28 class WorkerProcessLauncher;
29 class WtsTerminalMonitor;
31 // DesktopSession implementation which attaches to either physical or virtual
32 // (RDP) console. Receives IPC messages from the desktop process, running in
33 // the target session, via |WorkerProcessIpcDelegate|, and monitors session
34 // attach/detach events via |WtsTerminalObserer|.
35 class DesktopSessionWin
36 : public DesktopSession,
37 public WorkerProcessIpcDelegate,
38 public WtsTerminalObserver {
39 public:
40 // Creates a desktop session instance that attaches to the physical console.
41 static scoped_ptr<DesktopSession> CreateForConsole(
42 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
43 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
44 DaemonProcess* daemon_process,
45 int id,
46 const ScreenResolution& resolution);
48 // Creates a desktop session instance that attaches to a virtual console.
49 static scoped_ptr<DesktopSession> CreateForVirtualTerminal(
50 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
51 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
52 DaemonProcess* daemon_process,
53 int id,
54 const ScreenResolution& resolution);
56 protected:
57 // Passes the owning |daemon_process|, a unique identifier of the desktop
58 // session |id| and the interface for monitoring session attach/detach events.
59 // Both |daemon_process| and |monitor| must outlive |this|.
60 DesktopSessionWin(
61 scoped_refptr<AutoThreadTaskRunner> caller_task_runner,
62 scoped_refptr<AutoThreadTaskRunner> io_task_runner,
63 DaemonProcess* daemon_process,
64 int id,
65 WtsTerminalMonitor* monitor);
66 ~DesktopSessionWin() override;
68 const scoped_refptr<AutoThreadTaskRunner>& caller_task_runner() const {
69 return caller_task_runner_;
72 // Called when |session_attach_timer_| expires.
73 void OnSessionAttachTimeout();
75 // Starts monitoring for session attach/detach events for |terminal_id|.
76 void StartMonitoring(const std::string& terminal_id);
78 // Stops monitoring for session attach/detach events.
79 void StopMonitoring();
81 // Asks DaemonProcess to terminate this session.
82 void TerminateSession();
84 // Injects a secure attention sequence into the session.
85 virtual void InjectSas() = 0;
87 // WorkerProcessIpcDelegate implementation.
88 void OnChannelConnected(int32 peer_pid) override;
89 bool OnMessageReceived(const IPC::Message& message) override;
90 void OnPermanentError(int exit_code) override;
92 // WtsTerminalObserver implementation.
93 void OnSessionAttached(uint32 session_id) override;
94 void OnSessionDetached() override;
96 private:
97 // ChromotingDesktopDaemonMsg_DesktopAttached handler.
98 void OnDesktopSessionAgentAttached(IPC::PlatformFileForTransit desktop_pipe);
100 // Requests the desktop process to crash.
101 void CrashDesktopProcess(const tracked_objects::Location& location);
103 // Reports time elapsed since previous event to the debug log.
104 void ReportElapsedTime(const std::string& event);
106 // Task runner on which public methods of this class should be called.
107 scoped_refptr<AutoThreadTaskRunner> caller_task_runner_;
109 // Message loop used by the IPC channel.
110 scoped_refptr<AutoThreadTaskRunner> io_task_runner_;
112 // Handle of the desktop process (running an instance of DesktopSessionAgent).
113 base::win::ScopedHandle desktop_process_;
115 // Launches and monitors the desktop process.
116 scoped_ptr<WorkerProcessLauncher> launcher_;
118 // Used to unsubscribe from session attach and detach events.
119 WtsTerminalMonitor* monitor_;
121 // True if |this| is subsribed to receive session attach/detach notifications.
122 bool monitoring_notifications_;
124 // Used to report an error if the session attach notification does not arrives
125 // for too long.
126 base::OneShotTimer<DesktopSessionWin> session_attach_timer_;
128 base::Time last_timestamp_;
130 DISALLOW_COPY_AND_ASSIGN(DesktopSessionWin);
133 } // namespace remoting
135 #endif // REMOTING_HOST_DESKTOP_SESSION_WIN_H_