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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/browser/chromeos/settings/cros_settings.h" | 28 #include "chrome/browser/chromeos/settings/cros_settings.h" |
29 #include "chrome/browser/extensions/external_loader.h" | 29 #include "chrome/browser/extensions/external_loader.h" |
30 #include "chrome/browser/extensions/external_provider_impl.h" | 30 #include "chrome/browser/extensions/external_provider_impl.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 32 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chromeos/chromeos_paths.h" | 33 #include "chromeos/chromeos_paths.h" |
34 #include "chromeos/cryptohome/async_method_caller.h" | 34 #include "chromeos/cryptohome/async_method_caller.h" |
35 #include "chromeos/settings/cros_settings_names.h" | 35 #include "chromeos/settings/cros_settings_names.h" |
36 #include "components/ownership/owner_key_util.h" | 36 #include "components/ownership/owner_key_util.h" |
37 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 38 #include "extensions/common/extension_urls.h" |
38 | 39 |
39 namespace chromeos { | 40 namespace chromeos { |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
43 // Domain that is used for kiosk-app account IDs. | 44 // Domain that is used for kiosk-app account IDs. |
44 const char kKioskAppAccountDomain[] = "kiosk-apps"; | 45 const char kKioskAppAccountDomain[] = "kiosk-apps"; |
45 | 46 |
46 std::string GenerateKioskAppAccountId(const std::string& app_id) { | 47 std::string GenerateKioskAppAccountId(const std::string& app_id) { |
47 return app_id + '@' + kKioskAppAccountDomain; | 48 return app_id + '@' + kKioskAppAccountDomain; |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (it->type == policy::DeviceLocalAccount::TYPE_KIOSK_APP && | 269 if (it->type == policy::DeviceLocalAccount::TYPE_KIOSK_APP && |
269 it->kiosk_app_id == app_id) { | 270 it->kiosk_app_id == app_id) { |
270 return; | 271 return; |
271 } | 272 } |
272 } | 273 } |
273 | 274 |
274 // Add the new account. | 275 // Add the new account. |
275 device_local_accounts.push_back(policy::DeviceLocalAccount( | 276 device_local_accounts.push_back(policy::DeviceLocalAccount( |
276 policy::DeviceLocalAccount::TYPE_KIOSK_APP, | 277 policy::DeviceLocalAccount::TYPE_KIOSK_APP, |
277 GenerateKioskAppAccountId(app_id), | 278 GenerateKioskAppAccountId(app_id), |
278 app_id)); | 279 app_id, |
| 280 std::string())); |
279 | 281 |
280 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); | 282 policy::SetDeviceLocalAccounts(CrosSettings::Get(), device_local_accounts); |
281 } | 283 } |
282 | 284 |
283 void KioskAppManager::RemoveApp(const std::string& app_id) { | 285 void KioskAppManager::RemoveApp(const std::string& app_id) { |
284 // Resets auto launch app if it is the removed app. | 286 // Resets auto launch app if it is the removed app. |
285 if (auto_launch_app_id_ == app_id) | 287 if (auto_launch_app_id_ == app_id) |
286 SetAutoLaunchApp(std::string()); | 288 SetAutoLaunchApp(std::string()); |
287 | 289 |
288 std::vector<policy::DeviceLocalAccount> device_local_accounts = | 290 std::vector<policy::DeviceLocalAccount> device_local_accounts = |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 policy::GetDeviceLocalAccounts(CrosSettings::Get()); | 512 policy::GetDeviceLocalAccounts(CrosSettings::Get()); |
511 for (std::vector<policy::DeviceLocalAccount>::const_iterator | 513 for (std::vector<policy::DeviceLocalAccount>::const_iterator |
512 it = device_local_accounts.begin(); | 514 it = device_local_accounts.begin(); |
513 it != device_local_accounts.end(); ++it) { | 515 it != device_local_accounts.end(); ++it) { |
514 if (it->type != policy::DeviceLocalAccount::TYPE_KIOSK_APP) | 516 if (it->type != policy::DeviceLocalAccount::TYPE_KIOSK_APP) |
515 continue; | 517 continue; |
516 | 518 |
517 if (it->account_id == auto_login_account_id) | 519 if (it->account_id == auto_login_account_id) |
518 auto_launch_app_id_ = it->kiosk_app_id; | 520 auto_launch_app_id_ = it->kiosk_app_id; |
519 | 521 |
520 // TODO(mnissler): Support non-CWS update URLs. | |
521 | |
522 std::map<std::string, KioskAppData*>::iterator old_it = | 522 std::map<std::string, KioskAppData*>::iterator old_it = |
523 old_apps.find(it->kiosk_app_id); | 523 old_apps.find(it->kiosk_app_id); |
524 if (old_it != old_apps.end()) { | 524 if (old_it != old_apps.end()) { |
525 apps_.push_back(old_it->second); | 525 apps_.push_back(old_it->second); |
526 old_apps.erase(old_it); | 526 old_apps.erase(old_it); |
527 } else { | 527 } else { |
528 KioskAppData* new_app = | 528 KioskAppData* new_app = new KioskAppData( |
529 new KioskAppData(this, it->kiosk_app_id, it->user_id); | 529 this, it->kiosk_app_id, it->user_id, GURL(it->kiosk_app_update_url)); |
530 apps_.push_back(new_app); // Takes ownership of |new_app|. | 530 apps_.push_back(new_app); // Takes ownership of |new_app|. |
531 new_app->Load(); | 531 new_app->Load(); |
532 } | 532 } |
533 } | 533 } |
534 | 534 |
535 // Clears cache and deletes the remaining old data. | 535 // Clears cache and deletes the remaining old data. |
536 std::vector<std::string> apps_to_remove; | 536 std::vector<std::string> apps_to_remove; |
537 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); | 537 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); |
538 it != old_apps.end(); ++it) { | 538 it != old_apps.end(); ++it) { |
539 it->second->ClearCache(); | 539 it->second->ClearCache(); |
540 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 540 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
541 it->second->user_id(), | 541 it->second->user_id(), |
542 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); | 542 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); |
543 apps_to_remove.push_back(it->second->app_id()); | 543 apps_to_remove.push_back(it->second->app_id()); |
544 } | 544 } |
545 STLDeleteValues(&old_apps); | 545 STLDeleteValues(&old_apps); |
546 external_cache_->RemoveExtensions(apps_to_remove); | 546 external_cache_->RemoveExtensions(apps_to_remove); |
547 | 547 |
548 // Request external_cache_ to download new apps and update the existing | 548 // Request external_cache_ to download new apps and update the existing |
549 // apps. | 549 // apps. |
550 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 550 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
551 for (size_t i = 0; i < apps_.size(); ++i) { | 551 for (size_t i = 0; i < apps_.size(); ++i) { |
552 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 552 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
553 entry->SetBoolean(extensions::ExternalProviderImpl::kIsFromWebstore, true); | 553 |
| 554 if (apps_[i]->update_url().is_valid()) { |
| 555 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| 556 apps_[i]->update_url().spec()); |
| 557 } else { |
| 558 entry->SetString(extensions::ExternalProviderImpl::kExternalUpdateUrl, |
| 559 extension_urls::GetWebstoreUpdateUrl().spec()); |
| 560 } |
| 561 |
554 prefs->Set(apps_[i]->app_id(), entry.release()); | 562 prefs->Set(apps_[i]->app_id(), entry.release()); |
555 } | 563 } |
556 external_cache_->UpdateExtensionsList(prefs.Pass()); | 564 external_cache_->UpdateExtensionsList(prefs.Pass()); |
557 | 565 |
558 RetryFailedAppDataFetch(); | 566 RetryFailedAppDataFetch(); |
559 | 567 |
560 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, | 568 FOR_EACH_OBSERVER(KioskAppManagerObserver, observers_, |
561 OnKioskAppsSettingsChanged()); | 569 OnKioskAppsSettingsChanged()); |
562 } | 570 } |
563 | 571 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); | 637 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); |
630 } | 638 } |
631 | 639 |
632 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { | 640 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { |
633 base::FilePath temp_dir; | 641 base::FilePath temp_dir; |
634 base::GetTempDir(&temp_dir); | 642 base::GetTempDir(&temp_dir); |
635 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); | 643 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); |
636 } | 644 } |
637 | 645 |
638 } // namespace chromeos | 646 } // namespace chromeos |
OLD | NEW |