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

Unified Diff: remoting/host/daemon_process_win.cc

Issue 17261013: Change the daemon start type to 'manual' if the host ID has been deleted. (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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/daemon_process_win.cc
diff --git a/remoting/host/daemon_process_win.cc b/remoting/host/daemon_process_win.cc
index 5603c9a7ec75f857ee4bdf615f38875b6140cda0..6bf2e6e5914bd7e2e4b9e3820ace57dc00136853 100644
--- a/remoting/host/daemon_process_win.cc
+++ b/remoting/host/daemon_process_win.cc
@@ -20,6 +20,8 @@
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/base/scoped_sc_handle_win.h"
+#include "remoting/host/branding.h"
#include "remoting/host/chromoting_messages.h"
#include "remoting/host/desktop_session_win.h"
#include "remoting/host/host_exit_codes.h"
@@ -51,6 +53,7 @@ class DaemonProcessWin : public DaemonProcess {
// WorkerProcessIpcDelegate implementation.
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
+ virtual void OnPermanentError(int exit_code) OVERRIDE;
// DaemonProcess overrides.
virtual void SendToNetwork(IPC::Message* message) OVERRIDE;
@@ -69,6 +72,9 @@ class DaemonProcessWin : public DaemonProcess {
const tracked_objects::Location& location) OVERRIDE;
virtual void LaunchNetworkProcess() OVERRIDE;
+ // Changes the service start type to 'manual'.
+ void DisableAutoStart();
+
private:
scoped_ptr<WorkerProcessLauncher> network_launcher_;
@@ -99,6 +105,16 @@ void DaemonProcessWin::OnChannelConnected(int32 peer_pid) {
DaemonProcess::OnChannelConnected(peer_pid);
}
+void DaemonProcessWin::OnPermanentError(int exit_code) {
+ // Change the service start type to 'manual' if the host has been deleted
+ // remotely. This way the host will not be started every time the machine
+ // boots until the user re-enable it again.
+ if (exit_code == kInvalidHostIdExitCode)
+ DisableAutoStart();
+
+ DaemonProcess::OnPermanentError(exit_code);
+}
+
void DaemonProcessWin::SendToNetwork(IPC::Message* message) {
if (network_launcher_) {
network_launcher_->Send(message);
@@ -186,4 +202,42 @@ scoped_ptr<DaemonProcess> DaemonProcess::Create(
return daemon_process.PassAs<DaemonProcess>();
}
+void DaemonProcessWin::DisableAutoStart() {
+ ScopedScHandle scmanager(
+ OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE,
+ SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE));
+ if (!scmanager.IsValid()) {
+ LOG_GETLASTERROR(INFO)
+ << "Failed to connect to the service control manager";
+ return;
+ }
+
+ DWORD desired_access = SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS;
+ ScopedScHandle service(
+ OpenService(scmanager, kWindowsServiceName, desired_access));
+ if (!service.IsValid()) {
+ LOG_GETLASTERROR(INFO)
+ << "Failed to open to the '" << kWindowsServiceName << "' service";
+ return;
+ }
+
+ // Change the service start type to 'manual'. All |NULL| parameters below mean
+ // that there is no change to the corresponding service parameter.
+ if (!ChangeServiceConfig(service,
+ SERVICE_NO_CHANGE,
+ SERVICE_DEMAND_START,
+ SERVICE_NO_CHANGE,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL)) {
+ LOG_GETLASTERROR(INFO)
+ << "Failed to change the '" << kWindowsServiceName
+ << "'service start type to 'manual'";
+ }
+}
+
} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698