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

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

Issue 2639033002: Restore auto-launched state on kiosk restart within session (Closed)
Patch Set: Attempt No 2 Created 3 years, 10 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 22 matching lines...) Expand all
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"
43 #include "chromeos/settings/cros_settings_names.h" 44 #include "chromeos/settings/cros_settings_names.h"
44 #include "components/ownership/owner_key_util.h" 45 #include "components/ownership/owner_key_util.h"
45 #include "components/prefs/pref_registry_simple.h" 46 #include "components/prefs/pref_registry_simple.h"
46 #include "components/prefs/pref_service.h" 47 #include "components/prefs/pref_service.h"
47 #include "components/prefs/scoped_user_pref_update.h" 48 #include "components/prefs/scoped_user_pref_update.h"
48 #include "components/signin/core/account_id/account_id.h" 49 #include "components/signin/core/account_id/account_id.h"
49 #include "components/user_manager/known_user.h" 50 #include "components/user_manager/known_user.h"
50 #include "components/user_manager/user_manager.h" 51 #include "components/user_manager/user_manager.h"
51 #include "content/public/browser/browser_thread.h" 52 #include "content/public/browser/browser_thread.h"
52 #include "extensions/common/extension_urls.h" 53 #include "extensions/common/extension_urls.h"
53 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 54 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
55 #include "third_party/cros_system_api/switches/chrome_switches.h"
54 56
55 namespace chromeos { 57 namespace chromeos {
56 58
57 namespace { 59 namespace {
58 60
59 // Domain that is used for kiosk-app account IDs. 61 // Domain that is used for kiosk-app account IDs.
60 const char kKioskAppAccountDomain[] = "kiosk-apps"; 62 const char kKioskAppAccountDomain[] = "kiosk-apps";
61 63
62 // Preference for the dictionary of user ids for which cryptohomes have to be 64 // Preference for the dictionary of user ids for which cryptohomes have to be
63 // removed upon browser restart. 65 // removed upon browser restart.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 base::Version GetPlatformVersion() { 142 base::Version GetPlatformVersion() {
141 int32_t major_version; 143 int32_t major_version;
142 int32_t minor_version; 144 int32_t minor_version;
143 int32_t bugfix_version; 145 int32_t bugfix_version;
144 base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version, 146 base::SysInfo::OperatingSystemVersionNumbers(&major_version, &minor_version,
145 &bugfix_version); 147 &bugfix_version);
146 return base::Version(base::StringPrintf("%d.%d.%d", major_version, 148 return base::Version(base::StringPrintf("%d.%d.%d", major_version,
147 minor_version, bugfix_version)); 149 minor_version, bugfix_version));
148 } 150 }
149 151
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
150 } // namespace 160 } // namespace
151 161
152 // static 162 // static
153 const char KioskAppManager::kKioskDictionaryName[] = "kiosk"; 163 const char KioskAppManager::kKioskDictionaryName[] = "kiosk";
154 const char KioskAppManager::kKeyApps[] = "apps"; 164 const char KioskAppManager::kKeyApps[] = "apps";
155 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state"; 165 const char KioskAppManager::kKeyAutoLoginState[] = "auto_login_state";
156 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon"; 166 const char KioskAppManager::kIconCacheDir[] = "kiosk/icon";
157 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx"; 167 const char KioskAppManager::kCrxCacheDir[] = "kiosk/crx";
158 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack"; 168 const char KioskAppManager::kCrxUnpackDir[] = "kiosk_unpack";
159 169
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay( 244 void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay(
235 const std::string& app_id) { 245 const std::string& app_id) {
236 DCHECK_EQ(auto_launch_app_id_, app_id); 246 DCHECK_EQ(auto_launch_app_id_, app_id);
237 currently_auto_launched_with_zero_delay_app_ = app_id; 247 currently_auto_launched_with_zero_delay_app_ = app_id;
238 } 248 }
239 249
240 void KioskAppManager::InitSession(Profile* profile, 250 void KioskAppManager::InitSession(Profile* profile,
241 const std::string& app_id) { 251 const std::string& app_id) {
242 LOG_IF(FATAL, app_session_) << "Kiosk session is already initialized."; 252 LOG_IF(FATAL, app_session_) << "Kiosk session is already initialized.";
243 253
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
244 app_session_.reset(new AppSession); 270 app_session_.reset(new AppSession);
245 app_session_->Init(profile, app_id); 271 app_session_->Init(profile, app_id);
246 } 272 }
247 273
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
248 void KioskAppManager::AddAppForTest( 318 void KioskAppManager::AddAppForTest(
249 const std::string& app_id, 319 const std::string& app_id,
250 const AccountId& account_id, 320 const AccountId& account_id,
251 const GURL& update_url, 321 const GURL& update_url,
252 const std::string& required_platform_version) { 322 const std::string& required_platform_version) {
253 for (auto it = apps_.begin(); it != apps_.end(); ++it) { 323 for (auto it = apps_.begin(); it != apps_.end(); ++it) {
254 if ((*it)->app_id() == app_id) { 324 if ((*it)->app_id() == app_id) {
255 apps_.erase(it); 325 apps_.erase(it);
256 break; 326 break;
257 } 327 }
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const { 968 base::TimeDelta KioskAppManager::GetAutoLaunchDelay() const {
899 int delay; 969 int delay;
900 if (!CrosSettings::Get()->GetInteger( 970 if (!CrosSettings::Get()->GetInteger(
901 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) { 971 kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) {
902 return base::TimeDelta(); // Default delay is 0ms. 972 return base::TimeDelta(); // Default delay is 0ms.
903 } 973 }
904 return base::TimeDelta::FromMilliseconds(delay); 974 return base::TimeDelta::FromMilliseconds(delay);
905 } 975 }
906 976
907 } // namespace chromeos 977 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698