OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/signin/proximity_auth_facade.h" | 5 #include "chrome/browser/signin/proximity_auth_facade.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 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" | 8 #include "components/proximity_auth/screenlock_bridge.h" |
14 #include "components/signin/core/browser/signin_manager_base.h" | |
15 | 9 |
16 namespace { | 10 namespace { |
17 | 11 |
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 | 12 // A facade class that is the glue required to initialize and manage the |
49 // lifecycle of various objects of the Proximity Auth component. | 13 // lifecycle of various objects of the Proximity Auth component. |
50 class ProximityAuthFacade { | 14 class ProximityAuthFacade { |
51 public: | 15 public: |
52 proximity_auth::ScreenlockBridge* GetScreenlockBridge() { | 16 proximity_auth::ScreenlockBridge* GetScreenlockBridge() { |
53 return &screenlock_bridge_; | 17 return &screenlock_bridge_; |
54 } | 18 } |
55 | 19 |
56 private: | 20 private: |
57 friend struct base::DefaultLazyInstanceTraits<ProximityAuthFacade>; | 21 friend struct base::DefaultLazyInstanceTraits<ProximityAuthFacade>; |
58 friend struct base::DefaultDeleter<ProximityAuthFacade>; | 22 friend struct base::DefaultDeleter<ProximityAuthFacade>; |
59 | 23 |
60 ProximityAuthFacade() : screenlock_bridge_(&proximity_auth_client_) {} | 24 ProximityAuthFacade() {} |
61 ~ProximityAuthFacade() {} | 25 ~ProximityAuthFacade() {} |
62 | 26 |
63 ChromeProximityAuthClient proximity_auth_client_; | |
64 proximity_auth::ScreenlockBridge screenlock_bridge_; | 27 proximity_auth::ScreenlockBridge screenlock_bridge_; |
65 | 28 |
66 DISALLOW_COPY_AND_ASSIGN(ProximityAuthFacade); | 29 DISALLOW_COPY_AND_ASSIGN(ProximityAuthFacade); |
67 }; | 30 }; |
68 | 31 |
69 base::LazyInstance<ProximityAuthFacade> g_proximity_auth_facade_instance = | 32 base::LazyInstance<ProximityAuthFacade> g_proximity_auth_facade_instance = |
70 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
71 | 34 |
72 } // namespace | 35 } // namespace |
73 | 36 |
74 proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() { | 37 proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() { |
75 return g_proximity_auth_facade_instance.Pointer()->GetScreenlockBridge(); | 38 return g_proximity_auth_facade_instance.Pointer()->GetScreenlockBridge(); |
76 } | 39 } |
OLD | NEW |