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/files/file_path.h" | 11 #include "base/files/file_path.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/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
| 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
22 #include "chrome/browser/chromeos/login/users/user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/user_manager.h" |
23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 24 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
24 #include "chrome/browser/chromeos/policy/device_local_account.h" | 25 #include "chrome/browser/chromeos/policy/device_local_account.h" |
25 #include "chrome/browser/chromeos/settings/cros_settings.h" | 26 #include "chrome/browser/chromeos/settings/cros_settings.h" |
26 #include "chrome/browser/chromeos/settings/owner_key_util.h" | 27 #include "chrome/browser/chromeos/settings/owner_key_util.h" |
| 28 #include "chrome/browser/extensions/external_loader.h" |
27 #include "chrome/browser/extensions/external_provider_impl.h" | 29 #include "chrome/browser/extensions/external_provider_impl.h" |
28 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
30 #include "chromeos/chromeos_paths.h" | 32 #include "chromeos/chromeos_paths.h" |
31 #include "chromeos/cryptohome/async_method_caller.h" | 33 #include "chromeos/cryptohome/async_method_caller.h" |
32 #include "chromeos/settings/cros_settings_names.h" | 34 #include "chromeos/settings/cros_settings_names.h" |
33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
34 | 36 |
35 namespace chromeos { | 37 namespace chromeos { |
36 | 38 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 const std::string& app_id, | 351 const std::string& app_id, |
350 Profile* profile, | 352 Profile* profile, |
351 const extensions::Extension* app) { | 353 const extensions::Extension* app) { |
352 KioskAppData* app_data = GetAppDataMutable(app_id); | 354 KioskAppData* app_data = GetAppDataMutable(app_id); |
353 if (!app_data) | 355 if (!app_data) |
354 return; | 356 return; |
355 | 357 |
356 app_data->LoadFromInstalledApp(profile, app); | 358 app_data->LoadFromInstalledApp(profile, app); |
357 } | 359 } |
358 | 360 |
| 361 bool KioskAppManager::GetCachedCrx(const std::string& app_id, |
| 362 base::FilePath* file_path, |
| 363 std::string* version) { |
| 364 return external_cache_->GetExtension(app_id, file_path, version); |
| 365 } |
| 366 |
| 367 bool KioskAppManager::IsExtensionPendingForCache(const std::string& id) { |
| 368 return external_cache_->IsExtensionPending(id) && |
| 369 !external_cache_->IsExtensionDownloadFailed(id); |
| 370 } |
| 371 |
| 372 bool KioskAppManager::IsExtensionPendingForUpdateCheck(const std::string& id) { |
| 373 return external_cache_->IsExtensionPendingForUpdateCheck(id); |
| 374 } |
| 375 |
359 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { | 376 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { |
360 observers_.AddObserver(observer); | 377 observers_.AddObserver(observer); |
361 } | 378 } |
362 | 379 |
363 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { | 380 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { |
364 observers_.RemoveObserver(observer); | 381 observers_.RemoveObserver(observer); |
365 } | 382 } |
366 | 383 |
367 KioskAppManager::KioskAppManager() : ownership_established_(false) { | 384 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() { |
| 385 if (external_loader_created_) { |
| 386 NOTREACHED(); |
| 387 return NULL; |
| 388 } |
| 389 external_loader_created_ = true; |
| 390 KioskAppExternalLoader* loader = new KioskAppExternalLoader(); |
| 391 external_loader_ = loader->AsWeakPtr(); |
| 392 |
| 393 return loader; |
| 394 } |
| 395 |
| 396 void KioskAppManager::InstallKioskApp(const std::string& id) { |
| 397 const base::DictionaryValue* extension = NULL; |
| 398 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) { |
| 399 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 400 base::DictionaryValue* extension_copy = extension->DeepCopy(); |
| 401 prefs->Set(id, extension_copy); |
| 402 external_loader_->SetCurrentAppExtensions(prefs.Pass()); |
| 403 } else { |
| 404 LOG(ERROR) << "Can't find app in the cached externsions" |
| 405 << " id = " << id; |
| 406 } |
| 407 } |
| 408 |
| 409 KioskAppManager::KioskAppManager() |
| 410 : ownership_established_(false), external_loader_created_(false) { |
368 base::FilePath cache_dir; | 411 base::FilePath cache_dir; |
369 GetCrxCacheDir(&cache_dir); | 412 GetCrxCacheDir(&cache_dir); |
370 external_cache_.reset( | 413 external_cache_.reset( |
371 new ExternalCache(cache_dir, | 414 new ExternalCache(cache_dir, |
372 g_browser_process->system_request_context(), | 415 g_browser_process->system_request_context(), |
373 GetBackgroundTaskRunner(), | 416 GetBackgroundTaskRunner(), |
374 this, | 417 this, |
375 true /* always_check_updates */, | 418 true /* always_check_updates */, |
376 false /* wait_for_cache_initialization */)); | 419 false /* wait_for_cache_initialization */)); |
377 | 420 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 dict_update->SetInteger(kKeyAutoLoginState, state); | 572 dict_update->SetInteger(kKeyAutoLoginState, state); |
530 prefs->CommitPendingWrite(); | 573 prefs->CommitPendingWrite(); |
531 } | 574 } |
532 | 575 |
533 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { | 576 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { |
534 base::FilePath user_data_dir; | 577 base::FilePath user_data_dir; |
535 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 578 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
536 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); | 579 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); |
537 } | 580 } |
538 | 581 |
539 bool KioskAppManager::GetCachedCrx(const std::string& app_id, | |
540 base::FilePath* file_path, | |
541 std::string* version) { | |
542 return external_cache_->GetExtension(app_id, file_path, version); | |
543 } | |
544 | |
545 } // namespace chromeos | 582 } // namespace chromeos |
OLD | NEW |