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

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

Issue 269573010: Download and cache kiosk app extension when it is added via kiosk mamangement ui. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove the change from chromeos_path.cc/h. Created 6 years, 7 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/logging.h" 12 #include "base/logging.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/prefs/pref_registry_simple.h" 14 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
15 #include "base/prefs/scoped_user_pref_update.h" 16 #include "base/prefs/scoped_user_pref_update.h"
16 #include "base/stl_util.h" 17 #include "base/stl_util.h"
17 #include "base/sys_info.h" 18 #include "base/sys_info.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" 20 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h"
20 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" 21 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h"
21 #include "chrome/browser/chromeos/login/user_manager.h" 22 #include "chrome/browser/chromeos/login/user_manager.h"
22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
23 #include "chrome/browser/chromeos/policy/device_local_account.h" 24 #include "chrome/browser/chromeos/policy/device_local_account.h"
24 #include "chrome/browser/chromeos/settings/cros_settings.h" 25 #include "chrome/browser/chromeos/settings/cros_settings.h"
25 #include "chrome/browser/chromeos/settings/owner_key_util.h" 26 #include "chrome/browser/chromeos/settings/owner_key_util.h"
27 #include "chrome/browser/extensions/external_provider_impl.h"
26 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/extensions/extension_constants.h"
30 #include "chromeos/chromeos_paths.h"
27 #include "chromeos/cryptohome/async_method_caller.h" 31 #include "chromeos/cryptohome/async_method_caller.h"
28 #include "chromeos/settings/cros_settings_names.h" 32 #include "chromeos/settings/cros_settings_names.h"
29 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
30 34
31 namespace chromeos { 35 namespace chromeos {
32 36
33 namespace { 37 namespace {
34 38
35 // Domain that is used for kiosk-app account IDs. 39 // Domain that is used for kiosk-app account IDs.
36 const char kKioskAppAccountDomain[] = "kiosk-apps"; 40 const char kKioskAppAccountDomain[] = "kiosk-apps";
(...skipping 10 matching lines...) Expand all
47 << " failed, return code: " << return_code; 51 << " failed, return code: " << return_code;
48 } 52 }
49 } 53 }
50 54
51 // Check for presence of machine owner public key file. 55 // Check for presence of machine owner public key file.
52 void CheckOwnerFilePresence(bool *present) { 56 void CheckOwnerFilePresence(bool *present) {
53 scoped_refptr<OwnerKeyUtil> util = OwnerKeyUtil::Create(); 57 scoped_refptr<OwnerKeyUtil> util = OwnerKeyUtil::Create();
54 *present = util->IsPublicKeyPresent(); 58 *present = util->IsPublicKeyPresent();
55 } 59 }
56 60
61 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() {
62 base::SequencedWorkerPool* pool = content::BrowserThread::GetBlockingPool();
63 CHECK(pool);
64 return pool->GetSequencedTaskRunnerWithShutdownBehavior(
65 pool->GetSequenceToken(), base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
66 }
67
57 } // namespace 68 } // namespace
58 69
59 // static 70 // static
60 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; 71 const char KioskAppManager::kKioskDictionaryName[] = "kiosk";
61 const char KioskAppManager::kKeyApps[] = "apps"; 72 const char KioskAppManager::kKeyApps[] = "apps";
62 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; 73 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state";
63 const char KioskAppManager::kIconCacheDir[] = "kiosk"; 74 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon";
75 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx";
64 76
65 // static 77 // static
66 static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER; 78 static base::LazyInstance<KioskAppManager> instance = LAZY_INSTANCE_INITIALIZER;
67 KioskAppManager* KioskAppManager::Get() { 79 KioskAppManager* KioskAppManager::Get() {
68 return instance.Pointer(); 80 return instance.Pointer();
69 } 81 }
70 82
71 // static 83 // static
72 void KioskAppManager::Shutdown() { 84 void KioskAppManager::Shutdown() {
73 if (instance == NULL) 85 if (instance == NULL)
74 return; 86 return;
75 87
76 instance.Pointer()->CleanUp(); 88 instance.Pointer()->CleanUp();
77 } 89 }
78 90
79 // static 91 // static
80 void KioskAppManager::RegisterPrefs(PrefRegistrySimple* registry) { 92 void KioskAppManager::RegisterPrefs(PrefRegistrySimple* registry) {
81 registry->RegisterDictionaryPref(kKioskDictionaryName); 93 registry->RegisterDictionaryPref(kKioskDictionaryName);
82 } 94 }
83 95
84 KioskAppManager::App::App(const KioskAppData& data) 96 KioskAppManager::App::App(const KioskAppData& data, bool is_extension_pending)
85 : app_id(data.app_id()), 97 : app_id(data.app_id()),
86 user_id(data.user_id()), 98 user_id(data.user_id()),
87 name(data.name()), 99 name(data.name()),
88 icon(data.icon()), 100 icon(data.icon()),
89 is_loading(data.IsLoading()) { 101 is_loading(data.IsLoading() || is_extension_pending) {
90 } 102 }
91 103
92 KioskAppManager::App::App() : is_loading(false) {} 104 KioskAppManager::App::App() : is_loading(false) {}
93 KioskAppManager::App::~App() {} 105 KioskAppManager::App::~App() {}
94 106
95 std::string KioskAppManager::GetAutoLaunchApp() const { 107 std::string KioskAppManager::GetAutoLaunchApp() const {
96 return auto_launch_app_id_; 108 return auto_launch_app_id_;
97 } 109 }
98 110
99 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) { 111 void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 297
286 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); 298 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts);
287 } 299 }
288 300
289 void KioskAppManager::GetApps(Apps* apps) const { 301 void KioskAppManager::GetApps(Apps* apps) const {
290 apps->clear(); 302 apps->clear();
291 apps->reserve(apps_.size()); 303 apps->reserve(apps_.size());
292 for (size_t i = 0; i < apps_.size(); ++i) { 304 for (size_t i = 0; i < apps_.size(); ++i) {
293 const KioskAppData& app_data = *apps_[i]; 305 const KioskAppData& app_data = *apps_[i];
294 if (app_data.status() != KioskAppData::STATUS_ERROR) 306 if (app_data.status() != KioskAppData::STATUS_ERROR)
295 apps->push_back(App(app_data)); 307 apps->push_back(App(
308 app_data, external_cache_->IsExtensionPending(app_data.app_id())));
296 } 309 }
297 } 310 }
298 311
299 bool KioskAppManager::GetApp(const std::string& app_id, App* app) const { 312 bool KioskAppManager::GetApp(const std::string& app_id, App* app) const {
300 const KioskAppData* data = GetAppData(app_id); 313 const KioskAppData* data = GetAppData(app_id);
301 if (!data) 314 if (!data)
302 return false; 315 return false;
303 316
304 *app = App(*data); 317 *app = App(*data, external_cache_->IsExtensionPending(app_id));
305 return true; 318 return true;
306 } 319 }
307 320
308 const base::RefCountedString* KioskAppManager::GetAppRawIcon( 321 const base::RefCountedString* KioskAppManager::GetAppRawIcon(
309 const std::string& app_id) const { 322 const std::string& app_id) const {
310 const KioskAppData* data = GetAppData(app_id); 323 const KioskAppData* data = GetAppData(app_id);
311 if (!data) 324 if (!data)
312 return NULL; 325 return NULL;
313 326
314 return data->raw_icon(); 327 return data->raw_icon();
(...skipping 30 matching lines...) Expand all
345 358
346 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) { 359 void KioskAppManager::AddObserver(KioskAppManagerObserver* observer) {
347 observers_.AddObserver(observer); 360 observers_.AddObserver(observer);
348 } 361 }
349 362
350 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) { 363 void KioskAppManager::RemoveObserver(KioskAppManagerObserver* observer) {
351 observers_.RemoveObserver(observer); 364 observers_.RemoveObserver(observer);
352 } 365 }
353 366
354 KioskAppManager::KioskAppManager() : ownership_established_(false) { 367 KioskAppManager::KioskAppManager() : ownership_established_(false) {
368 base::FilePath cache_dir;
369 GetKioskAppCrxCacheDir(&cache_dir);
370 external_cache_.reset(
371 new ExternalCache(cache_dir,
372 g_browser_process->system_request_context(),
373 GetBackgroundTaskRunner(),
374 this,
375 true /* always_check_updates */,
376 false /* wait_for_cache_initialization */));
377
355 UpdateAppData(); 378 UpdateAppData();
356 local_accounts_subscription_ = 379 local_accounts_subscription_ =
357 CrosSettings::Get()->AddSettingsObserver( 380 CrosSettings::Get()->AddSettingsObserver(
358 kAccountsPrefDeviceLocalAccounts, 381 kAccountsPrefDeviceLocalAccounts,
359 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); 382 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this)));
360 local_account_auto_login_id_subscription_ = 383 local_account_auto_login_id_subscription_ =
361 CrosSettings::Get()->AddSettingsObserver( 384 CrosSettings::Get()->AddSettingsObserver(
362 kAccountsPrefDeviceLocalAccountAutoLoginId, 385 kAccountsPrefDeviceLocalAccountAutoLoginId,
363 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this))); 386 base::Bind(&KioskAppManager::UpdateAppData, base::Unretained(this)));
364 } 387 }
365 388
366 KioskAppManager::~KioskAppManager() {} 389 KioskAppManager::~KioskAppManager() {}
367 390
368 void KioskAppManager::CleanUp() { 391 void KioskAppManager::CleanUp() {
369 local_accounts_subscription_.reset(); 392 local_accounts_subscription_.reset();
370 local_account_auto_login_id_subscription_.reset(); 393 local_account_auto_login_id_subscription_.reset();
371 apps_.clear(); 394 apps_.clear();
395 external_cache_.reset();
372 } 396 }
373 397
374 const KioskAppData* KioskAppManager::GetAppData( 398 const KioskAppData* KioskAppManager::GetAppData(
375 const std::string& app_id) const { 399 const std::string& app_id) const {
376 for (size_t i = 0; i < apps_.size(); ++i) { 400 for (size_t i = 0; i < apps_.size(); ++i) {
377 const KioskAppData* data = apps_[i]; 401 const KioskAppData* data = apps_[i];
378 if (data->app_id() == app_id) 402 if (data->app_id() == app_id)
379 return data; 403 return data;
380 } 404 }
381 405
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 old_apps.erase(old_it); 443 old_apps.erase(old_it);
420 } else { 444 } else {
421 KioskAppData* new_app = 445 KioskAppData* new_app =
422 new KioskAppData(this, it->kiosk_app_id, it->user_id); 446 new KioskAppData(this, it->kiosk_app_id, it->user_id);
423 apps_.push_back(new_app); // Takes ownership of |new_app|. 447 apps_.push_back(new_app); // Takes ownership of |new_app|.
424 new_app->Load(); 448 new_app->Load();
425 } 449 }
426 } 450 }
427 451
428 // Clears cache and deletes the remaining old data. 452 // Clears cache and deletes the remaining old data.
453 std::vector<std::string> apps_to_remove;
429 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); 454 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin();
430 it != old_apps.end(); ++it) { 455 it != old_apps.end(); ++it) {
431 it->second->ClearCache(); 456 it->second->ClearCache();
432 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( 457 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove(
433 it->second->user_id(), 458 it->second->user_id(),
434 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); 459 base::Bind(&OnRemoveAppCryptohomeComplete, it->first));
460 apps_to_remove.push_back(it->second->app_id());
435 } 461 }
436 STLDeleteValues(&old_apps); 462 STLDeleteValues(&old_apps);
463 external_cache_->RemoveExtensions(apps_to_remove);
464
465 // Request external_cache_ to download new apps and update the existing
466 // apps.
467 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
468 for (size_t i = 0; i < apps_.size(); ++i)
469 prefs->Set(apps_[i]->app_id(), new base::DictionaryValue);
470 external_cache_->UpdateExtensionsList(prefs.Pass());
437 471
438 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, 472 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_,
439 OnKioskAppsSettingsChanged()); 473 OnKioskAppsSettingsChanged());
440 } 474 }
441 475
442 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) { 476 void KioskAppManager::GetKioskAppIconCacheDir(base::FilePath* cache_dir) {
443 base::FilePath user_data_dir; 477 base::FilePath user_data_dir;
444 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); 478 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
445 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir); 479 *cache_dir = user_data_dir.AppendASCII(kIconCacheDir);
446 } 480 }
447 481
448 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) { 482 void KioskAppManager::OnKioskAppDataChanged(const std::string& app_id) {
449 FOR_EACH_OBSERVER(KioskAppManagerObserver, 483 FOR_EACH_OBSERVER(KioskAppManagerObserver,
450 observers_, 484 observers_,
451 OnKioskAppDataChanged(app_id)); 485 OnKioskAppDataChanged(app_id));
452 } 486 }
453 487
454 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) { 488 void KioskAppManager::OnKioskAppDataLoadFailure(const std::string& app_id) {
455 FOR_EACH_OBSERVER(KioskAppManagerObserver, 489 FOR_EACH_OBSERVER(KioskAppManagerObserver,
456 observers_, 490 observers_,
457 OnKioskAppDataLoadFailure(app_id)); 491 OnKioskAppDataLoadFailure(app_id));
458 } 492 }
459 493
494 void KioskAppManager::OnExtensionListsUpdated(
495 const base::DictionaryValue* prefs) {
496 }
497
498 void KioskAppManager::OnExtensionLoadedInCache(const std::string& id) {
499 KioskAppData* app_data = GetAppDataMutable(id);
500 if (!app_data)
501 return;
502 OnKioskAppDataChanged(id);
503 }
504
505 void KioskAppManager::OnExtensionDownloadFailed(
506 const std::string& id,
507 extensions::ExtensionDownloaderDelegate::Error error) {
508 KioskAppData* app_data = GetAppDataMutable(id);
509 if (!app_data)
510 return;
511 OnKioskAppDataLoadFailure(id);
512 }
513
460 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const { 514 KioskAppManager::AutoLoginState KioskAppManager::GetAutoLoginState() const {
461 PrefService* prefs = g_browser_process->local_state(); 515 PrefService* prefs = g_browser_process->local_state();
462 const base::DictionaryValue* dict = 516 const base::DictionaryValue* dict =
463 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName); 517 prefs->GetDictionary(KioskAppManager::kKioskDictionaryName);
464 int value; 518 int value;
465 if (!dict->GetInteger(kKeyAutoLoginState, &value)) 519 if (!dict->GetInteger(kKeyAutoLoginState, &value))
466 return AUTOLOGIN_NONE; 520 return AUTOLOGIN_NONE;
467 521
468 return static_cast<AutoLoginState>(value); 522 return static_cast<AutoLoginState>(value);
469 } 523 }
470 524
471 void KioskAppManager::SetAutoLoginState(AutoLoginState state) { 525 void KioskAppManager::SetAutoLoginState(AutoLoginState state) {
472 PrefService* prefs = g_browser_process->local_state(); 526 PrefService* prefs = g_browser_process->local_state();
473 DictionaryPrefUpdate dict_update(prefs, 527 DictionaryPrefUpdate dict_update(prefs,
474 KioskAppManager::kKioskDictionaryName); 528 KioskAppManager::kKioskDictionaryName);
475 dict_update->SetInteger(kKeyAutoLoginState, state); 529 dict_update->SetInteger(kKeyAutoLoginState, state);
476 prefs->CommitPendingWrite(); 530 prefs->CommitPendingWrite();
477 } 531 }
478 532
533 void KioskAppManager::GetKioskAppCrxCacheDir(base::FilePath* cache_dir) {
534 base::FilePath user_data_dir;
535 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
536 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir);
537 }
538
479 } // namespace chromeos 539 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/app_mode/kiosk_app_manager.h ('k') | chrome/browser/chromeos/extensions/external_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698