Chromium Code Reviews| Index: chrome/browser/signin/easy_unlock_util.cc |
| diff --git a/chrome/browser/signin/easy_unlock_util.cc b/chrome/browser/signin/easy_unlock_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ff74f434428b37a5f6635297bb0bb887b0e2aa3b |
| --- /dev/null |
| +++ b/chrome/browser/signin/easy_unlock_util.cc |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
Ilya Sherman
2015/04/24 21:22:02
nit: 2015
msarda
2015/04/27 11:29:25
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/signin/easy_unlock_util.h" |
| + |
| +#include "base/lazy_instance.h" |
| +#include "base/logging.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_window.h" |
| +#include "chrome/browser/signin/signin_manager_factory.h" |
| +#include "components/proximity_auth/proximity_auth_client.h" |
| +#include "components/proximity_auth/screenlock_bridge.h" |
| +#include "components/signin/core/browser/signin_manager_base.h" |
| + |
| +namespace { |
| + |
| +// A Chrome-specific implementation of the ProximityAuthClient. |
| +class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient { |
| + public: |
| + ChromeProximityAuthClient(); |
| + ~ChromeProximityAuthClient() override; |
|
Ilya Sherman
2015/04/24 21:22:02
nit: Please inline these trivial constructor and d
msarda
2015/04/27 11:29:25
Done.
|
| + |
| + // proximity_auth::ProximityAuthClient implementation: |
| + std::string GetAuthenticatedUsername( |
| + content::BrowserContext* browser_context) override; |
|
Ilya Sherman
2015/04/24 21:22:02
nit: Can this be const?
msarda
2015/04/27 11:29:25
Done.
|
| + void Lock(content::BrowserContext* browser_context) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ChromeProximityAuthClient); |
| +}; |
| + |
| +ChromeProximityAuthClient::ChromeProximityAuthClient() { |
| +} |
| + |
| +ChromeProximityAuthClient::~ChromeProximityAuthClient() { |
| +} |
| + |
| +std::string ChromeProximityAuthClient::GetAuthenticatedUsername( |
| + content::BrowserContext* browser_context) { |
| + Profile* profile = Profile::FromBrowserContext(browser_context); |
| + const SigninManagerBase* signin_manager = |
| + SigninManagerFactory::GetForProfileIfExists(profile); |
| + // |profile| has to be a signed-in profile with SigninManager already |
| + // created. Otherwise, just crash to collect stack. |
| + CHECK(signin_manager); |
| + return signin_manager->GetAuthenticatedUsername(); |
| +} |
| + |
| +void ChromeProximityAuthClient::Lock(content::BrowserContext* browser_context) { |
| + profiles::LockProfile(Profile::FromBrowserContext(browser_context)); |
| +} |
| + |
| +// A /utility class that serves as the glue code required to initialize and |
|
Ilya Sherman
2015/04/24 21:22:02
nit: Please remove the "/" before "utility"
msarda
2015/04/27 11:29:24
Done.
|
| +// manage the lifecycle of various objects of the Proximity Auth component. |
| +class EasyUnlockUtil { |
| + public: |
| + proximity_auth::ScreenlockBridge* GetScreenlockBridge(); |
|
Ilya Sherman
2015/04/24 21:22:02
nit: This is a trivial accessor, so please name it
msarda
2015/04/27 11:29:24
I think this is not really a trivial accessor - it
|
| + |
| + private: |
| + friend struct base::DefaultLazyInstanceTraits<EasyUnlockUtil>; |
| + friend struct base::DefaultDeleter<EasyUnlockUtil>; |
| + |
| + EasyUnlockUtil(); |
| + ~EasyUnlockUtil(); |
| + |
| + ChromeProximityAuthClient proximity_auth_client_; |
| + proximity_auth::ScreenlockBridge screenlock_bridge_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(EasyUnlockUtil); |
| +}; |
| + |
| +base::LazyInstance<EasyUnlockUtil> g_easy_unlock_util_instance = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +EasyUnlockUtil::EasyUnlockUtil() |
| + : proximity_auth_client_(), screenlock_bridge_(&proximity_auth_client_) { |
|
Ilya Sherman
2015/04/24 21:22:02
nit: Please omit the default constructor call for
msarda
2015/04/27 11:29:25
Done.
|
| +} |
| + |
| +EasyUnlockUtil::~EasyUnlockUtil() { |
| +} |
| + |
| +proximity_auth::ScreenlockBridge* EasyUnlockUtil::GetScreenlockBridge() { |
| + return &screenlock_bridge_; |
| +} |
|
Ilya Sherman
2015/04/24 21:22:02
nit: Please inline all of the EasyUnlockUtil metho
msarda
2015/04/27 11:29:24
Done.
|
| + |
| +} // namespace |
| + |
| +proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() { |
| + return g_easy_unlock_util_instance.Pointer()->GetScreenlockBridge(); |
| +} |