blob: aef87c1150b047de29ba0767098bcaa739cb468a [file] [log] [blame]
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "remoting/host/curtain.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
namespace {
static const char* kCGSessionPath =
"/System/Library/CoreServices/Menu Extras/"
namespace remoting {
namespace {
class CurtainMac : public Curtain {
CurtainMac() {}
virtual void EnableCurtainMode(bool enable) OVERRIDE;
void CurtainMac::EnableCurtainMode(bool enable) {
// Whether curtain mode is being enabled or disabled, switch out the session.
// TODO(jamiewalch): If curtain mode is being enabled at the login screen, it
// should be deferred until the user logs in.
pid_t child = fork();
if (child == 0) {
execl(kCGSessionPath, kCGSessionPath, "-suspend", (char*)0);
} else if (child > 0) {
int status = 0;
waitpid(child, &status, 0);
// To ensure that the system has plenty of time to notify the CGDisplay-
// ReconfigurationCallback, sleep here. 1s is probably overkill.
} // namespace
Curtain* Curtain::Create() {
// There's no need to check for curtain mode being enabled here because on
// the mac it's easy for a local user to recover if anything crashes while
// a session is active--they just have to enter a password to switch their
// session back in.
return new CurtainMac();
} // namespace remoting