Index: chrome/browser/chromeos/extensions/screenlock_private_api.cc |
diff --git a/chrome/browser/chromeos/extensions/screenlock_private_api.cc b/chrome/browser/chromeos/extensions/screenlock_private_api.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..02c1a51a436b0ea9c44bb630aad66f11e42f82d5 |
--- /dev/null |
+++ b/chrome/browser/chromeos/extensions/screenlock_private_api.cc |
@@ -0,0 +1,123 @@ |
+// Copyright (c) 2013 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 "chrome/browser/chromeos/extensions/screenlock_private_api.h" |
+ |
+#include "base/lazy_instance.h" |
+#include "base/values.h" |
+#include "chrome/browser/chromeos/login/screen_locker.h" |
+#include "chrome/browser/extensions/event_router.h" |
+#include "chrome/browser/extensions/extension_system.h" |
+#include "chrome/common/extensions/api/screenlock_private.h" |
+#include "chromeos/dbus/dbus_thread_manager.h" |
+ |
+namespace screenlock = extensions::api::screenlock_private; |
+ |
+namespace extensions { |
+ |
+ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} |
+ |
+ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} |
+ |
+bool ScreenlockPrivateGetLockedFunction::RunImpl() { |
+ bool locked = false; |
+ chromeos::ScreenLocker* locker = |
+ chromeos::ScreenLocker::default_screen_locker(); |
+ if (locker) |
+ locked = locker->locked(); |
+ SetResult(new base::FundamentalValue(locked)); |
+ SendResponse(error_.empty()); |
+ return true; |
+} |
+ |
+ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} |
+ |
+ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} |
+ |
+bool ScreenlockPrivateSetLockedFunction::RunImpl() { |
+ scoped_ptr<screenlock::SetLocked::Params> params( |
+ screenlock::SetLocked::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params.get()); |
+ if (params->locked) { |
+ chromeos::SessionManagerClient* session_manager = |
+ chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
+ session_manager->RequestLockScreen(); |
+ } else { |
+ chromeos::ScreenLocker* locker = |
+ chromeos::ScreenLocker::default_screen_locker(); |
+ if (locker) |
+ chromeos::ScreenLocker::Hide(); |
+ } |
+ SendResponse(error_.empty()); |
+ return true; |
+} |
+ |
+ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {} |
+ |
+ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {} |
+ |
+bool ScreenlockPrivateShowMessageFunction::RunImpl() { |
+ scoped_ptr<screenlock::SetLocked::Params> params( |
+ screenlock::SetLocked::Params::Create(*args_)); |
+ EXTENSION_FUNCTION_VALIDATE(params.get()); |
+ chromeos::ScreenLocker* locker = |
+ chromeos::ScreenLocker::default_screen_locker(); |
+ if (!locker) { |
+ SendResponse(error_.empty()); |
+ return true; |
+ } |
+ // TODO locker->ShowMessage(params->message); |
+ SendResponse(error_.empty()); |
+ return true; |
+} |
+ |
+ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(Profile* profile) |
+ : profile_(profile) { |
+ chromeos::SessionManagerClient* session_manager = |
+ chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
+ if (!session_manager->HasObserver(this)) |
+ session_manager->AddObserver(this); |
+} |
+ |
+ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} |
+ |
+void ScreenlockPrivateEventRouter::ScreenIsLocked() { |
+ DispatchEvent(screenlock::OnChanged::kEventName, |
+ new base::FundamentalValue(true)); |
+} |
+ |
+void ScreenlockPrivateEventRouter::ScreenIsUnlocked() { |
+ DispatchEvent(screenlock::OnChanged::kEventName, |
+ new base::FundamentalValue(false)); |
+} |
+ |
+void ScreenlockPrivateEventRouter::DispatchEvent( |
+ const std::string& event_name, |
+ base::Value* arg) { |
+ scoped_ptr<base::ListValue> args(new base::ListValue()); |
+ args->Append(arg); |
+ scoped_ptr<extensions::Event> event(new extensions::Event( |
+ event_name, args.Pass())); |
+ extensions::ExtensionSystem::Get(profile_)->event_router()-> |
+ BroadcastEvent(event.Pass()); |
+} |
+ |
+static base::LazyInstance<extensions::ProfileKeyedAPIFactory< |
+ ScreenlockPrivateEventRouter> > |
+ g_factory = LAZY_INSTANCE_INITIALIZER; |
+ |
+// static |
+extensions::ProfileKeyedAPIFactory<ScreenlockPrivateEventRouter>* |
+ScreenlockPrivateEventRouter::GetFactoryInstance() { |
+ return &g_factory.Get(); |
+} |
+ |
+void ScreenlockPrivateEventRouter::Shutdown() { |
+ chromeos::SessionManagerClient* session_manager = |
+ chromeos::DBusThreadManager::Get()->GetSessionManagerClient(); |
+ if (session_manager->HasObserver(this)) |
+ session_manager->RemoveObserver(this); |
+} |
+ |
+} // namespace extensions |