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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/extensions/external_loader.h" | 33 #include "chrome/browser/extensions/external_loader.h" |
34 #include "chrome/browser/extensions/external_provider_impl.h" | 34 #include "chrome/browser/extensions/external_provider_impl.h" |
35 #include "chrome/browser/lifetime/application_lifetime.h" | 35 #include "chrome/browser/lifetime/application_lifetime.h" |
36 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
37 #include "chrome/common/extensions/extension_constants.h" | 37 #include "chrome/common/extensions/extension_constants.h" |
38 #include "chromeos/chromeos_paths.h" | 38 #include "chromeos/chromeos_paths.h" |
39 #include "chromeos/chromeos_switches.h" | 39 #include "chromeos/chromeos_switches.h" |
40 #include "chromeos/cryptohome/async_method_caller.h" | 40 #include "chromeos/cryptohome/async_method_caller.h" |
41 #include "chromeos/cryptohome/cryptohome_parameters.h" | 41 #include "chromeos/cryptohome/cryptohome_parameters.h" |
42 #include "chromeos/dbus/dbus_thread_manager.h" | 42 #include "chromeos/dbus/dbus_thread_manager.h" |
43 #include "chromeos/dbus/session_manager_client.h" | |
44 #include "chromeos/settings/cros_settings_names.h" | 43 #include "chromeos/settings/cros_settings_names.h" |
45 #include "components/ownership/owner_key_util.h" | 44 #include "components/ownership/owner_key_util.h" |
46 #include "components/prefs/pref_registry_simple.h" | 45 #include "components/prefs/pref_registry_simple.h" |
47 #include "components/prefs/pref_service.h" | 46 #include "components/prefs/pref_service.h" |
48 #include "components/prefs/scoped_user_pref_update.h" | 47 #include "components/prefs/scoped_user_pref_update.h" |
49 #include "components/signin/core/account_id/account_id.h" | 48 #include "components/signin/core/account_id/account_id.h" |
50 #include "components/user_manager/known_user.h" | 49 #include "components/user_manager/known_user.h" |
51 #include "components/user_manager/user_manager.h" | 50 #include "components/user_manager/user_manager.h" |
52 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
53 #include "extensions/common/extension_urls.h" | 52 #include "extensions/common/extension_urls.h" |
54 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 53 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
55 #include "third_party/cros_system_api/switches/chrome_switches.h" | |
56 | 54 |
57 namespace chromeos { | 55 namespace chromeos { |
58 | 56 |
59 namespace { | 57 namespace { |
60 | 58 |
61 // Domain that is used for kiosk-app account IDs. | 59 // Domain that is used for kiosk-app account IDs. |
62 const char kKioskAppAccountDomain[] = "kiosk-apps"; | 60 const char kKioskAppAccountDomain[] = "kiosk-apps"; |
63 | 61 |
64 // Preference for the dictionary of user ids for which cryptohomes have to be | 62 // Preference for the dictionary of user ids for which cryptohomes have to be |
65 // removed upon browser restart. | 63 // removed upon browser restart. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 base::Version GetPlatformVersion() { | 140 base::Version GetPlatformVersion() { |
143 int32_t major_version; | 141 int32_t major_version; |
144 int32_t minor_version; | 142 int32_t minor_version; |
145 int32_t bugfix_version; | 143 int32_t bugfix_version; |
146 base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, | 144 base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, |
147 &bugfix_version); | 145 &bugfix_version); |
148 return base::Version(base::StringPrintf("%d.%d.%d", major_version, | 146 return base::Version(base::StringPrintf("%d.%d.%d", major_version, |
149 minor_version, bugfix_version)); | 147 minor_version, bugfix_version)); |
150 } | 148 } |
151 | 149 |
152 // Converts a flag constant to actual command line switch value. | |
153 std::string GetSwitchString(const std::string& flag_name) { | |
154 base::CommandLine cmd_line(base::CommandLine::NO_PROGRAM); | |
155 cmd_line.AppendSwitch(flag_name); | |
156 DCHECK_EQ(2U, cmd_line.argv().size()); | |
157 return cmd_line.argv()[1]; | |
158 } | |
159 | |
160 } // namespace | 150 } // namespace |
161 | 151 |
162 // static | 152 // static |
163 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; | 153 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; |
164 const char KioskAppManager::kKeyApps[] = "apps"; | 154 const char KioskAppManager::kKeyApps[] = "apps"; |
165 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; | 155 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; |
166 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; | 156 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; |
167 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; | 157 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; |
168 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack"; | 158 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack"; |
169 | 159 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay( | 234 void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay( |
245 const std::string& app_id) { | 235 const std::string& app_id) { |
246 DCHECK_EQ(auto_launch_app_id_, app_id); | 236 DCHECK_EQ(auto_launch_app_id_, app_id); |
247 currently_auto_launched_with_zero_delay_app_ = app_id; | 237 currently_auto_launched_with_zero_delay_app_ = app_id; |
248 } | 238 } |
249 | 239 |
250 void KioskAppManager::InitSession(Profile* profile, | 240 void KioskAppManager::InitSession(Profile* profile, |
251 const std::string& app_id) { | 241 const std::string& app_id) { |
252 LOG_IF(FATAL, app_session_) << "Kiosk session is already initialized."; | 242 LOG_IF(FATAL, app_session_) << "Kiosk session is already initialized."; |
253 | 243 |
254 base::CommandLine session_flags(base::CommandLine::NO_PROGRAM); | |
255 if (GetSwitchesForSessionRestore(app_id, &session_flags)) { | |
256 base::CommandLine::StringVector flags; | |
257 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. | |
258 flags.assign(session_flags.argv().begin() + 1, session_flags.argv().end()); | |
259 | |
260 // Update user flags, but do not restart Chrome - the purpose of the flags | |
261 // set here is to be able to properly restore session if the session is | |
262 // restarted - e.g. due to crash. For example, this will ensure restarted | |
263 // app session restores auto-launched state. | |
264 DBusThreadManager::Get()->GetSessionManagerClient()->SetFlagsForUser( | |
265 cryptohome::Identification( | |
266 user_manager::UserManager::Get()->GetActiveUser()->GetAccountId()), | |
267 flags); | |
268 } | |
269 | |
270 app_session_.reset(new AppSession); | 244 app_session_.reset(new AppSession); |
271 app_session_->Init(profile, app_id); | 245 app_session_->Init(profile, app_id); |
272 } | 246 } |
273 | 247 |
274 bool KioskAppManager::GetSwitchesForSessionRestore( | |
275 const std::string& app_id, | |
276 base::CommandLine* switches) { | |
277 bool auto_launched = app_id == currently_auto_launched_with_zero_delay_app_; | |
278 const base::CommandLine* current_command_line = | |
279 base::CommandLine::ForCurrentProcess(); | |
280 bool has_auto_launched_flag = | |
281 current_command_line->HasSwitch(switches::kAppAutoLaunched); | |
282 if (auto_launched == has_auto_launched_flag) | |
283 return false; | |
284 | |
285 // Collect current policy defined switches, so they can be passed on to the | |
286 // session manager as well - otherwise they would get lost on restart. | |
287 // This ignores 'flag-switches-begin' - 'flag-switches-end' flags, but those | |
288 // should not be present for kiosk sessions. | |
289 bool in_policy_switches_block = false; | |
290 const std::string policy_switches_begin = | |
291 GetSwitchString(switches::kPolicySwitchesBegin); | |
292 const std::string policy_switches_end = | |
293 GetSwitchString(switches::kPolicySwitchesEnd); | |
294 | |
295 for (const auto& it : current_command_line->argv()) { | |
296 if (it == policy_switches_begin) { | |
297 DCHECK(!in_policy_switches_block); | |
298 in_policy_switches_block = true; | |
299 } | |
300 | |
301 if (in_policy_switches_block) | |
302 switches->AppendSwitch(it); | |
303 | |
304 if (it == policy_switches_end) { | |
305 DCHECK(in_policy_switches_block); | |
306 in_policy_switches_block = false; | |
307 } | |
308 } | |
309 | |
310 DCHECK(!in_policy_switches_block); | |
311 | |
312 if (auto_launched) | |
313 switches->AppendSwitch(switches::kAppAutoLaunched); | |
314 | |
315 return true; | |
316 } | |
317 | |
318 void KioskAppManager::AddAppForTest( | 248 void KioskAppManager::AddAppForTest( |
319 const std::string& app_id, | 249 const std::string& app_id, |
320 const AccountId& account_id, | 250 const AccountId& account_id, |
321 const GURL& update_url, | 251 const GURL& update_url, |
322 const std::string& required_platform_version) { | 252 const std::string& required_platform_version) { |
323 for (auto it = apps_.begin(); it != apps_.end(); ++it) { | 253 for (auto it = apps_.begin(); it != apps_.end(); ++it) { |
324 if ((*it)->app_id() == app_id) { | 254 if ((*it)->app_id() == app_id) { |
325 apps_.erase(it); | 255 apps_.erase(it); |
326 break; | 256 break; |
327 } | 257 } |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { | 898 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { |
969 int delay; | 899 int delay; |
970 if (!CrosSettings::Get()->GetInteger( | 900 if (!CrosSettings::Get()->GetInteger( |
971 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { | 901 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { |
972 return base::TimeDelta(); // Default delay is 0ms. | 902 return base::TimeDelta(); // Default delay is 0ms. |
973 } | 903 } |
974 return base::TimeDelta::FromMilliseconds(delay); | 904 return base::TimeDelta::FromMilliseconds(delay); |
975 } | 905 } |
976 | 906 |
977 } // namespace chromeos | 907 } // namespace chromeos |
OLD | NEW |