| 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/gtest_prod_util.h" | |
| 10 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 11 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 12 #include "base/thread.h" | 11 #include "base/thread.h" |
| 13 #include "base/waitable_event.h" | 12 #include "base/waitable_event.h" |
| 14 | 13 |
| 15 class CloudPrintProxy; | 14 class CloudPrintProxy; |
| 16 class JsonPrefStore; | 15 class JsonPrefStore; |
| 17 class ServiceIPCServer; | 16 class ServiceIPCServer; |
| 18 namespace net { | 17 namespace net { |
| 19 class NetworkChangeNotifier; | 18 class NetworkChangeNotifier; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace remoting { | 21 namespace remoting { |
| 23 class ChromotingHost; | 22 class ChromotingHost; |
| 24 class ChromotingHostContext; | 23 class ChromotingHostContext; |
| 25 class JsonHostConfig; | 24 class MutableHostConfig; |
| 26 } | 25 } |
| 27 | 26 |
| 28 // The ServiceProcess does not inherit from ChildProcess because this | 27 // The ServiceProcess does not inherit from ChildProcess because this |
| 29 // process can live independently of the browser process. | 28 // process can live independently of the browser process. |
| 30 class ServiceProcess { | 29 class ServiceProcess { |
| 31 public: | 30 public: |
| 32 ServiceProcess(); | 31 ServiceProcess(); |
| 33 ~ServiceProcess(); | 32 ~ServiceProcess(); |
| 34 | 33 |
| 35 // Initialize the ServiceProcess with the message loop that it should run on. | 34 bool Initialize(); |
| 36 bool Initialize(MessageLoop* message_loop); | |
| 37 bool Teardown(); | 35 bool Teardown(); |
| 38 // TODO(sanjeevr): Change various parts of the code such as | 36 // TODO(sanjeevr): Change various parts of the code such as |
| 39 // net::ProxyService::CreateSystemProxyConfigService to take in | 37 // net::ProxyService::CreateSystemProxyConfigService to take in |
| 40 // MessageLoopProxy* instead of MessageLoop*. When we have done that, we can | 38 // MessageLoopProxy* instead of MessageLoop*. When we have done that, we can |
| 41 // remove the io_thread() and file_thread() accessors and replace them with | 39 // remove the io_thread() and file_thread() accessors and replace them with |
| 42 // io_message_loop_proxy() and file_message_loop_proxy() respectively. | 40 // io_message_loop_proxy() and file_message_loop_proxy() respectively. |
| 43 | 41 |
| 44 // Returns the thread that we perform I/O coordination on (network requests, | 42 // Returns the thread that we perform I/O coordination on (network requests, |
| 45 // communication with renderers, etc. | 43 // communication with renderers, etc. |
| 46 // NOTE: You should ONLY use this to pass to IPC or other objects which must | 44 // NOTE: You should ONLY use this to pass to IPC or other objects which must |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 } | 57 } |
| 60 | 58 |
| 61 // A global event object that is signalled when the main thread's message | 59 // A global event object that is signalled when the main thread's message |
| 62 // loop exits. This gives background threads a way to observe the main | 60 // loop exits. This gives background threads a way to observe the main |
| 63 // thread shutting down. | 61 // thread shutting down. |
| 64 base::WaitableEvent* shutdown_event() { | 62 base::WaitableEvent* shutdown_event() { |
| 65 return &shutdown_event_; | 63 return &shutdown_event_; |
| 66 } | 64 } |
| 67 | 65 |
| 68 CloudPrintProxy* GetCloudPrintProxy(); | 66 CloudPrintProxy* GetCloudPrintProxy(); |
| 69 | |
| 70 #if defined(ENABLE_REMOTING) | 67 #if defined(ENABLE_REMOTING) |
| 71 // Return the reference to the chromoting host only if it has started. | 68 remoting::ChromotingHost* CreateChromotingHost( |
| 72 remoting::ChromotingHost* GetChromotingHost() { return chromoting_host_; } | 69 remoting::ChromotingHostContext* context, |
| 73 | 70 remoting::MutableHostConfig* config); |
| 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(); | |
| 81 #endif | 71 #endif |
| 82 | 72 |
| 83 private: | 73 private: |
| 84 #if defined(ENABLE_REMOTING) | |
| 85 FRIEND_TEST(ServiceProcessTest, RunChromoting); | |
| 86 FRIEND_TEST_ALL_PREFIXES(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 | |
| 104 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 74 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 105 scoped_ptr<base::Thread> io_thread_; | 75 scoped_ptr<base::Thread> io_thread_; |
| 106 scoped_ptr<base::Thread> file_thread_; | 76 scoped_ptr<base::Thread> file_thread_; |
| 107 scoped_ptr<CloudPrintProxy> cloud_print_proxy_; | 77 scoped_ptr<CloudPrintProxy> cloud_print_proxy_; |
| 108 scoped_ptr<JsonPrefStore> service_prefs_; | 78 scoped_ptr<JsonPrefStore> service_prefs_; |
| 109 scoped_ptr<ServiceIPCServer> ipc_server_; | 79 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 | |
| 116 // An event that will be signalled when we shutdown. | 80 // An event that will be signalled when we shutdown. |
| 117 base::WaitableEvent shutdown_event_; | 81 base::WaitableEvent shutdown_event_; |
| 118 | 82 |
| 119 // The main message loop for the service process. | |
| 120 MessageLoop* main_message_loop_; | |
| 121 | |
| 122 DISALLOW_COPY_AND_ASSIGN(ServiceProcess); | 83 DISALLOW_COPY_AND_ASSIGN(ServiceProcess); |
| 123 }; | 84 }; |
| 124 | 85 |
| 125 extern ServiceProcess* g_service_process; | 86 extern ServiceProcess* g_service_process; |
| 126 | 87 |
| 127 #endif // CHROME_SERVICE_SERVICE_PROCESS_H_ | 88 #endif // CHROME_SERVICE_SERVICE_PROCESS_H_ |
| 89 |
| OLD | NEW |