OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_SERVICE_SERVICE_PROCESS_H_ | 5 #ifndef CHROME_SERVICE_SERVICE_PROCESS_H_ |
6 #define CHROME_SERVICE_SERVICE_PROCESS_H_ | 6 #define CHROME_SERVICE_SERVICE_PROCESS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
11 #include "base/thread.h" | 11 #include "base/thread.h" |
12 #include "base/waitable_event.h" | 12 #include "base/waitable_event.h" |
| 13 #include "testing/gtest/include/gtest/gtest_prod.h" |
13 | 14 |
14 class CloudPrintProxy; | 15 class CloudPrintProxy; |
15 class JsonPrefStore; | 16 class JsonPrefStore; |
16 class ServiceIPCServer; | 17 class ServiceIPCServer; |
17 namespace net { | 18 namespace net { |
18 class NetworkChangeNotifier; | 19 class NetworkChangeNotifier; |
19 } | 20 } |
20 | 21 |
21 namespace remoting { | 22 namespace remoting { |
22 class ChromotingHost; | 23 class ChromotingHost; |
23 class ChromotingHostContext; | 24 class ChromotingHostContext; |
24 class MutableHostConfig; | 25 class JsonHostConfig; |
25 } | 26 } |
26 | 27 |
27 // The ServiceProcess does not inherit from ChildProcess because this | 28 // The ServiceProcess does not inherit from ChildProcess because this |
28 // process can live independently of the browser process. | 29 // process can live independently of the browser process. |
29 class ServiceProcess { | 30 class ServiceProcess { |
30 public: | 31 public: |
31 ServiceProcess(); | 32 ServiceProcess(); |
32 ~ServiceProcess(); | 33 ~ServiceProcess(); |
33 | 34 |
34 bool Initialize(); | 35 // Initialize the ServiceProcess with the message loop that it should run on. |
| 36 bool Initialize(MessageLoop* message_loop); |
35 bool Teardown(); | 37 bool Teardown(); |
36 // TODO(sanjeevr): Change various parts of the code such as | 38 // TODO(sanjeevr): Change various parts of the code such as |
37 // net::ProxyService::CreateSystemProxyConfigService to take in | 39 // net::ProxyService::CreateSystemProxyConfigService to take in |
38 // MessageLoopProxy* instead of MessageLoop*. When we have done that, we can | 40 // MessageLoopProxy* instead of MessageLoop*. When we have done that, we can |
39 // remove the io_thread() and file_thread() accessors and replace them with | 41 // remove the io_thread() and file_thread() accessors and replace them with |
40 // io_message_loop_proxy() and file_message_loop_proxy() respectively. | 42 // io_message_loop_proxy() and file_message_loop_proxy() respectively. |
41 | 43 |
42 // Returns the thread that we perform I/O coordination on (network requests, | 44 // Returns the thread that we perform I/O coordination on (network requests, |
43 // communication with renderers, etc. | 45 // communication with renderers, etc. |
44 // NOTE: You should ONLY use this to pass to IPC or other objects which must | 46 // NOTE: You should ONLY use this to pass to IPC or other objects which must |
(...skipping 12 matching lines...) Expand all Loading... |
57 } | 59 } |
58 | 60 |
59 // A global event object that is signalled when the main thread's message | 61 // A global event object that is signalled when the main thread's message |
60 // loop exits. This gives background threads a way to observe the main | 62 // loop exits. This gives background threads a way to observe the main |
61 // thread shutting down. | 63 // thread shutting down. |
62 base::WaitableEvent* shutdown_event() { | 64 base::WaitableEvent* shutdown_event() { |
63 return &shutdown_event_; | 65 return &shutdown_event_; |
64 } | 66 } |
65 | 67 |
66 CloudPrintProxy* GetCloudPrintProxy(); | 68 CloudPrintProxy* GetCloudPrintProxy(); |
| 69 |
67 #if defined(ENABLE_REMOTING) | 70 #if defined(ENABLE_REMOTING) |
68 remoting::ChromotingHost* CreateChromotingHost( | 71 // Return the reference to the chromoting host only if it has started. |
69 remoting::ChromotingHostContext* context, | 72 remoting::ChromotingHost* GetChromotingHost() { return chromoting_host_; } |
70 remoting::MutableHostConfig* config); | 73 |
| 74 // Start running the chromoting host asynchronously. |
| 75 // Return true if chromoting host has started. |
| 76 bool StartChromotingHost(); |
| 77 |
| 78 // Shutdown chromoting host. Return true if chromoting host was shutdown. |
| 79 // The shutdown process will happen asynchronously. |
| 80 bool ShutdownChromotingHost(); |
71 #endif | 81 #endif |
72 | 82 |
73 private: | 83 private: |
| 84 #if defined(ENABLE_REMOTING) |
| 85 FRIEND_TEST(ServiceProcessTest, RunChromoting); |
| 86 FRIEND_TEST(ServiceProcessTest, RunChromotingUntilShutdown); |
| 87 |
| 88 // Save authenication token to the json config file. |
| 89 void SaveChromotingConfig( |
| 90 const std::string& login, |
| 91 const std::string& token, |
| 92 const std::string& host_id, |
| 93 const std::string& host_name, |
| 94 const std::string& private_key); |
| 95 |
| 96 // Load settings for chromoting from json file. |
| 97 void LoadChromotingConfig(); |
| 98 |
| 99 // This method is called when chromoting is shutting down. This is virtual |
| 100 // for used in the test. |
| 101 virtual void OnChromotingHostShutdown(); |
| 102 #endif |
| 103 |
74 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 104 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
75 scoped_ptr<base::Thread> io_thread_; | 105 scoped_ptr<base::Thread> io_thread_; |
76 scoped_ptr<base::Thread> file_thread_; | 106 scoped_ptr<base::Thread> file_thread_; |
77 scoped_ptr<CloudPrintProxy> cloud_print_proxy_; | 107 scoped_ptr<CloudPrintProxy> cloud_print_proxy_; |
78 scoped_ptr<JsonPrefStore> service_prefs_; | 108 scoped_ptr<JsonPrefStore> service_prefs_; |
79 scoped_ptr<ServiceIPCServer> ipc_server_; | 109 scoped_ptr<ServiceIPCServer> ipc_server_; |
| 110 |
| 111 #if defined(ENABLE_REMOTING) |
| 112 scoped_refptr<remoting::JsonHostConfig> chromoting_config_; |
| 113 scoped_ptr<remoting::ChromotingHostContext> chromoting_context_; |
| 114 scoped_refptr<remoting::ChromotingHost> chromoting_host_; |
| 115 #endif |
80 // An event that will be signalled when we shutdown. | 116 // An event that will be signalled when we shutdown. |
81 base::WaitableEvent shutdown_event_; | 117 base::WaitableEvent shutdown_event_; |
82 | 118 |
| 119 // The main message loop for the service process. |
| 120 MessageLoop* main_message_loop_; |
| 121 |
83 DISALLOW_COPY_AND_ASSIGN(ServiceProcess); | 122 DISALLOW_COPY_AND_ASSIGN(ServiceProcess); |
84 }; | 123 }; |
85 | 124 |
86 extern ServiceProcess* g_service_process; | 125 extern ServiceProcess* g_service_process; |
87 | 126 |
88 #endif // CHROME_SERVICE_SERVICE_PROCESS_H_ | 127 #endif // CHROME_SERVICE_SERVICE_PROCESS_H_ |
89 | |
OLD | NEW |