OLD | NEW |
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/common/extensions/api/screenlock_private.h" | 11 #include "chrome/common/extensions/api/screenlock_private.h" |
| 12 #include "chrome/common/extensions/extension_constants.h" |
12 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
13 | 14 |
14 namespace screenlock = extensions::api::screenlock_private; | 15 namespace screenlock = extensions::api::screenlock_private; |
15 | 16 |
16 namespace extensions { | 17 namespace extensions { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 screenlock::AuthType FromLockHandlerAuthType( | 21 screenlock::AuthType FromLockHandlerAuthType( |
21 ScreenlockBridge::LockHandler::AuthType auth_type) { | 22 ScreenlockBridge::LockHandler::AuthType auth_type) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 } | 55 } |
55 | 56 |
56 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} | 57 ScreenlockPrivateSetLockedFunction::ScreenlockPrivateSetLockedFunction() {} |
57 | 58 |
58 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} | 59 ScreenlockPrivateSetLockedFunction::~ScreenlockPrivateSetLockedFunction() {} |
59 | 60 |
60 bool ScreenlockPrivateSetLockedFunction::RunAsync() { | 61 bool ScreenlockPrivateSetLockedFunction::RunAsync() { |
61 scoped_ptr<screenlock::SetLocked::Params> params( | 62 scoped_ptr<screenlock::SetLocked::Params> params( |
62 screenlock::SetLocked::Params::Create(*args_)); | 63 screenlock::SetLocked::Params::Create(*args_)); |
63 EXTENSION_FUNCTION_VALIDATE(params.get()); | 64 EXTENSION_FUNCTION_VALIDATE(params.get()); |
64 if (params->locked) | 65 if (params->locked) { |
| 66 if (extension()->id() == extension_misc::kEasyUnlockAppId) { |
| 67 // Mark the Easy Unlock behaviour on the lock screen as the one initiated |
| 68 // by the Easy Unlock setup app as a trial one. |
| 69 // TODO(tbarzic): Move this logic to a new easyUnlockPrivate function. |
| 70 EasyUnlockService* service = EasyUnlockService::Get(GetProfile()); |
| 71 if (service) |
| 72 service->SetTrialRun(); |
| 73 } |
65 ScreenlockBridge::Get()->Lock(GetProfile()); | 74 ScreenlockBridge::Get()->Lock(GetProfile()); |
66 else | 75 } else { |
67 ScreenlockBridge::Get()->Unlock(GetProfile()); | 76 ScreenlockBridge::Get()->Unlock(GetProfile()); |
| 77 } |
68 SendResponse(error_.empty()); | 78 SendResponse(error_.empty()); |
69 return true; | 79 return true; |
70 } | 80 } |
71 | 81 |
72 ScreenlockPrivateAcceptAuthAttemptFunction:: | 82 ScreenlockPrivateAcceptAuthAttemptFunction:: |
73 ScreenlockPrivateAcceptAuthAttemptFunction() {} | 83 ScreenlockPrivateAcceptAuthAttemptFunction() {} |
74 | 84 |
75 ScreenlockPrivateAcceptAuthAttemptFunction:: | 85 ScreenlockPrivateAcceptAuthAttemptFunction:: |
76 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} | 86 ~ScreenlockPrivateAcceptAuthAttemptFunction() {} |
77 | 87 |
78 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() { | 88 bool ScreenlockPrivateAcceptAuthAttemptFunction::RunSync() { |
79 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( | 89 scoped_ptr<screenlock::AcceptAuthAttempt::Params> params( |
80 screenlock::AcceptAuthAttempt::Params::Create(*args_)); | 90 screenlock::AcceptAuthAttempt::Params::Create(*args_)); |
81 EXTENSION_FUNCTION_VALIDATE(params.get()); | 91 EXTENSION_FUNCTION_VALIDATE(params.get()); |
82 | 92 |
83 Profile* profile = Profile::FromBrowserContext(browser_context()); | 93 Profile* profile = Profile::FromBrowserContext(browser_context()); |
84 EasyUnlockService::Get(profile)->FinalizeUnlock(params->accept); | 94 EasyUnlockService* service = EasyUnlockService::Get(profile); |
| 95 if (service) |
| 96 service->FinalizeUnlock(params->accept); |
85 return true; | 97 return true; |
86 } | 98 } |
87 | 99 |
88 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( | 100 ScreenlockPrivateEventRouter::ScreenlockPrivateEventRouter( |
89 content::BrowserContext* context) | 101 content::BrowserContext* context) |
90 : browser_context_(context) { | 102 : browser_context_(context) { |
91 ScreenlockBridge::Get()->AddObserver(this); | 103 ScreenlockBridge::Get()->AddObserver(this); |
92 } | 104 } |
93 | 105 |
94 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} | 106 ScreenlockPrivateEventRouter::~ScreenlockPrivateEventRouter() {} |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); | 155 args->AppendString(screenlock::ToString(FromLockHandlerAuthType(auth_type))); |
144 args->AppendString(value); | 156 args->AppendString(value); |
145 | 157 |
146 scoped_ptr<extensions::Event> event(new extensions::Event( | 158 scoped_ptr<extensions::Event> event(new extensions::Event( |
147 screenlock::OnAuthAttempted::kEventName, args.Pass())); | 159 screenlock::OnAuthAttempted::kEventName, args.Pass())); |
148 router->BroadcastEvent(event.Pass()); | 160 router->BroadcastEvent(event.Pass()); |
149 return true; | 161 return true; |
150 } | 162 } |
151 | 163 |
152 } // namespace extensions | 164 } // namespace extensions |
OLD | NEW |