Move generic_handler.* to content\browser\webui since it's needed by all webui pages.
[chromium-blink-merge.git] / remoting / host / win / host_service.h
bloba79ad2f830aecac3242b72f08f989ac62f271533
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_WIN_HOST_SERVICE_H_
6 #define REMOTING_HOST_WIN_HOST_SERVICE_H_
8 #include <windows.h>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/singleton.h"
12 #include "base/observer_list.h"
13 #include "base/synchronization/waitable_event.h"
14 #include "remoting/host/win/wts_console_monitor.h"
16 class CommandLine;
18 namespace base {
19 class SingleThreadTaskRunner;
20 } // namespace base
22 namespace remoting {
24 class AutoThreadTaskRunner;
25 class Stoppable;
26 class WtsConsoleObserver;
28 class HostService : public WtsConsoleMonitor {
29 public:
30 static HostService* GetInstance();
32 // This function parses the command line and selects the action routine.
33 bool InitWithCommandLine(const CommandLine* command_line);
35 // Invoke the choosen action routine.
36 int Run();
38 // WtsConsoleMonitor implementation
39 virtual void AddWtsConsoleObserver(WtsConsoleObserver* observer) OVERRIDE;
40 virtual void RemoveWtsConsoleObserver(
41 WtsConsoleObserver* observer) OVERRIDE;
43 private:
44 HostService();
45 ~HostService();
47 void OnChildStopped();
49 // Notifies the service of changes in session state.
50 void OnSessionChange();
52 // Creates the process launcher.
53 void CreateLauncher(scoped_refptr<AutoThreadTaskRunner> task_runner);
55 // Runs the binary specified by the command line, elevated.
56 int Elevate();
58 // This function handshakes with the service control manager and starts
59 // the service.
60 int RunAsService();
62 // Runs the service on the service thread. A separate routine is used to make
63 // sure all local objects are destoyed by the time |stopped_event_| is
64 // signalled.
65 void RunAsServiceImpl();
67 // This function starts the service in interactive mode (i.e. as a plain
68 // console application).
69 int RunInConsole();
71 static BOOL WINAPI ConsoleControlHandler(DWORD event);
73 // The control handler of the service.
74 static DWORD WINAPI ServiceControlHandler(DWORD control,
75 DWORD event_type,
76 LPVOID event_data,
77 LPVOID context);
79 // The main service entry point.
80 static VOID WINAPI ServiceMain(DWORD argc, WCHAR* argv[]);
82 static LRESULT CALLBACK SessionChangeNotificationProc(HWND hwnd,
83 UINT message,
84 WPARAM wparam,
85 LPARAM lparam);
87 // Current physical console session id.
88 uint32 console_session_id_;
90 // The list of observers receiving notifications about any session attached
91 // to the physical console.
92 ObserverList<WtsConsoleObserver> console_observers_;
94 scoped_ptr<Stoppable> child_;
96 // Service message loop.
97 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
99 // The action routine to be executed.
100 int (HostService::*run_routine_)();
102 // The service status handle.
103 SERVICE_STATUS_HANDLE service_status_handle_;
105 // A waitable event that is used to wait until the service is stopped.
106 base::WaitableEvent stopped_event_;
108 // Singleton.
109 friend struct DefaultSingletonTraits<HostService>;
111 DISALLOW_COPY_AND_ASSIGN(HostService);
114 } // namespace remoting
116 #endif // REMOTING_HOST_WIN_HOST_SERVICE_H_