OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/kiosk_mode/kiosk_mode_helper.h" | 5 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_helper.h" |
6 | 6 |
7 #include <algorithm> | |
8 | |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
9 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
10 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/chromeos/cros_settings.h" | |
14 #include "chrome/browser/chromeos/cros_settings_names.h" | |
11 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h" | 15 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_screensaver.h" |
12 #include "chrome/browser/policy/cloud_policy_constants.h" | 16 #include "chrome/browser/policy/cloud_policy_constants.h" |
13 #include "chrome/browser/policy/browser_policy_connector.h" | 17 #include "chrome/browser/policy/browser_policy_connector.h" |
14 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
15 | 19 |
16 namespace { | 20 namespace { |
17 | 21 |
18 const int64 kScreensaverIdleTimeout = 60; | 22 const int kMaxIdleLogoutTimeout = 100000; // ms = 100s. |
19 const int64 kLoginIdleTimeout = 100; | 23 const int kMinIdleLogoutTimeout = 25000; // ms = 25s. |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
Where do this values come from? They seem overly r
rkc
2012/03/19 23:59:48
Done.
| |
20 const int64 kLoginIdleCountdownTimeout = 20; | 24 |
25 const int kMaxIdleLogoutWarningTimeout = 20000; // ms = 20s. | |
26 const int kMinIdleLogoutWarningTimeout = 5000; // ms = 5s. | |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
same here
rkc
2012/03/19 23:59:48
Done.
| |
21 | 27 |
22 } // namespace | 28 } // namespace |
23 | 29 |
24 namespace chromeos { | 30 namespace chromeos { |
25 | 31 |
26 static base::LazyInstance<KioskModeHelper> g_kiosk_mode_helper = | 32 static base::LazyInstance<KioskModeHelper> g_kiosk_mode_helper = |
27 LAZY_INSTANCE_INITIALIZER; | 33 LAZY_INSTANCE_INITIALIZER; |
28 | 34 |
29 // static | 35 // static |
30 bool KioskModeHelper::IsKioskModeEnabled() { | 36 bool KioskModeHelper::IsKioskModeEnabled() { |
31 if (g_browser_process) { | 37 if (g_browser_process) { |
32 policy::BrowserPolicyConnector* bpc = | 38 policy::BrowserPolicyConnector* bpc = |
33 g_browser_process->browser_policy_connector(); | 39 g_browser_process->browser_policy_connector(); |
34 if (bpc && policy::DEVICE_MODE_KIOSK == bpc->GetDeviceMode()) | 40 if (bpc && policy::DEVICE_MODE_KIOSK == bpc->GetDeviceMode()) |
35 return true; | 41 return true; |
36 } | 42 } |
37 // In case we've force-enabled kiosk mode. | 43 // In case we've force-enabled kiosk mode. |
38 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableKioskMode)) | 44 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableKioskMode)) |
39 return true; | 45 return true; |
40 | 46 |
41 return false; | 47 return false; |
42 } | 48 } |
43 | 49 |
44 // static | 50 // static |
45 KioskModeHelper* KioskModeHelper::Get() { | 51 KioskModeHelper* KioskModeHelper::Get() { |
46 return g_kiosk_mode_helper.Pointer(); | 52 return g_kiosk_mode_helper.Pointer(); |
47 } | 53 } |
48 | 54 |
49 void KioskModeHelper::Initialize(const base::Closure& notify_initialized) { | 55 void KioskModeHelper::Initialize(const base::Closure& notify_initialized) { |
56 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); | |
57 if (!cros_settings->GetTrusted( | |
58 kIdleLogoutTimeout, | |
59 base::Bind(&KioskModeHelper::Initialize, | |
60 base::Unretained(this), | |
61 notify_initialized))) { | |
62 return; | |
63 } | |
64 | |
65 // Ignored till we land the code to pull the screensaver path from the app | |
66 // packs with the screensaver id. | |
67 cros_settings->GetString(kScreenSaverExtensionId, &screensaver_id_); | |
68 | |
69 int screensaver_timeout = 0; | |
70 int idle_logout_timeout = 0, idle_logout_warning_timeout = 0; | |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
nit: It's relatively uncommon to have declarations
rkc
2012/03/19 23:59:48
Done.
| |
71 cros_settings->GetInteger(kScreenSaverTimeout, &screensaver_timeout); | |
72 cros_settings->GetInteger(kIdleLogoutTimeout, &idle_logout_timeout); | |
73 cros_settings->GetInteger(kIdleLogoutWarningDuration, | |
74 &idle_logout_warning_timeout); | |
75 | |
76 screensaver_timeout_ = base::TimeDelta::FromMilliseconds( | |
77 screensaver_timeout); | |
78 | |
79 // Restrict idle timeouts to safe values to prevent them from being turned off | |
80 // or otherwise misused. | |
81 idle_logout_timeout_ = base::TimeDelta::FromMilliseconds( | |
82 std::min(idle_logout_timeout, kMaxIdleLogoutTimeout)); | |
83 idle_logout_timeout_ = base::TimeDelta::FromMilliseconds( | |
84 std::max(idle_logout_timeout, kMinIdleLogoutTimeout)); | |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
There's a bug here, as you clobber the value assig
rkc
2012/03/19 23:59:48
Done and added unit tests to test this and other s
| |
85 | |
86 idle_logout_warning_timeout_ = base::TimeDelta::FromMilliseconds( | |
87 std::min(idle_logout_warning_timeout, kMaxIdleLogoutWarningTimeout)); | |
88 idle_logout_warning_timeout_ = base::TimeDelta::FromMilliseconds( | |
89 std::max(idle_logout_warning_timeout, kMinIdleLogoutWarningTimeout)); | |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
ditto.
rkc
2012/03/19 23:59:48
Done.
| |
90 | |
50 is_initialized_ = true; | 91 is_initialized_ = true; |
51 notify_initialized.Run(); | 92 notify_initialized.Run(); |
52 } | 93 } |
53 | 94 |
54 std::string KioskModeHelper::GetScreensaverPath() const { | 95 std::string KioskModeHelper::GetScreensaverPath() const { |
55 if (!is_initialized_) | 96 if (!is_initialized_) |
56 return std::string(); | 97 return std::string(); |
57 | 98 |
58 return CommandLine::ForCurrentProcess()-> | 99 return CommandLine::ForCurrentProcess()-> |
59 GetSwitchValueASCII(switches::kKioskModeScreensaverPath); | 100 GetSwitchValueASCII(switches::kKioskModeScreensaverPath); |
60 } | 101 } |
61 | 102 |
62 int64 KioskModeHelper::GetScreensaverTimeout() const { | 103 base::TimeDelta KioskModeHelper::GetScreensaverTimeout() const { |
63 if (!is_initialized_) | 104 if (!is_initialized_) |
64 return -1; | 105 return base::TimeDelta::FromSeconds(-1); |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
This seems like a pretty arbitrary value, since it
rkc
2012/03/19 23:59:48
I specifically wanted a negative value so 0 could
| |
65 | 106 |
66 return kScreensaverIdleTimeout; | 107 return screensaver_timeout_; |
67 } | 108 } |
68 | 109 |
69 int64 KioskModeHelper::GetIdleLogoutTimeout() const { | 110 base::TimeDelta KioskModeHelper::GetIdleLogoutTimeout() const { |
70 if (!is_initialized_) | 111 if (!is_initialized_) |
71 return -1; | 112 return base::TimeDelta::FromSeconds(-1); |
72 | 113 |
73 return kLoginIdleTimeout; | 114 return idle_logout_timeout_; |
74 } | 115 } |
Mattias Nissler (ping if slow)
2012/03/16 09:56:46
insert blank line.
rkc
2012/03/19 23:59:48
Done.
| |
75 int64 KioskModeHelper::GetIdleLogoutWarningTimeout() const { | 116 base::TimeDelta KioskModeHelper::GetIdleLogoutWarningTimeout() const { |
76 if (!is_initialized_) | 117 if (!is_initialized_) |
77 return -1; | 118 return base::TimeDelta::FromSeconds(-1); |
78 | 119 |
79 return kLoginIdleCountdownTimeout; | 120 return idle_logout_warning_timeout_; |
80 } | 121 } |
81 | 122 |
82 KioskModeHelper::KioskModeHelper() : is_initialized_(false) { | 123 KioskModeHelper::KioskModeHelper() : is_initialized_(false) { |
83 } | 124 } |
84 | 125 |
85 } // namespace chromeos | 126 } // namespace chromeos |
OLD | NEW |