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

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: clean up test.js 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 using chromeos::ScreenLocker;
16
17 namespace screenlock = extensions::api::screenlock_private;
18
19 namespace extensions {
20
21 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {}
22
23 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {}
24
25 bool ScreenlockPrivateGetLockedFunction::RunImpl() {
26 bool locked = false;
27 ScreenLocker* locker = ScreenLocker::default_screen_locker();
28 if (locker)
29 locked = locker->locked();
30 SetResult(new base::FundamentalValue(locked));
31 SendResponse(error_.empty());
32 return true;
33 }
34
35 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {}
36
37 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {}
38
39 bool ScreenlockPrivateSetLockedFunction::RunImpl() {
40 scoped_ptr<screenlock::SetLocked::Params> params(
41 screenlock::SetLocked::Params::Create(*args_));
42 EXTENSION_FUNCTION_VALIDATE(params.get());
43 if (params->locked) {
44 ScreenLocker::Show();
xiyuan 2013/11/13 20:47:30 Let's do the locking via session manager. BusThre
benjhayden 2013/11/13 21:42:22 Done.
45 } else {
46 ScreenLocker* locker = ScreenLocker::default_screen_locker();
47 if (locker)
48 ScreenLocker::Hide();
49 }
50 SendResponse(error_.empty());
51 return true;
52 }
53
54 ScreenlockPrivateShowMessageFunction::ScreenlockPrivateShowMessageFunction() {}
55
56 ScreenlockPrivateShowMessageFunction::~ScreenlockPrivateShowMessageFunction() {}
57
58 bool ScreenlockPrivateShowMessageFunction::RunImpl() {
59 scoped_ptr<screenlock::SetLocked::Params> params(
60 screenlock::SetLocked::Params::Create(*args_));
61 EXTENSION_FUNCTION_VALIDATE(params.get());
62 ScreenLocker* locker = ScreenLocker::default_screen_locker();
63 if (!locker) {
64 SendResponse(error_.empty());
65 return true;
66 }
67 // TODO locker->ShowMessage(params->message);
68 SendResponse(error_.empty());
69 return true;
70 }
71
72 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(Profile* profile)
73 : profile_(profile) {
74 chromeos::SessionManagerClient* session_manager =
75 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
76 if (!session_manager->HasObserver(this))
77 session_manager->AddObserver(this);
78 }
79
80 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {}
81
82 void ScreenlockPrivateEventRouter::ScreenIsLocked() {
83 DispatchEvent(screenlock::OnChanged::kEventName,
84 new base::FundamentalValue(true));
85 }
86
87 void ScreenlockPrivateEventRouter::ScreenIsUnlocked() {
88 DispatchEvent(screenlock::OnChanged::kEventName,
89 new base::FundamentalValue(false));
90 }
91
92 void ScreenlockPrivateEventRouter::DispatchEvent(
93 const std::string& event_name,
94 base::Value* arg) {
95 scoped_ptr<base::ListValue> args(new base::ListValue());
96 args->Append(arg);
97 scoped_ptr<extensions::Event> event(new extensions::Event(
98 event_name, args.Pass()));
99 extensions::ExtensionSystem::Get(profile_)->event_router()->
100 BroadcastEvent(event.Pass());
101 }
102
103 static base::LazyInstance<extensions::ProfileKeyedAPIFactory<
104 ScreenlockPrivateEventRouter> >
105 g_factory = LAZY_INSTANCE_INITIALIZER;
106
107 // static
108 extensions::ProfileKeyedAPIFactory<ScreenlockPrivateEventRouter>*
109 ScreenlockPrivateEventRouter::GetFactoryInstance() {
110 return &g_factory.Get();
111 }
112
113 void ScreenlockPrivateEventRouter::Shutdown() {
114 chromeos::SessionManagerClient* session_manager =
115 chromeos::DBusThreadManager::Get()->GetSessionManagerClient();
116 if (session_manager->HasObserver(this))
117 session_manager->RemoveObserver(this);
118 }
119
120 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698