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

Side by Side Diff: chrome/browser/extensions/api/screenlock_private/screenlock_private_api.cc

Issue 1096293003: Move screenlock_bridge to components/proximity_auth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h" 5 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap i.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/easy_unlock_service.h" 10 #include "chrome/browser/signin/easy_unlock_service.h"
11 #include "chrome/browser/signin/easy_unlock_util.h"
11 #include "chrome/common/extensions/api/screenlock_private.h" 12 #include "chrome/common/extensions/api/screenlock_private.h"
12 #include "chrome/common/extensions/extension_constants.h" 13 #include "chrome/common/extensions/extension_constants.h"
13 #include "extensions/browser/app_window/app_window_registry.h" 14 #include "extensions/browser/app_window/app_window_registry.h"
14 #include "extensions/browser/event_router.h" 15 #include "extensions/browser/event_router.h"
15 16
16 namespace screenlock = extensions::api::screenlock_private; 17 namespace screenlock = extensions::api::screenlock_private;
17 18
18 namespace extensions { 19 namespace extensions {
19 20
20 namespace { 21 namespace {
21 22
22 screenlock::AuthType FromLockHandlerAuthType( 23 screenlock::AuthType FromLockHandlerAuthType(
23 ScreenlockBridge::LockHandler::AuthType auth_type) { 24 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type) {
24 switch (auth_type) { 25 switch (auth_type) {
25 case ScreenlockBridge::LockHandler::OFFLINE_PASSWORD: 26 case proximity_auth::ScreenlockBridge::LockHandler::OFFLINE_PASSWORD:
26 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; 27 return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
27 case ScreenlockBridge::LockHandler::NUMERIC_PIN: 28 case proximity_auth::ScreenlockBridge::LockHandler::NUMERIC_PIN:
28 return screenlock::AUTH_TYPE_NUMERICPIN; 29 return screenlock::AUTH_TYPE_NUMERICPIN;
29 case ScreenlockBridge::LockHandler::USER_CLICK: 30 case proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK:
30 return screenlock::AUTH_TYPE_USERCLICK; 31 return screenlock::AUTH_TYPE_USERCLICK;
31 case ScreenlockBridge::LockHandler::ONLINE_SIGN_IN: 32 case proximity_auth::ScreenlockBridge::LockHandler::ONLINE_SIGN_IN:
32 // Apps should treat forced online sign in same as system password. 33 // Apps should treat forced online sign in same as system password.
33 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; 34 return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
34 case ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK: 35 case proximity_auth::ScreenlockBridge::LockHandler::EXPAND_THEN_USER_CLICK:
35 // This type is used for public sessions, which do not support screen 36 // This type is used for public sessions, which do not support screen
36 // locking. 37 // locking.
37 NOTREACHED(); 38 NOTREACHED();
38 return screenlock::AUTH_TYPE_NONE; 39 return screenlock::AUTH_TYPE_NONE;
39 case ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD: 40 case proximity_auth::ScreenlockBridge::LockHandler::FORCE_OFFLINE_PASSWORD:
40 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; 41 return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
41 } 42 }
42 NOTREACHED(); 43 NOTREACHED();
43 return screenlock::AUTH_TYPE_OFFLINEPASSWORD; 44 return screenlock::AUTH_TYPE_OFFLINEPASSWORD;
44 } 45 }
45 46
46 } // namespace 47 } // namespace
47 48
48 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {} 49 ScreenlockPrivateGetLockedFunction::ScreenlockPrivateGetLockedFunction() {}
49 50
50 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {} 51 ScreenlockPrivateGetLockedFunction::~ScreenlockPrivateGetLockedFunction() {}
51 52
52 bool ScreenlockPrivateGetLockedFunction::RunAsync() { 53 bool ScreenlockPrivateGetLockedFunction::RunAsync() {
53 SetResult(new base::FundamentalValue(ScreenlockBridge::Get()->IsLocked())); 54 SetResult(
55 new base::FundamentalValue(GetScreenlockBridgeInstance()->IsLocked()));
54 SendResponse(error_.empty()); 56 SendResponse(error_.empty());
55 return true; 57 return true;
56 } 58 }
57 59
58 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} 60 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {}
59 61
60 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} 62 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {}
61 63
62 bool ScreenlockPrivateSetLockedFunction::RunAsync() { 64 bool ScreenlockPrivateSetLockedFunction::RunAsync() {
63 scoped_ptr<screenlock::SetLocked::Params> params( 65 scoped_ptr<screenlock::SetLocked::Params> params(
64 screenlock::SetLocked::Params::Create(*args_)); 66 screenlock::SetLocked::Params::Create(*args_));
65 EXTENSION_FUNCTION_VALIDATE(params.get()); 67 EXTENSION_FUNCTION_VALIDATE(params.get());
66 if (params->locked) { 68 if (params->locked) {
67 if (extension()->id() == extension_misc::kEasyUnlockAppId && 69 if (extension()->id() == extension_misc::kEasyUnlockAppId &&
68 AppWindowRegistry::Get(browser_context()) 70 AppWindowRegistry::Get(browser_context())
69 ->GetAppWindowForAppAndKey(extension()->id(), 71 ->GetAppWindowForAppAndKey(extension()->id(),
70 "easy_unlock_pairing")) { 72 "easy_unlock_pairing")) {
71 // Mark the Easy Unlock behaviour on the lock screen as the one initiated 73 // Mark the Easy Unlock behaviour on the lock screen as the one initiated
72 // by the Easy Unlock setup app as a trial one. 74 // by the Easy Unlock setup app as a trial one.
73 // TODO(tbarzic): Move this logic to a new easyUnlockPrivate function. 75 // TODO(tbarzic): Move this logic to a new easyUnlockPrivate function.
74 EasyUnlockService* service = EasyUnlockService::Get(GetProfile()); 76 EasyUnlockService* service = EasyUnlockService::Get(GetProfile());
75 if (service) 77 if (service)
76 service->SetTrialRun(); 78 service->SetTrialRun();
77 } 79 }
78 ScreenlockBridge::Get()->Lock(GetProfile()); 80 GetScreenlockBridgeInstance()->Lock(GetProfile());
79 } else { 81 } else {
80 ScreenlockBridge::Get()->Unlock(GetProfile()); 82 GetScreenlockBridgeInstance()->Unlock(GetProfile());
81 } 83 }
82 SendResponse(error_.empty()); 84 SendResponse(error_.empty());
83 return true; 85 return true;
84 } 86 }
85 87
86 ScreenlockPrivateAcceptAuthAttemptFunction:: 88 ScreenlockPrivateAcceptAuthAttemptFunction::
87 ScreenlockPrivateAcceptAuthAttemptFunction() {} 89 ScreenlockPrivateAcceptAuthAttemptFunction() {}
88 90
89 ScreenlockPrivateAcceptAuthAttemptFunction:: 91 ScreenlockPrivateAcceptAuthAttemptFunction::
90 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} 92 ~ScreenlockPrivateAcceptAuthAttemptFunction() {}
91 93
92 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() { 94 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() {
93 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( 95 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params(
94 screenlock::AcceptAuthAttempt::Params::Create(*args_)); 96 screenlock::AcceptAuthAttempt::Params::Create(*args_));
95 EXTENSION_FUNCTION_VALIDATE(params.get()); 97 EXTENSION_FUNCTION_VALIDATE(params.get());
96 98
97 Profile* profile = Profile::FromBrowserContext(browser_context()); 99 Profile* profile = Profile::FromBrowserContext(browser_context());
98 EasyUnlockService* service = EasyUnlockService::Get(profile); 100 EasyUnlockService* service = EasyUnlockService::Get(profile);
99 if (service) 101 if (service)
100 service->FinalizeUnlock(params->accept); 102 service->FinalizeUnlock(params->accept);
101 return true; 103 return true;
102 } 104 }
103 105
104 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( 106 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter(
105 content::BrowserContext* context) 107 content::BrowserContext* context)
106 : browser_context_(context) { 108 : browser_context_(context) {
107 ScreenlockBridge::Get()->AddObserver(this); 109 GetScreenlockBridgeInstance()->AddObserver(this);
108 } 110 }
109 111
110 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} 112 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {}
111 113
112 void ScreenlockPrivateEventRouter::OnScreenDidLock( 114 void ScreenlockPrivateEventRouter::OnScreenDidLock(
113 ScreenlockBridge::LockHandler::ScreenType screen_type) { 115 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
114 DispatchEvent(screenlock::OnChanged::kEventName, 116 DispatchEvent(screenlock::OnChanged::kEventName,
115 new base::FundamentalValue(true)); 117 new base::FundamentalValue(true));
116 } 118 }
117 119
118 void ScreenlockPrivateEventRouter::OnScreenDidUnlock( 120 void ScreenlockPrivateEventRouter::OnScreenDidUnlock(
119 ScreenlockBridge::LockHandler::ScreenType screen_type) { 121 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) {
120 DispatchEvent(screenlock::OnChanged::kEventName, 122 DispatchEvent(screenlock::OnChanged::kEventName,
121 new base::FundamentalValue(false)); 123 new base::FundamentalValue(false));
122 } 124 }
123 125
124 void ScreenlockPrivateEventRouter::OnFocusedUserChanged( 126 void ScreenlockPrivateEventRouter::OnFocusedUserChanged(
125 const std::string& user_id) { 127 const std::string& user_id) {
126 } 128 }
127 129
128 void ScreenlockPrivateEventRouter::DispatchEvent( 130 void ScreenlockPrivateEventRouter::DispatchEvent(
129 const std::string& event_name, 131 const std::string& event_name,
130 base::Value* arg) { 132 base::Value* arg) {
131 scoped_ptr<base::ListValue> args(new base::ListValue()); 133 scoped_ptr<base::ListValue> args(new base::ListValue());
132 if (arg) 134 if (arg)
133 args->Append(arg); 135 args->Append(arg);
134 scoped_ptr<extensions::Event> event(new extensions::Event( 136 scoped_ptr<extensions::Event> event(new extensions::Event(
135 event_name, args.Pass())); 137 event_name, args.Pass()));
136 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass()); 138 extensions::EventRouter::Get(browser_context_)->BroadcastEvent(event.Pass());
137 } 139 }
138 140
139 static base::LazyInstance<extensions::BrowserContextKeyedAPIFactory< 141 static base::LazyInstance<extensions::BrowserContextKeyedAPIFactory<
140 ScreenlockPrivateEventRouter> > g_factory = LAZY_INSTANCE_INITIALIZER; 142 ScreenlockPrivateEventRouter> > g_factory = LAZY_INSTANCE_INITIALIZER;
141 143
142 // static 144 // static
143 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>* 145 extensions::BrowserContextKeyedAPIFactory<ScreenlockPrivateEventRouter>*
144 ScreenlockPrivateEventRouter::GetFactoryInstance() { 146 ScreenlockPrivateEventRouter::GetFactoryInstance() {
145 return g_factory.Pointer(); 147 return g_factory.Pointer();
146 } 148 }
147 149
148 void ScreenlockPrivateEventRouter::Shutdown() { 150 void ScreenlockPrivateEventRouter::Shutdown() {
149 ScreenlockBridge::Get()->RemoveObserver(this); 151 GetScreenlockBridgeInstance()->RemoveObserver(this);
150 } 152 }
151 153
152 bool ScreenlockPrivateEventRouter::OnAuthAttempted( 154 bool ScreenlockPrivateEventRouter::OnAuthAttempted(
153 ScreenlockBridge::LockHandler::AuthType auth_type, 155 proximity_auth::ScreenlockBridge::LockHandler::AuthType auth_type,
154 const std::string& value) { 156 const std::string& value) {
155 extensions::EventRouter* router = 157 extensions::EventRouter* router =
156 extensions::EventRouter::Get(browser_context_); 158 extensions::EventRouter::Get(browser_context_);
157 if (!router->HasEventListener(screenlock::OnAuthAttempted::kEventName)) 159 if (!router->HasEventListener(screenlock::OnAuthAttempted::kEventName))
158 return false; 160 return false;
159 161
160 scoped_ptr<base::ListValue> args(new base::ListValue()); 162 scoped_ptr<base::ListValue> args(new base::ListValue());
161 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); 163 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type)));
162 args->AppendString(value); 164 args->AppendString(value);
163 165
164 scoped_ptr<extensions::Event> event(new extensions::Event( 166 scoped_ptr<extensions::Event> event(new extensions::Event(
165 screenlock::OnAuthAttempted::kEventName, args.Pass())); 167 screenlock::OnAuthAttempted::kEventName, args.Pass()));
166 router->BroadcastEvent(event.Pass()); 168 router->BroadcastEvent(event.Pass());
167 return true; 169 return true;
168 } 170 }
169 171
170 } // namespace extensions 172 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698