OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/easy_unlock_service.h" | 5 #include "chrome/browser/signin/easy_unlock_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/component_loader.h" | 13 #include "chrome/browser/extensions/component_loader.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
16 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 17 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 18 #include "chrome/browser/signin/screenlock_bridge.h" |
17 #include "chrome/browser/ui/extensions/application_launch.h" | 19 #include "chrome/browser/ui/extensions/application_launch.h" |
18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
22 #include "extensions/common/one_shot_event.h" | 24 #include "extensions/common/one_shot_event.h" |
23 #include "grit/browser_resources.h" | 25 #include "grit/browser_resources.h" |
24 | 26 |
25 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
26 #include "chrome/browser/chromeos/login/users/user_manager.h" | 28 #include "chrome/browser/chromeos/login/users/user_manager.h" |
(...skipping 11 matching lines...) Expand all Loading... |
38 } | 40 } |
39 | 41 |
40 } // namespace | 42 } // namespace |
41 | 43 |
42 // static | 44 // static |
43 EasyUnlockService* EasyUnlockService::Get(Profile* profile) { | 45 EasyUnlockService* EasyUnlockService::Get(Profile* profile) { |
44 return EasyUnlockServiceFactory::GetForProfile(profile); | 46 return EasyUnlockServiceFactory::GetForProfile(profile); |
45 } | 47 } |
46 | 48 |
47 EasyUnlockService::EasyUnlockService(Profile* profile) | 49 EasyUnlockService::EasyUnlockService(Profile* profile) |
48 : profile_(profile), weak_ptr_factory_(this) { | 50 : profile_(profile), |
| 51 weak_ptr_factory_(this) { |
49 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 52 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
50 FROM_HERE, | 53 FROM_HERE, |
51 base::Bind(&EasyUnlockService::Initialize, | 54 base::Bind(&EasyUnlockService::Initialize, |
52 weak_ptr_factory_.GetWeakPtr())); | 55 weak_ptr_factory_.GetWeakPtr())); |
53 } | 56 } |
54 | 57 |
55 EasyUnlockService::~EasyUnlockService() { | 58 EasyUnlockService::~EasyUnlockService() { |
56 } | 59 } |
57 | 60 |
58 // static | 61 // static |
(...skipping 22 matching lines...) Expand all Loading... |
81 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 84 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
82 const extensions::Extension* extension = | 85 const extensions::Extension* extension = |
83 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); | 86 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); |
84 | 87 |
85 OpenApplication(AppLaunchParams( | 88 OpenApplication(AppLaunchParams( |
86 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | 89 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); |
87 } | 90 } |
88 | 91 |
89 bool EasyUnlockService::IsAllowed() { | 92 bool EasyUnlockService::IsAllowed() { |
90 #if defined(OS_CHROMEOS) | 93 #if defined(OS_CHROMEOS) |
91 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) | 94 if (!chromeos::UserManager::Get()->IsLoggedInAsRegularUser()) |
92 return false; | 95 return false; |
93 | 96 |
94 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile_)) | 97 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile_)) |
95 return false; | 98 return false; |
96 | 99 |
97 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) | 100 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) |
98 return false; | 101 return false; |
99 | 102 |
100 // It is only disabled when the trial exists and is in "Disable" group. | 103 // It is only disabled when the trial exists and is in "Disable" group. |
101 return base::FieldTrialList::FindFullName("EasyUnlock") != "Disable"; | 104 return base::FieldTrialList::FindFullName("EasyUnlock") != "Disable"; |
102 #else | 105 #else |
103 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 106 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
104 return false; | 107 return false; |
105 #endif | 108 #endif |
106 } | 109 } |
107 | 110 |
| 111 |
| 112 EasyUnlockScreenlockStateHandler* |
| 113 EasyUnlockService::GetScreenlockStateHandler() { |
| 114 if (!IsAllowed()) |
| 115 return NULL; |
| 116 if (!screenlock_state_handler_) { |
| 117 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
| 118 ScreenlockBridge::GetAuthenticatedUserEmail(profile_), |
| 119 profile_->GetPrefs(), |
| 120 ScreenlockBridge::Get())); |
| 121 } |
| 122 return screenlock_state_handler_.get(); |
| 123 } |
| 124 |
108 void EasyUnlockService::Initialize() { | 125 void EasyUnlockService::Initialize() { |
109 registrar_.Init(profile_->GetPrefs()); | 126 registrar_.Init(profile_->GetPrefs()); |
110 registrar_.Add( | 127 registrar_.Add( |
111 prefs::kEasyUnlockAllowed, | 128 prefs::kEasyUnlockAllowed, |
112 base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this))); | 129 base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this))); |
113 OnPrefsChanged(); | 130 OnPrefsChanged(); |
114 } | 131 } |
115 | 132 |
116 void EasyUnlockService::LoadApp() { | 133 void EasyUnlockService::LoadApp() { |
117 DCHECK(IsAllowed()); | 134 DCHECK(IsAllowed()); |
(...skipping 18 matching lines...) Expand all Loading... |
136 ->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); | 153 ->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); |
137 } | 154 } |
138 #endif // defined(GOOGLE_CHROME_BUILD) | 155 #endif // defined(GOOGLE_CHROME_BUILD) |
139 } | 156 } |
140 | 157 |
141 void EasyUnlockService::UnloadApp() { | 158 void EasyUnlockService::UnloadApp() { |
142 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); | 159 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); |
143 } | 160 } |
144 | 161 |
145 void EasyUnlockService::OnPrefsChanged() { | 162 void EasyUnlockService::OnPrefsChanged() { |
146 if (IsAllowed()) | 163 if (IsAllowed()) { |
147 LoadApp(); | 164 LoadApp(); |
148 else | 165 } else { |
149 UnloadApp(); | 166 UnloadApp(); |
| 167 // Reset the screenlock state handler to make sure Screenlock state set |
| 168 // by Easy Unlock app is reset. |
| 169 screenlock_state_handler_.reset(); |
| 170 } |
150 } | 171 } |
OLD | NEW |