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..60580bc80a76f1c054fcb0f0a11ad4cdb0d19bc8 |
| --- /dev/null |
| +++ b/chrome/browser/signin/easy_unlock_util.cc |
| @@ -0,0 +1,91 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// 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 "base/memory/scoped_ptr.h" |
| +#include "base/strings/string16.h" |
|
Ilya Sherman
2015/04/23 20:52:53
nit: Not needed?
msarda
2015/04/24 15:47:05
Done.
|
| +#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. |
|
Ilya Sherman
2015/04/23 20:52:53
nit: "Chrome specific" -> "Chrome-specific"
msarda
2015/04/24 15:47:05
Done.
|
| +class ChromeProximityAuthClient : public ProximityAuthClient { |
| + public: |
| + ChromeProximityAuthClient(); |
| + virtual ~ChromeProximityAuthClient(); |
|
Ilya Sherman
2015/04/23 20:52:53
nit: Please leave a blank line after this one.
sdefresne
2015/04/24 14:22:02
~ChromeProximityAuthClient() override;
|
| + std::string GetAuthenticatedUsername( |
|
Ilya Sherman
2015/04/23 20:52:53
nit: Above this line, please add "// ProximityAuth
msarda
2015/04/24 15:47:05
Done.
|
| + content::BrowserContext* browser_context) override; |
| + void Lock(content::BrowserContext* browser_context) override; |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(ChromeProximityAuthClient); |
| +}; |
| + |
| +ChromeProximityAuthClient::ChromeProximityAuthClient() { |
| +} |
| + |
| +ChromeProximityAuthClient::~ChromeProximityAuthClient() { |
| +} |
|
Ilya Sherman
2015/04/23 20:52:53
Optional: Eventually, we'll probably a more involv
msarda
2015/04/24 15:47:06
I prefer to do that later as I would argue we coul
|
| + |
| +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); |
|
Ilya Sherman
2015/04/23 20:52:53
nit: No need for the explicit CHECK -- a null poin
sdefresne
2015/04/24 14:22:02
It will only crash reliably if the called method i
msarda
2015/04/24 15:47:06
+1 for what Sylvain said (this was also the reason
|
| + return signin_manager->GetAuthenticatedUsername(); |
| +} |
| + |
| +void ChromeProximityAuthClient::Lock(content::BrowserContext* browser_context) { |
| + profiles::LockProfile(Profile::FromBrowserContext(browser_context)); |
| +} |
| + |
| +// A utilitary class that serves as the glue code required to initialize and |
|
Ilya Sherman
2015/04/23 20:52:53
nit: s/utilitary/utility
msarda
2015/04/24 15:47:05
Done.
msarda
2015/04/24 15:47:05
Done.
|
| +// manage the lifecycle of various objects of the Proximity Auth components. |
| +class EasyUnlockUtil { |
| + public: |
| + ScreenlockBridge* GetScreenlockBridge(); |
| + |
| + private: |
| + EasyUnlockUtil(); |
| + ~EasyUnlockUtil(); |
| + |
| + scoped_ptr<ChromeProximityAuthClient> proximity_auth_client_; |
|
sdefresne
2015/04/24 14:22:03
Why not directly use instance value instead of sco
msarda
2015/04/24 15:47:05
Done.
|
| + scoped_ptr<ScreenlockBridge> screenlock_bridge_; |
| + friend struct base::DefaultLazyInstanceTraits<EasyUnlockUtil>; |
|
sdefresne
2015/04/24 14:22:02
style: friend comes before everything else
https:
msarda
2015/04/24 15:47:05
Done.
|
| + friend struct base::DefaultDeleter<EasyUnlockUtil>; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(EasyUnlockUtil); |
| +}; |
| + |
| +base::LazyInstance<EasyUnlockUtil> g_easy_unlock_util_instance = |
| + LAZY_INSTANCE_INITIALIZER; |
| + |
| +EasyUnlockUtil::EasyUnlockUtil() { |
| + proximity_auth_client_.reset(new ChromeProximityAuthClient()); |
| + screenlock_bridge_.reset(new ScreenlockBridge(proximity_auth_client_.get())); |
| +} |
| + |
| +EasyUnlockUtil::~EasyUnlockUtil() { |
| +} |
| + |
| +ScreenlockBridge* EasyUnlockUtil::GetScreenlockBridge() { |
| + return screenlock_bridge_.get(); |
| +} |
| + |
| +} // namespace |
| + |
| +ScreenlockBridge* GetScreenlockBridgeInstance() { |
| + return g_easy_unlock_util_instance.Pointer()->GetScreenlockBridge(); |
| +} |