| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/app_mode/kiosk_app_manager.h" | 5 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/chromeos/chromeos_version.h" | 11 #include "base/chromeos/chromeos_version.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | |
| 19 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 19 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager.h" | 20 #include "chrome/browser/chromeos/login/user_manager.h" |
| 22 #include "chrome/browser/chromeos/policy/device_local_account.h" | 21 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 23 #include "chrome/browser/chromeos/settings/cros_settings.h" | 22 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 24 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 23 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 25 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 24 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
| 26 #include "chrome/browser/policy/browser_policy_connector.h" | 25 #include "chrome/browser/policy/browser_policy_connector.h" |
| 27 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 26 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 28 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 92 |
| 94 KioskAppManager::App::App() : is_loading(false) {} | 93 KioskAppManager::App::App() : is_loading(false) {} |
| 95 KioskAppManager::App::~App() {} | 94 KioskAppManager::App::~App() {} |
| 96 | 95 |
| 97 std::string KioskAppManager::GetAutoLaunchApp() const { | 96 std::string KioskAppManager::GetAutoLaunchApp() const { |
| 98 return auto_launch_app_id_; | 97 return auto_launch_app_id_; |
| 99 } | 98 } |
| 100 | 99 |
| 101 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { | 100 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { |
| 102 SetAutoLoginState(AUTOLOGIN_REQUESTED); | 101 SetAutoLoginState(AUTOLOGIN_REQUESTED); |
| 103 // Clean first, so the proper change notifications are triggered even | 102 // Clean first, so the proper change callbacks are triggered even |
| 104 // if we are only changing AutoLoginState here. | 103 // if we are only changing AutoLoginState here. |
| 105 if (!auto_launch_app_id_.empty()) { | 104 if (!auto_launch_app_id_.empty()) { |
| 106 CrosSettings::Get()->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, | 105 CrosSettings::Get()->SetString(kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 107 std::string()); | 106 std::string()); |
| 108 } | 107 } |
| 109 | 108 |
| 110 CrosSettings::Get()->SetString( | 109 CrosSettings::Get()->SetString( |
| 111 kAccountsPrefDeviceLocalAccountAutoLoginId, | 110 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 112 app_id.empty() ? std::string() : GenerateKioskAppAccountId(app_id)); | 111 app_id.empty() ? std::string() : GenerateKioskAppAccountId(app_id)); |
| 113 CrosSettings::Get()->SetInteger( | 112 CrosSettings::Get()->SetInteger( |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { | 306 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { |
| 308 observers_.AddObserver(observer); | 307 observers_.AddObserver(observer); |
| 309 } | 308 } |
| 310 | 309 |
| 311 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 310 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
| 312 observers_.RemoveObserver(observer); | 311 observers_.RemoveObserver(observer); |
| 313 } | 312 } |
| 314 | 313 |
| 315 KioskAppManager::KioskAppManager() : ownership_established_(false) { | 314 KioskAppManager::KioskAppManager() : ownership_established_(false) { |
| 316 UpdateAppData(); | 315 UpdateAppData(); |
| 317 CrosSettings::Get()->AddSettingsObserver( | 316 local_accounts_subscription_ = |
| 318 kAccountsPrefDeviceLocalAccounts, this); | 317 CrosSettings::Get()->AddSettingsObserver( |
| 319 CrosSettings::Get()->AddSettingsObserver( | 318 kAccountsPrefDeviceLocalAccounts, |
| 320 kAccountsPrefDeviceLocalAccountAutoLoginId, this); | 319 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 320 local_account_auto_login_id_subscription_ = |
| 321 CrosSettings::Get()->AddSettingsObserver( |
| 322 kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 323 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); |
| 321 } | 324 } |
| 322 | 325 |
| 323 KioskAppManager::~KioskAppManager() {} | 326 KioskAppManager::~KioskAppManager() {} |
| 324 | 327 |
| 325 void KioskAppManager::CleanUp() { | 328 void KioskAppManager::CleanUp() { |
| 326 CrosSettings::Get()->RemoveSettingsObserver( | 329 local_accounts_subscription_.reset(); |
| 327 kAccountsPrefDeviceLocalAccounts, this); | 330 local_account_auto_login_id_subscription_.reset(); |
| 328 CrosSettings::Get()->RemoveSettingsObserver( | |
| 329 kAccountsPrefDeviceLocalAccountAutoLoginId, this); | |
| 330 apps_.clear(); | 331 apps_.clear(); |
| 331 } | 332 } |
| 332 | 333 |
| 333 const KioskAppData* KioskAppManager::GetAppData( | 334 const KioskAppData* KioskAppManager::GetAppData( |
| 334 const std::string& app_id) const { | 335 const std::string& app_id) const { |
| 335 for (size_t i = 0; i < apps_.size(); ++i) { | 336 for (size_t i = 0; i < apps_.size(); ++i) { |
| 336 const KioskAppData* data = apps_[i]; | 337 const KioskAppData* data = apps_[i]; |
| 337 if (data->app_id() == app_id) | 338 if (data->app_id() == app_id) |
| 338 return data; | 339 return data; |
| 339 } | 340 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 388 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 388 it->second->user_id(), | 389 it->second->user_id(), |
| 389 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); | 390 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); |
| 390 } | 391 } |
| 391 STLDeleteValues(&old_apps); | 392 STLDeleteValues(&old_apps); |
| 392 | 393 |
| 393 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, | 394 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
| 394 OnKioskAppsSettingsChanged()); | 395 OnKioskAppsSettingsChanged()); |
| 395 } | 396 } |
| 396 | 397 |
| 397 void KioskAppManager::Observe(int type, | |
| 398 const content::NotificationSource& source, | |
| 399 const content::NotificationDetails& details) { | |
| 400 DCHECK_EQ(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED, type); | |
| 401 UpdateAppData(); | |
| 402 } | |
| 403 | |
| 404 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { | 398 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { |
| 405 base::FilePath user_data_dir; | 399 base::FilePath user_data_dir; |
| 406 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 400 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 407 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); | 401 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); |
| 408 } | 402 } |
| 409 | 403 |
| 410 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { | 404 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { |
| 411 FOR_EACH_OBSERVER(KioskAppManagerObserver, | 405 FOR_EACH_OBSERVER(KioskAppManagerObserver, |
| 412 observers_, | 406 observers_, |
| 413 OnKioskAppDataChanged(app_id)); | 407 OnKioskAppDataChanged(app_id)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 433 | 427 |
| 434 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { | 428 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { |
| 435 PrefService* prefs = g_browser_process->local_state(); | 429 PrefService* prefs = g_browser_process->local_state(); |
| 436 DictionaryPrefUpdate dict_update(prefs, | 430 DictionaryPrefUpdate dict_update(prefs, |
| 437 KioskAppManager::kKioskDictionaryName); | 431 KioskAppManager::kKioskDictionaryName); |
| 438 dict_update->SetInteger(kKeyAutoLoginState, state); | 432 dict_update->SetInteger(kKeyAutoLoginState, state); |
| 439 prefs->CommitPendingWrite(); | 433 prefs->CommitPendingWrite(); |
| 440 } | 434 } |
| 441 | 435 |
| 442 } // namespace chromeos | 436 } // namespace chromeos |
| OLD | NEW |