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_service_factory.h" | 16 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
17 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
22 #include "extensions/common/one_shot_event.h" | 22 #include "extensions/common/one_shot_event.h" |
23 #include "grit/browser_resources.h" | 23 #include "grit/browser_resources.h" |
24 | 24 |
25 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
26 #include "chrome/browser/chromeos/login/users/user_manager.h" | 26 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 27 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
27 #endif | 28 #endif |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 extensions::ComponentLoader* GetComponentLoader( | 32 extensions::ComponentLoader* GetComponentLoader( |
32 content::BrowserContext* context) { | 33 content::BrowserContext* context) { |
33 extensions::ExtensionSystem* extension_system = | 34 extensions::ExtensionSystem* extension_system = |
34 extensions::ExtensionSystem::Get(context); | 35 extensions::ExtensionSystem::Get(context); |
35 ExtensionService* extension_service = extension_system->extension_service(); | 36 ExtensionService* extension_service = extension_system->extension_service(); |
36 return extension_service->component_loader(); | 37 return extension_service->component_loader(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 84 |
84 OpenApplication(AppLaunchParams( | 85 OpenApplication(AppLaunchParams( |
85 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | 86 profile_, extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); |
86 } | 87 } |
87 | 88 |
88 bool EasyUnlockService::IsAllowed() { | 89 bool EasyUnlockService::IsAllowed() { |
89 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
90 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) | 91 if (chromeos::UserManager::Get()->IsLoggedInAsGuest()) |
91 return false; | 92 return false; |
92 | 93 |
| 94 if (!chromeos::ProfileHelper::IsPrimaryProfile(profile_)) |
| 95 return false; |
| 96 |
93 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) | 97 if (!profile_->GetPrefs()->GetBoolean(prefs::kEasyUnlockAllowed)) |
94 return false; | 98 return false; |
95 | 99 |
96 // It is only disabled when the trial exists and is in "Disable" group. | 100 // It is only disabled when the trial exists and is in "Disable" group. |
97 return base::FieldTrialList::FindFullName("EasyUnlock") != "Disable"; | 101 return base::FieldTrialList::FindFullName("EasyUnlock") != "Disable"; |
98 #else | 102 #else |
99 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 103 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
100 return false; | 104 return false; |
101 #endif | 105 #endif |
102 } | 106 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void EasyUnlockService::UnloadApp() { | 141 void EasyUnlockService::UnloadApp() { |
138 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); | 142 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); |
139 } | 143 } |
140 | 144 |
141 void EasyUnlockService::OnPrefsChanged() { | 145 void EasyUnlockService::OnPrefsChanged() { |
142 if (IsAllowed()) | 146 if (IsAllowed()) |
143 LoadApp(); | 147 LoadApp(); |
144 else | 148 else |
145 UnloadApp(); | 149 UnloadApp(); |
146 } | 150 } |
OLD | NEW |