Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(660)

Side by Side Diff: chrome/browser/chromeos/app_mode/kiosk_app_manager.cc

Issue 300843013: Install and launch kiosk app from cached crx file at start up. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the new test file from cl. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 app_data->LoadFromInstalledApp(profile, app); 358 app_data->LoadFromInstalledApp(profile, app);
357 } 359 }
358 360
359 void KioskAppManager::RetryFailedAppDataFetch() { 361 void KioskAppManager::RetryFailedAppDataFetch() {
360 for (size_t i = 0; i < apps_.size(); ++i) { 362 for (size_t i = 0; i < apps_.size(); ++i) {
361 if (apps_[i]->status() == KioskAppData::STATUS_ERROR) 363 if (apps_[i]->status() == KioskAppData::STATUS_ERROR)
362 apps_[i]->Load(); 364 apps_[i]->Load();
363 } 365 }
364 } 366 }
365 367
368 bool KioskAppManager::HasCachedCrx(const std::string& app_id) const {
369 base::FilePath crx_path;
370 std::string version;
371 return GetCachedCrx(app_id, &crx_path, &version);
372 }
373
366 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { 374 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) {
367 observers_.AddObserver(observer); 375 observers_.AddObserver(observer);
368 } 376 }
369 377
370 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { 378 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) {
371 observers_.RemoveObserver(observer); 379 observers_.RemoveObserver(observer);
372 } 380 }
373 381
374 KioskAppManager::KioskAppManager() : ownership_established_(false) { 382 extensions::ExternalLoader* KioskAppManager::CreateExternalLoader() {
383 if (external_loader_created_) {
384 NOTREACHED();
385 return NULL;
386 }
387 external_loader_created_ = true;
388 KioskAppExternalLoader* loader = new KioskAppExternalLoader();
389 external_loader_ = loader->AsWeakPtr();
390
391 return loader;
392 }
393
394 void KioskAppManager::InstallFromCache(const std::string& id) {
395 const base::DictionaryValue* extension = NULL;
396 if (external_cache_->cached_extensions()->GetDictionary(id, &extension)) {
397 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
398 base::DictionaryValue* extension_copy = extension->DeepCopy();
399 prefs->Set(id, extension_copy);
400 external_loader_->SetCurrentAppExtensions(prefs.Pass());
401 } else {
402 LOG(ERROR) << "Can't find app in the cached externsions"
403 << " id = " << id;
404 }
405 }
406
407 void KioskAppManager::UpdateExternalCache() {
408 UpdateAppData();
409 }
410
411 KioskAppManager::KioskAppManager()
412 : ownership_established_(false), external_loader_created_(false) {
375 base::FilePath cache_dir; 413 base::FilePath cache_dir;
376 GetCrxCacheDir(&cache_dir); 414 GetCrxCacheDir(&cache_dir);
377 external_cache_.reset( 415 external_cache_.reset(
378 new ExternalCache(cache_dir, 416 new ExternalCache(cache_dir,
379 g_browser_process->system_request_context(), 417 g_browser_process->system_request_context(),
380 GetBackgroundTaskRunner(), 418 GetBackgroundTaskRunner(),
381 this, 419 this,
382 true /* always_check_updates */, 420 true /* always_check_updates */,
383 false /* wait_for_cache_initialization */)); 421 false /* wait_for_cache_initialization */));
384
385 UpdateAppData(); 422 UpdateAppData();
386 local_accounts_subscription_ = 423 local_accounts_subscription_ =
387 CrosSettings::Get()->AddSettingsObserver( 424 CrosSettings::Get()->AddSettingsObserver(
388 kAccountsPrefDeviceLocalAccounts, 425 kAccountsPrefDeviceLocalAccounts,
389 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); 426 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this)));
390 local_account_auto_login_id_subscription_ = 427 local_account_auto_login_id_subscription_ =
391 CrosSettings::Get()->AddSettingsObserver( 428 CrosSettings::Get()->AddSettingsObserver(
392 kAccountsPrefDeviceLocalAccountAutoLoginId, 429 kAccountsPrefDeviceLocalAccountAutoLoginId,
393 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); 430 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this)));
394 } 431 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 } 577 }
541 578
542 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) { 579 void KioskAppManager::GetCrxCacheDir(base::FilePath* cache_dir) {
543 base::FilePath user_data_dir; 580 base::FilePath user_data_dir;
544 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); 581 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
545 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); 582 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir);
546 } 583 }
547 584
548 bool KioskAppManager::GetCachedCrx(const std::string& app_id, 585 bool KioskAppManager::GetCachedCrx(const std::string& app_id,
549 base::FilePath* file_path, 586 base::FilePath* file_path,
550 std::string* version) { 587 std::string* version) const {
551 return external_cache_->GetExtension(app_id, file_path, version); 588 return external_cache_->GetExtension(app_id, file_path, version);
552 } 589 }
553 590
554 } // namespace chromeos 591 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698