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

Side by Side Diff: chrome/browser/chromeos/extensions/screenlock_private_api.cc

Issue 60583003: The chrome.screenlockPrivate API allows select apps to control the ChromeOS ScreenLocker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/extensions/screenlock_private_api.h"
6
7 #include "base/lazy_instance.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/login/screen_locker.h"
10 #include "chrome/browser/extensions/event_router.h"
11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/common/extensions/api/screenlock_private.h"
13 #include "chromeos/dbus/dbus_thread_manager.h"
14
15 namespace screenlock = extensions::api::screenlock_private;
16
17 namespace extensions {
18
19 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {}
20
21 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {}
22
23 bool ScreenlockPrivateGetLockedFunction::RunImpl() {
24 bool locked = false;
25 chromeos::ScreenLocker* locker =
26 chromeos::ScreenLocker::default_screen_locker();
27 if (locker)
28 locked = locker->locked();
29 SetResult(new base::FundamentalValue(locked));
30 SendResponse(error_.empty());
31 return true;
32 }
33
34 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {}
35
36 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {}
37
38 bool ScreenlockPrivateSetLockedFunction::RunImpl() {
39 scoped_ptr<screenlock::SetLocked::Params> params(
40 screenlock::SetLocked::Params::Create(*args_));
41 EXTENSION_FUNCTION_VALIDATE(params.get());
42 if (params->locked) {
43 chromeos::SessionManagerClient* session_manager =
44 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
45 session_manager->RequestLockScreen();
46 } else {
47 chromeos::ScreenLocker* locker =
48 chromeos::ScreenLocker::default_screen_locker();
49 if (locker)
50 chromeos::ScreenLocker::Hide();
51 }
52 SendResponse(error_.empty());
53 return true;
54 }
55
56 ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {}
57
58 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {}
59
60 bool ScreenlockPrivateShowMessageFunction::RunImpl() {
61 scoped_ptr<screenlock::SetLocked::Params> params(
62 screenlock::SetLocked::Params::Create(*args_));
63 EXTENSION_FUNCTION_VALIDATE(params.get());
64 chromeos::ScreenLocker* locker =
65 chromeos::ScreenLocker::default_screen_locker();
66 if (!locker) {
67 SendResponse(error_.empty());
68 return true;
69 }
70 // TODO locker->ShowMessage(params->message);
71 SendResponse(error_.empty());
72 return true;
73 }
74
75 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(Profile* profile)
76 : profile_(profile) {
77 chromeos::SessionManagerClient* session_manager =
78 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
79 if (!session_manager->HasObserver(this))
80 session_manager->AddObserver(this);
81 }
82
83 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {}
84
85 void ScreenlockPrivateEventRouter::ScreenIsLocked() {
86 DispatchEvent(screenlock::OnChanged::kEventName,
87 new base::FundamentalValue(true));
88 }
89
90 void ScreenlockPrivateEventRouter::ScreenIsUnlocked() {
91 DispatchEvent(screenlock::OnChanged::kEventName,
92 new base::FundamentalValue(false));
93 }
94
95 void ScreenlockPrivateEventRouter::DispatchEvent(
96 const std::string& event_name,
97 base::Value* arg) {
98 scoped_ptr<base::ListValue> args(new base::ListValue());
99 args->Append(arg);
100 scoped_ptr<extensions::Event> event(new extensions::Event(
101 event_name, args.Pass()));
102 extensions::ExtensionSystem::Get(profile_)->event_router()->
103 BroadcastEvent(event.Pass());
104 }
105
106 static base::LazyInstance<extensions::ProfileKeyedAPIFactory<
107 ScreenlockPrivateEventRouter> >
108 g_factory = LAZY_INSTANCE_INITIALIZER;
109
110 // static
111 extensions::ProfileKeyedAPIFactory<ScreenlockPrivateEventRouter>*
112 ScreenlockPrivateEventRouter::GetFactoryInstance() {
113 return &g_factory.Get();
114 }
115
116 void ScreenlockPrivateEventRouter::Shutdown() {
117 chromeos::SessionManagerClient* session_manager =
118 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
119 if (session_manager->HasObserver(this))
120 session_manager->RemoveObserver(this);
121 }
122
123 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698