Chromium Code Reviews| 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 on the console. | |
|
Jamie
2011/10/31 22:17:47
For consistency, maybe say "if the user is switche
| |
| 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 LOG(ERROR) << "Enabling Curtain mode!"; |
|
Jamie
2011/10/31 22:17:47
Remove, or at least lower the log level (and get r
| |
| 39 int status = 0; | 43 |
| 40 waitpid(child, &status, 0); | 44 pid_t child = fork(); |
| 41 // To ensure that the system has plenty of time to notify the CGDisplay- | 45 if (child == 0) { |
| 42 // ReconfigurationCallback, sleep here. 1s is probably overkill. | 46 execl(kCGSessionPath, kCGSessionPath, "-suspend", (char*)0); |
| 43 sleep(1); | 47 exit(1); |
| 48 } else if (child > 0) { | |
| 49 int status = 0; | |
| 50 waitpid(child, &status, 0); | |
| 51 // To ensure that the system has plenty of time to notify the CGDisplay- | |
| 52 // ReconfigurationCallback, sleep here. 1s is probably overkill. | |
| 53 sleep(1); | |
| 54 } | |
| 44 } | 55 } |
| 45 } | 56 } |
| 46 | 57 |
| 47 } // namespace | 58 } // namespace |
| 48 | 59 |
| 49 Curtain* Curtain::Create() { | 60 Curtain* Curtain::Create() { |
| 50 // There's no need to check for curtain mode being enabled here because on | 61 // 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 | 62 // 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 | 63 // a session is active--they just have to enter a password to switch their |
| 53 // session back in. | 64 // session back in. |
| 54 return new CurtainMac(); | 65 return new CurtainMac(); |
| 55 } | 66 } |
| 56 | 67 |
| 57 } // namespace remoting | 68 } // namespace remoting |
| OLD | NEW |