Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 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/signin/easy_unlock_util.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/profiles/profile_window.h" | |
| 11 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 12 #include "components/proximity_auth/proximity_auth_client.h" | |
| 13 #include "components/proximity_auth/screenlock_bridge.h" | |
| 14 #include "components/signin/core/browser/signin_manager_base.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 // A Chrome-specific implementation of the ProximityAuthClient. | |
| 19 class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient { | |
| 20 public: | |
| 21 ChromeProximityAuthClient(); | |
| 22 ~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.
| |
| 23 | |
| 24 // proximity_auth::ProximityAuthClient implementation: | |
| 25 std::string GetAuthenticatedUsername( | |
| 26 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.
| |
| 27 void Lock(content::BrowserContext* browser_context) override; | |
| 28 | |
| 29 private: | |
| 30 DISALLOW_COPY_AND_ASSIGN(ChromeProximityAuthClient); | |
| 31 }; | |
| 32 | |
| 33 ChromeProximityAuthClient::ChromeProximityAuthClient() { | |
| 34 } | |
| 35 | |
| 36 ChromeProximityAuthClient::~ChromeProximityAuthClient() { | |
| 37 } | |
| 38 | |
| 39 std::string ChromeProximityAuthClient::GetAuthenticatedUsername( | |
| 40 content::BrowserContext* browser_context) { | |
| 41 Profile* profile = Profile::FromBrowserContext(browser_context); | |
| 42 const SigninManagerBase* signin_manager = | |
| 43 SigninManagerFactory::GetForProfileIfExists(profile); | |
| 44 // |profile| has to be a signed-in profile with SigninManager already | |
| 45 // created. Otherwise, just crash to collect stack. | |
| 46 CHECK(signin_manager); | |
| 47 return signin_manager->GetAuthenticatedUsername(); | |
| 48 } | |
| 49 | |
| 50 void ChromeProximityAuthClient::Lock(content::BrowserContext* browser_context) { | |
| 51 profiles::LockProfile(Profile::FromBrowserContext(browser_context)); | |
| 52 } | |
| 53 | |
| 54 // 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.
| |
| 55 // manage the lifecycle of various objects of the Proximity Auth component. | |
| 56 class EasyUnlockUtil { | |
| 57 public: | |
| 58 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
| |
| 59 | |
| 60 private: | |
| 61 friend struct base::DefaultLazyInstanceTraits<EasyUnlockUtil>; | |
| 62 friend struct base::DefaultDeleter<EasyUnlockUtil>; | |
| 63 | |
| 64 EasyUnlockUtil(); | |
| 65 ~EasyUnlockUtil(); | |
| 66 | |
| 67 ChromeProximityAuthClient proximity_auth_client_; | |
| 68 proximity_auth::ScreenlockBridge screenlock_bridge_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(EasyUnlockUtil); | |
| 71 }; | |
| 72 | |
| 73 base::LazyInstance<EasyUnlockUtil> g_easy_unlock_util_instance = | |
| 74 LAZY_INSTANCE_INITIALIZER; | |
| 75 | |
| 76 EasyUnlockUtil::EasyUnlockUtil() | |
| 77 : 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.
| |
| 78 } | |
| 79 | |
| 80 EasyUnlockUtil::~EasyUnlockUtil() { | |
| 81 } | |
| 82 | |
| 83 proximity_auth::ScreenlockBridge* EasyUnlockUtil::GetScreenlockBridge() { | |
| 84 return &screenlock_bridge_; | |
| 85 } | |
|
Ilya Sherman
2015/04/24 21:22:02
nit: Please inline all of the EasyUnlockUtil metho
msarda
2015/04/27 11:29:24
Done.
| |
| 86 | |
| 87 } // namespace | |
| 88 | |
| 89 proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() { | |
| 90 return g_easy_unlock_util_instance.Pointer()->GetScreenlockBridge(); | |
| 91 } | |
| OLD | NEW |