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/barrier_closure.h" | |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/path_service.h" | 15 #include "base/path_service.h" |
15 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
16 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
17 #include "base/prefs/scoped_user_pref_update.h" | 18 #include "base/prefs/scoped_user_pref_update.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/sys_info.h" | 20 #include "base/sys_info.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" | 22 #include "chrome/browser/chromeos/app_mode/kiosk_app_data.h" |
22 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" | 23 #include "chrome/browser/chromeos/app_mode/kiosk_app_external_loader.h" |
23 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" | 24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager_observer.h" |
24 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" | 25 #include "chrome/browser/chromeos/app_mode/kiosk_external_updater.h" |
25 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 26 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
26 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 27 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
27 #include "chrome/browser/chromeos/policy/device_local_account.h" | 28 #include "chrome/browser/chromeos/policy/device_local_account.h" |
28 #include "chrome/browser/chromeos/settings/cros_settings.h" | 29 #include "chrome/browser/chromeos/settings/cros_settings.h" |
29 #include "chrome/browser/extensions/external_loader.h" | 30 #include "chrome/browser/extensions/external_loader.h" |
30 #include "chrome/browser/extensions/external_provider_impl.h" | 31 #include "chrome/browser/extensions/external_provider_impl.h" |
32 #include "chrome/browser/lifetime/application_lifetime.h" | |
31 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/extensions/extension_constants.h" | 34 #include "chrome/common/extensions/extension_constants.h" |
33 #include "chromeos/chromeos_paths.h" | 35 #include "chromeos/chromeos_paths.h" |
34 #include "chromeos/cryptohome/async_method_caller.h" | 36 #include "chromeos/cryptohome/async_method_caller.h" |
35 #include "chromeos/settings/cros_settings_names.h" | 37 #include "chromeos/settings/cros_settings_names.h" |
36 #include "components/ownership/owner_key_util.h" | 38 #include "components/ownership/owner_key_util.h" |
39 #include "components/user_manager/user_manager.h" | |
37 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
38 #include "extensions/common/extension_urls.h" | 41 #include "extensions/common/extension_urls.h" |
39 | 42 |
40 namespace chromeos { | 43 namespace chromeos { |
41 | 44 |
42 namespace { | 45 namespace { |
43 | 46 |
44 // Domain that is used for kiosk-app account IDs. | 47 // Domain that is used for kiosk-app account IDs. |
45 const char kKioskAppAccountDomain[] = "kiosk-apps"; | 48 const char kKioskAppAccountDomain[] = "kiosk-apps"; |
46 | 49 |
47 std::string GenerateKioskAppAccountId(const std::string& app_id) { | 50 std::string GenerateKioskAppAccountId(const std::string& app_id) { |
48 return app_id + '@' + kKioskAppAccountDomain; | 51 return app_id + '@' + kKioskAppAccountDomain; |
49 } | 52 } |
50 | 53 |
51 void OnRemoveAppCryptohomeComplete(const std::string& app, | 54 void OnRemoveAppCryptohomeComplete(const std::string& app, |
55 const base::Closure& callback, | |
52 bool success, | 56 bool success, |
53 cryptohome::MountError return_code) { | 57 cryptohome::MountError return_code) { |
54 if (!success) { | 58 if (!success) { |
55 LOG(ERROR) << "Remove cryptohome for " << app | 59 LOG(ERROR) << "Remove cryptohome for " << app |
56 << " failed, return code: " << return_code; | 60 << " failed, return code: " << return_code; |
57 } | 61 } |
62 if (!callback.is_null()) | |
63 callback.Run(); | |
58 } | 64 } |
59 | 65 |
60 // Check for presence of machine owner public key file. | 66 // Check for presence of machine owner public key file. |
61 void CheckOwnerFilePresence(bool *present) { | 67 void CheckOwnerFilePresence(bool *present) { |
62 scoped_refptr<ownership::OwnerKeyUtil> util = | 68 scoped_refptr<ownership::OwnerKeyUtil> util = |
63 OwnerSettingsServiceChromeOSFactory::GetInstance()->GetOwnerKeyUtil(); | 69 OwnerSettingsServiceChromeOSFactory::GetInstance()->GetOwnerKeyUtil(); |
64 *present = util.get() && util->IsPublicKeyPresent(); | 70 *present = util.get() && util->IsPublicKeyPresent(); |
65 } | 71 } |
66 | 72 |
67 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { | 73 scoped_refptr<base::SequencedTaskRunner> GetBackgroundTaskRunner() { |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 apps_.push_back(old_it->second); | 537 apps_.push_back(old_it->second); |
532 old_apps.erase(old_it); | 538 old_apps.erase(old_it); |
533 } else { | 539 } else { |
534 KioskAppData* new_app = new KioskAppData( | 540 KioskAppData* new_app = new KioskAppData( |
535 this, it->kiosk_app_id, it->user_id, GURL(it->kiosk_app_update_url)); | 541 this, it->kiosk_app_id, it->user_id, GURL(it->kiosk_app_update_url)); |
536 apps_.push_back(new_app); // Takes ownership of |new_app|. | 542 apps_.push_back(new_app); // Takes ownership of |new_app|. |
537 new_app->Load(); | 543 new_app->Load(); |
538 } | 544 } |
539 } | 545 } |
540 | 546 |
547 base::Closure cryptohomes_barrier_closure; | |
548 | |
549 const user_manager::User* active_user = | |
550 user_manager::UserManager::Get()->GetActiveUser(); | |
551 if (active_user) { | |
552 std::string active_user_id = active_user->GetUserID(); | |
553 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); | |
554 it != old_apps.end(); ++it) { | |
xiyuan
2015/03/03 23:59:59
nit: C++11 style to save some typing.
for (const
Vladislav Kaznacheev
2015/03/04 00:24:54
Done.
| |
555 if (it->second->user_id() == active_user_id) { | |
556 VLOG(1) << "Currently running kiosk app removed from policy, exiting"; | |
557 cryptohomes_barrier_closure = BarrierClosure( | |
558 old_apps.size(), base::Bind(&chrome::AttemptUserExit)); | |
559 break; | |
560 } | |
561 } | |
562 } | |
563 | |
541 // Clears cache and deletes the remaining old data. | 564 // Clears cache and deletes the remaining old data. |
542 std::vector<std::string> apps_to_remove; | 565 std::vector<std::string> apps_to_remove; |
543 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); | 566 for (std::map<std::string, KioskAppData*>::iterator it = old_apps.begin(); |
544 it != old_apps.end(); ++it) { | 567 it != old_apps.end(); ++it) { |
545 it->second->ClearCache(); | 568 it->second->ClearCache(); |
546 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 569 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
547 it->second->user_id(), | 570 it->second->user_id(), |
548 base::Bind(&OnRemoveAppCryptohomeComplete, it->first)); | 571 base::Bind(&OnRemoveAppCryptohomeComplete, |
572 it->first, | |
573 cryptohomes_barrier_closure)); | |
549 apps_to_remove.push_back(it->second->app_id()); | 574 apps_to_remove.push_back(it->second->app_id()); |
550 } | 575 } |
551 STLDeleteValues(&old_apps); | 576 STLDeleteValues(&old_apps); |
552 external_cache_->RemoveExtensions(apps_to_remove); | 577 external_cache_->RemoveExtensions(apps_to_remove); |
553 | 578 |
554 // Request external_cache_ to download new apps and update the existing | 579 // Request external_cache_ to download new apps and update the existing |
555 // apps. | 580 // apps. |
556 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 581 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
557 for (size_t i = 0; i < apps_.size(); ++i) { | 582 for (size_t i = 0; i < apps_.size(); ++i) { |
558 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 583 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); | 674 *cache_dir = user_data_dir.AppendASCII(kCrxCacheDir); |
650 } | 675 } |
651 | 676 |
652 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { | 677 void KioskAppManager::GetCrxUnpackDir(base::FilePath* unpack_dir) { |
653 base::FilePath temp_dir; | 678 base::FilePath temp_dir; |
654 base::GetTempDir(&temp_dir); | 679 base::GetTempDir(&temp_dir); |
655 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); | 680 *unpack_dir = temp_dir.AppendASCII(kCrxUnpackDir); |
656 } | 681 } |
657 | 682 |
658 } // namespace chromeos | 683 } // namespace chromeos |
OLD | NEW |