OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 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/proximity_auth_facade.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 {} |
| 23 |
| 24 // proximity_auth::ProximityAuthClient implementation: |
| 25 std::string GetAuthenticatedUsername( |
| 26 content::BrowserContext* browser_context) const override; |
| 27 void Lock(content::BrowserContext* browser_context) override; |
| 28 |
| 29 private: |
| 30 DISALLOW_COPY_AND_ASSIGN(ChromeProximityAuthClient); |
| 31 }; |
| 32 |
| 33 std::string ChromeProximityAuthClient::GetAuthenticatedUsername( |
| 34 content::BrowserContext* browser_context) const { |
| 35 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 36 const SigninManagerBase* signin_manager = |
| 37 SigninManagerFactory::GetForProfileIfExists(profile); |
| 38 // |profile| has to be a signed-in profile with SigninManager already |
| 39 // created. Otherwise, just crash to collect stack. |
| 40 DCHECK(signin_manager); |
| 41 return signin_manager->GetAuthenticatedUsername(); |
| 42 } |
| 43 |
| 44 void ChromeProximityAuthClient::Lock(content::BrowserContext* browser_context) { |
| 45 profiles::LockProfile(Profile::FromBrowserContext(browser_context)); |
| 46 } |
| 47 |
| 48 // A facade class that is the glue required to initialize and manage the |
| 49 // lifecycle of various objects of the Proximity Auth component. |
| 50 class ProximityAuthFacade { |
| 51 public: |
| 52 proximity_auth::ScreenlockBridge* GetScreenlockBridge() { |
| 53 return &screenlock_bridge_; |
| 54 } |
| 55 |
| 56 private: |
| 57 friend struct base::DefaultLazyInstanceTraits<ProximityAuthFacade>; |
| 58 friend struct base::DefaultDeleter<ProximityAuthFacade>; |
| 59 |
| 60 ProximityAuthFacade() : screenlock_bridge_(&proximity_auth_client_) {} |
| 61 ~ProximityAuthFacade() {} |
| 62 |
| 63 ChromeProximityAuthClient proximity_auth_client_; |
| 64 proximity_auth::ScreenlockBridge screenlock_bridge_; |
| 65 |
| 66 DISALLOW_COPY_AND_ASSIGN(ProximityAuthFacade); |
| 67 }; |
| 68 |
| 69 base::LazyInstance<ProximityAuthFacade> g_proximity_auth_facade_instance = |
| 70 LAZY_INSTANCE_INITIALIZER; |
| 71 |
| 72 } // namespace |
| 73 |
| 74 proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() { |
| 75 return g_proximity_auth_facade_instance.Pointer()->GetScreenlockBridge(); |
| 76 } |
OLD | NEW |