Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(872)

Side by Side Diff: remoting/host/win/host_service.h

Issue 16143004: Use a weak pointer to post service control events and session change notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef REMOTING_HOST_WIN_HOST_SERVICE_H_ 5 #ifndef REMOTING_HOST_WIN_HOST_SERVICE_H_
6 #define REMOTING_HOST_WIN_HOST_SERVICE_H_ 6 #define REMOTING_HOST_WIN_HOST_SERVICE_H_
7 7
8 #include <windows.h> 8 #include <windows.h>
9 9
10 #include <list> 10 #include <list>
11 11
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/memory/weak_ptr.h"
14 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
15 #include "net/base/ip_endpoint.h" 16 #include "net/base/ip_endpoint.h"
16 #include "remoting/host/win/message_window.h" 17 #include "remoting/host/win/message_window.h"
17 #include "remoting/host/win/wts_terminal_monitor.h" 18 #include "remoting/host/win/wts_terminal_monitor.h"
18 19
19 class CommandLine; 20 class CommandLine;
20 21
21 namespace base { 22 namespace base {
22 class SingleThreadTaskRunner; 23 class SingleThreadTaskRunner;
23 } // namespace base 24 } // namespace base
24 25
25 namespace remoting { 26 namespace remoting {
26 27
27 class AutoThreadTaskRunner; 28 class AutoThreadTaskRunner;
28 class Stoppable; 29 class DaemonProcess;
29 class WtsTerminalObserver; 30 class WtsTerminalObserver;
30 31
31 class HostService : public win::MessageWindow::Delegate, 32 class HostService : public win::MessageWindow::Delegate,
32 public WtsTerminalMonitor { 33 public WtsTerminalMonitor {
33 public: 34 public:
34 static HostService* GetInstance(); 35 static HostService* GetInstance();
35 36
36 // This function parses the command line and selects the action routine. 37 // This function parses the command line and selects the action routine.
37 bool InitWithCommandLine(const CommandLine* command_line); 38 bool InitWithCommandLine(const CommandLine* command_line);
38 39
39 // Invoke the choosen action routine. 40 // Invoke the choosen action routine.
40 int Run(); 41 int Run();
41 42
42 // WtsTerminalMonitor implementation 43 // WtsTerminalMonitor implementation
43 virtual bool AddWtsTerminalObserver(const net::IPEndPoint& client_endpoint, 44 virtual bool AddWtsTerminalObserver(const net::IPEndPoint& client_endpoint,
44 WtsTerminalObserver* observer) OVERRIDE; 45 WtsTerminalObserver* observer) OVERRIDE;
45 virtual void RemoveWtsTerminalObserver( 46 virtual void RemoveWtsTerminalObserver(
46 WtsTerminalObserver* observer) OVERRIDE; 47 WtsTerminalObserver* observer) OVERRIDE;
47 48
48 private: 49 private:
49 HostService(); 50 HostService();
50 ~HostService(); 51 ~HostService();
51 52
52 // Notifies the service of changes in session state. 53 // Notifies the service of changes in session state.
53 void OnSessionChange(uint32 event, uint32 session_id); 54 void OnSessionChange(uint32 event, uint32 session_id);
54 55
55 // Creates the process launcher. 56 // Creates the process launcher.
56 void CreateLauncher(scoped_refptr<AutoThreadTaskRunner> task_runner); 57 void CreateLauncher(scoped_refptr<AutoThreadTaskRunner> task_runner);
57 58
58 void OnChildStopped();
59
60 // This function handshakes with the service control manager and starts 59 // This function handshakes with the service control manager and starts
61 // the service. 60 // the service.
62 int RunAsService(); 61 int RunAsService();
63 62
64 // Runs the service on the service thread. A separate routine is used to make 63 // Runs the service on the service thread. A separate routine is used to make
65 // sure all local objects are destoyed by the time |stopped_event_| is 64 // sure all local objects are destoyed by the time |stopped_event_| is
66 // signalled. 65 // signalled.
67 void RunAsServiceImpl(); 66 void RunAsServiceImpl();
68 67
69 // This function starts the service in interactive mode (i.e. as a plain 68 // This function starts the service in interactive mode (i.e. as a plain
70 // console application). 69 // console application).
71 int RunInConsole(); 70 int RunInConsole();
72 71
72 // Stops and deletes |daemon_process_|.
73 void StopDaemonProcess();
74
73 // win::MessageWindow::Delegate interface. 75 // win::MessageWindow::Delegate interface.
74 virtual bool HandleMessage(HWND hwnd, 76 virtual bool HandleMessage(HWND hwnd,
75 UINT message, 77 UINT message,
76 WPARAM wparam, 78 WPARAM wparam,
77 LPARAM lparam, 79 LPARAM lparam,
78 LRESULT* result) OVERRIDE; 80 LRESULT* result) OVERRIDE;
79 81
80 static BOOL WINAPI ConsoleControlHandler(DWORD event); 82 static BOOL WINAPI ConsoleControlHandler(DWORD event);
81 83
82 // The control handler of the service. 84 // The control handler of the service.
(...skipping 15 matching lines...) Expand all
98 uint32 session_id; 100 uint32 session_id;
99 101
100 // Points to the observer receiving notifications about the WTS console 102 // Points to the observer receiving notifications about the WTS console
101 // identified by |client_endpoint|. 103 // identified by |client_endpoint|.
102 WtsTerminalObserver* observer; 104 WtsTerminalObserver* observer;
103 }; 105 };
104 106
105 // The list of observers receiving session notifications. 107 // The list of observers receiving session notifications.
106 std::list<RegisteredObserver> observers_; 108 std::list<RegisteredObserver> observers_;
107 109
108 scoped_ptr<Stoppable> child_; 110 scoped_ptr<DaemonProcess> daemon_process_;
109 111
110 // Service message loop. 112 // Service message loop.
111 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 113 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
Wez 2013/06/07 17:48:24 nit: It's important that we're not clearing |main_
alexeypa (please no reviews) 2013/06/07 18:30:23 Done.
112 114
113 // The action routine to be executed. 115 // The action routine to be executed.
114 int (HostService::*run_routine_)(); 116 int (HostService::*run_routine_)();
115 117
116 // The service status handle. 118 // The service status handle.
117 SERVICE_STATUS_HANDLE service_status_handle_; 119 SERVICE_STATUS_HANDLE service_status_handle_;
118 120
119 // A waitable event that is used to wait until the service is stopped. 121 // A waitable event that is used to wait until the service is stopped.
120 base::WaitableEvent stopped_event_; 122 base::WaitableEvent stopped_event_;
121 123
124 // Used to post session change notifications and control events.
125 base::WeakPtrFactory<HostService> weak_factory_;
126 base::WeakPtr<HostService> weak_self_;
Wez 2013/06/07 17:48:24 nit: Elsewhere we call this |weak_ptr_|.
alexeypa (please no reviews) 2013/06/07 18:30:23 Done.
127
122 // Singleton. 128 // Singleton.
123 friend struct DefaultSingletonTraits<HostService>; 129 friend struct DefaultSingletonTraits<HostService>;
124 130
125 DISALLOW_COPY_AND_ASSIGN(HostService); 131 DISALLOW_COPY_AND_ASSIGN(HostService);
126 }; 132 };
127 133
128 } // namespace remoting 134 } // namespace remoting
129 135
130 #endif // REMOTING_HOST_WIN_HOST_SERVICE_H_ 136 #endif // REMOTING_HOST_WIN_HOST_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698