[Media Router] Add integration tests and e2e tests for media router and presentation...
[chromium-blink-merge.git] / chrome / browser / signin / proximity_auth_facade.cc
blobbef11432ff50e1d4b97580820f0a1517ae330ed6
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.
5 #include "chrome/browser/signin/proximity_auth_facade.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"
14 #include "components/signin/core/browser/signin_manager_base.h"
16 namespace {
18 // A Chrome-specific implementation of the ProximityAuthClient.
19 class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
20 public:
21 ChromeProximityAuthClient() {}
22 ~ChromeProximityAuthClient() override {}
24 // proximity_auth::ProximityAuthClient implementation:
25 std::string GetAuthenticatedUsername(
26 content::BrowserContext* browser_context) const override;
27 void Lock(content::BrowserContext* browser_context) override;
29 private:
30 DISALLOW_COPY_AND_ASSIGN(ChromeProximityAuthClient);
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();
44 void ChromeProximityAuthClient::Lock(content::BrowserContext* browser_context) {
45 profiles::LockProfile(Profile::FromBrowserContext(browser_context));
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_;
56 private:
57 friend struct base::DefaultLazyInstanceTraits<ProximityAuthFacade>;
58 friend struct base::DefaultDeleter<ProximityAuthFacade>;
60 ProximityAuthFacade() : screenlock_bridge_(&proximity_auth_client_) {}
61 ~ProximityAuthFacade() {}
63 ChromeProximityAuthClient proximity_auth_client_;
64 proximity_auth::ScreenlockBridge screenlock_bridge_;
66 DISALLOW_COPY_AND_ASSIGN(ProximityAuthFacade);
69 base::LazyInstance<ProximityAuthFacade> g_proximity_auth_facade_instance =
70 LAZY_INSTANCE_INITIALIZER;
72 } // namespace
74 proximity_auth::ScreenlockBridge* GetScreenlockBridgeInstance() {
75 return g_proximity_auth_facade_instance.Pointer()->GetScreenlockBridge();