Chromium Code Reviews| 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 return screenlock_state_handler_.get(); | |
| 115 } | |
| 116 | |
| 108 void EasyUnlockService::Initialize() { | 117 void EasyUnlockService::Initialize() { |
| 109 registrar_.Init(profile_->GetPrefs()); | 118 registrar_.Init(profile_->GetPrefs()); |
| 110 registrar_.Add( | 119 registrar_.Add( |
| 111 prefs::kEasyUnlockAllowed, | 120 prefs::kEasyUnlockAllowed, |
| 112 base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this))); | 121 base::Bind(&EasyUnlockService::OnPrefsChanged, base::Unretained(this))); |
| 113 OnPrefsChanged(); | 122 OnPrefsChanged(); |
| 114 } | 123 } |
| 115 | 124 |
| 116 void EasyUnlockService::LoadApp() { | 125 bool EasyUnlockService::LoadApp() { |
| 117 DCHECK(IsAllowed()); | 126 DCHECK(IsAllowed()); |
| 118 | 127 |
| 119 #if defined(GOOGLE_CHROME_BUILD) | 128 #if defined(GOOGLE_CHROME_BUILD) |
| 120 base::FilePath easy_unlock_path; | 129 base::FilePath easy_unlock_path; |
| 121 #if defined(OS_CHROMEOS) | 130 #if defined(OS_CHROMEOS) |
| 122 easy_unlock_path = base::FilePath("/usr/share/chromeos-assets/easy_unlock"); | 131 easy_unlock_path = base::FilePath("/usr/share/chromeos-assets/easy_unlock"); |
| 123 #endif // defined(OS_CHROMEOS) | 132 #endif // defined(OS_CHROMEOS) |
| 124 | 133 |
| 125 #ifndef NDEBUG | 134 #ifndef NDEBUG |
| 126 // Only allow app path override switch for debug build. | 135 // Only allow app path override switch for debug build. |
| 127 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 136 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 128 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { | 137 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { |
| 129 easy_unlock_path = | 138 easy_unlock_path = |
| 130 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); | 139 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); |
| 131 } | 140 } |
| 132 #endif // !defined(NDEBUG) | 141 #endif // !defined(NDEBUG) |
| 133 | 142 |
| 134 if (!easy_unlock_path.empty()) { | 143 if (!easy_unlock_path.empty()) { |
| 135 GetComponentLoader(profile_) | 144 std::string id = GetComponentLoader(profile_) |
| 136 ->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); | 145 ->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); |
| 146 return !id.empty(); | |
| 137 } | 147 } |
| 138 #endif // defined(GOOGLE_CHROME_BUILD) | 148 #endif // defined(GOOGLE_CHROME_BUILD) |
| 149 | |
| 150 return false; | |
| 139 } | 151 } |
| 140 | 152 |
| 141 void EasyUnlockService::UnloadApp() { | 153 void EasyUnlockService::UnloadApp() { |
| 142 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); | 154 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); |
| 143 } | 155 } |
| 144 | 156 |
| 145 void EasyUnlockService::OnPrefsChanged() { | 157 void EasyUnlockService::OnPrefsChanged() { |
| 146 if (IsAllowed()) | 158 if (IsAllowed()) { |
| 147 LoadApp(); | 159 if (LoadApp()) { |
| 148 else | 160 // If the app is loaded, set up screenlock_state_handler_. |
| 161 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( | |
| 162 ScreenlockBridge::GetAuthenticatedUserEmail(profile_), | |
|
xiyuan
2014/08/12 21:51:49
I would prefer to what we have in PS24, where |scr
tbarzic
2014/08/12 22:12:52
ok, reverting this back. I'll keep reset before Un
xiyuan
2014/08/12 22:14:39
Sounds good.
| |
| 163 profile_->GetPrefs(), | |
| 164 ScreenlockBridge::Get())); | |
| 165 } | |
| 166 } else { | |
| 167 screenlock_state_handler_.reset(); | |
| 149 UnloadApp(); | 168 UnloadApp(); |
| 169 } | |
| 150 } | 170 } |
| OLD | NEW |