| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "remoting/host/curtain.h" | 5 #include "remoting/host/curtain.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 |
| 7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/scoped_cftyperef.h" |
| 10 | 13 |
| 11 namespace { | 14 namespace { |
| 12 static const char* kCGSessionPath = | 15 static const char* kCGSessionPath = |
| 13 "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/" | 16 "/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/" |
| 14 "CGSession"; | 17 "CGSession"; |
| 15 } | 18 } |
| 16 | 19 |
| 17 namespace remoting { | 20 namespace remoting { |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 class CurtainMac : public Curtain { | 24 class CurtainMac : public Curtain { |
| 22 public: | 25 public: |
| 23 CurtainMac() {} | 26 CurtainMac() {} |
| 24 virtual void EnableCurtainMode(bool enable) OVERRIDE; | 27 virtual void EnableCurtainMode(bool enable) OVERRIDE; |
| 25 | 28 |
| 26 private: | 29 private: |
| 27 DISALLOW_COPY_AND_ASSIGN(CurtainMac); | 30 DISALLOW_COPY_AND_ASSIGN(CurtainMac); |
| 28 }; | 31 }; |
| 29 | 32 |
| 30 void CurtainMac::EnableCurtainMode(bool enable) { | 33 void CurtainMac::EnableCurtainMode(bool enable) { |
| 31 // Whether curtain mode is being enabled or disabled, switch out the session. | 34 // Whether curtain mode is being enabled or disabled, switch out the session |
| 35 // if the current user is switched in. |
| 32 // TODO(jamiewalch): If curtain mode is being enabled at the login screen, it | 36 // TODO(jamiewalch): If curtain mode is being enabled at the login screen, it |
| 33 // should be deferred until the user logs in. | 37 // should be deferred until the user logs in. |
| 34 pid_t child = fork(); | 38 base::mac::ScopedCFTypeRef<CFDictionaryRef> session( |
| 35 if (child == 0) { | 39 CGSessionCopyCurrentDictionary()); |
| 36 execl(kCGSessionPath, kCGSessionPath, "-suspend", (char*)0); | 40 if (CFDictionaryGetValue(session, |
| 37 exit(1); | 41 kCGSessionOnConsoleKey) == kCFBooleanTrue) { |
| 38 } else if (child > 0) { | 42 pid_t child = fork(); |
| 39 int status = 0; | 43 if (child == 0) { |
| 40 waitpid(child, &status, 0); | 44 execl(kCGSessionPath, kCGSessionPath, "-suspend", (char*)0); |
| 41 // To ensure that the system has plenty of time to notify the CGDisplay- | 45 exit(1); |
| 42 // ReconfigurationCallback, sleep here. 1s is probably overkill. | 46 } else if (child > 0) { |
| 43 sleep(1); | 47 int status = 0; |
| 48 waitpid(child, &status, 0); |
| 49 // To ensure that the system has plenty of time to notify the CGDisplay- |
| 50 // ReconfigurationCallback, sleep here. 1s is probably overkill. |
| 51 sleep(1); |
| 52 } |
| 44 } | 53 } |
| 45 } | 54 } |
| 46 | 55 |
| 47 } // namespace | 56 } // namespace |
| 48 | 57 |
| 49 Curtain* Curtain::Create() { | 58 Curtain* Curtain::Create() { |
| 50 // There's no need to check for curtain mode being enabled here because on | 59 // There's no need to check for curtain mode being enabled here because on |
| 51 // the mac it's easy for a local user to recover if anything crashes while | 60 // the mac it's easy for a local user to recover if anything crashes while |
| 52 // a session is active--they just have to enter a password to switch their | 61 // a session is active--they just have to enter a password to switch their |
| 53 // session back in. | 62 // session back in. |
| 54 return new CurtainMac(); | 63 return new CurtainMac(); |
| 55 } | 64 } |
| 56 | 65 |
| 57 } // namespace remoting | 66 } // namespace remoting |
| OLD | NEW |