Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / app_mode / kiosk_mode_idle_app_name_notification.cc
blob857d48a28e4a3a9a77b8b6b3c098a653b0fc5708
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/app_mode/kiosk_mode_idle_app_name_notification.h"
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/logging.h"
10 #include "chrome/browser/chromeos/ui/idle_app_name_notification_view.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chromeos/dbus/dbus_thread_manager.h"
15 #include "components/user_manager/user_manager.h"
16 #include "extensions/browser/extension_system.h"
17 #include "ui/base/user_activity/user_activity_detector.h"
19 namespace chromeos {
21 namespace {
23 // The timeout in ms before the message shows up.
24 const int kIdleAppNameNotificationTimeoutMs = 2 * 60 * 1000;
26 // The duration of visibility for the message.
27 const int kMessageVisibilityTimeMs = 3000;
29 // The anomation time to show / hide the message.
30 const int kMessageAnimationTimeMs = 200;
32 // Our global instance of the Kiosk mode message.
33 KioskModeIdleAppNameNotification* g_kiosk_mode_idle_app_message = NULL;
35 } // namespace
37 // static
38 void KioskModeIdleAppNameNotification::Initialize() {
39 DCHECK(!g_kiosk_mode_idle_app_message);
40 g_kiosk_mode_idle_app_message = new KioskModeIdleAppNameNotification();
43 // static
44 void KioskModeIdleAppNameNotification::Shutdown() {
45 if (g_kiosk_mode_idle_app_message) {
46 delete g_kiosk_mode_idle_app_message;
47 g_kiosk_mode_idle_app_message = NULL;
51 KioskModeIdleAppNameNotification::KioskModeIdleAppNameNotification()
52 : show_notification_upon_next_user_activity_(false) {
53 // Note: The timeout is currently fixed. If that changes we need to check if
54 // the KioskModeSettings were already initialized.
55 Setup();
58 KioskModeIdleAppNameNotification::~KioskModeIdleAppNameNotification() {
59 ui::UserActivityDetector* user_activity_detector =
60 ui::UserActivityDetector::Get();
61 if (user_activity_detector && user_activity_detector->HasObserver(this)) {
62 user_activity_detector->RemoveObserver(this);
63 // At this time the DBusThreadManager might already be gone.
64 if (chromeos::DBusThreadManager::IsInitialized())
65 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(
66 )->RemoveObserver(this);
70 void KioskModeIdleAppNameNotification::Setup() {
71 DCHECK(user_manager::UserManager::Get()->IsUserLoggedIn());
72 Start();
75 void KioskModeIdleAppNameNotification::OnUserActivity(const ui::Event* event) {
76 if (show_notification_upon_next_user_activity_) {
77 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
78 const std::string app_id =
79 command_line->GetSwitchValueASCII(::switches::kAppId);
80 Profile* profile = ProfileManager::GetActiveUserProfile();
81 notification_.reset(
82 new IdleAppNameNotificationView(
83 kMessageVisibilityTimeMs,
84 kMessageAnimationTimeMs,
85 extensions::ExtensionSystem::Get(profile
86 )->extension_service()->GetInstalledExtension(app_id)));
87 show_notification_upon_next_user_activity_ = false;
89 ResetTimer();
92 void KioskModeIdleAppNameNotification::SuspendDone(
93 const base::TimeDelta& sleep_duration) {
94 // When we come back from a system resume we stop the timer and show the
95 // message.
96 timer_.Stop();
97 OnTimeout();
100 void KioskModeIdleAppNameNotification::Start() {
101 if (!ui::UserActivityDetector::Get()->HasObserver(this)) {
102 ui::UserActivityDetector::Get()->AddObserver(this);
103 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
104 this);
106 ResetTimer();
109 void KioskModeIdleAppNameNotification::ResetTimer() {
110 if (timer_.IsRunning()) {
111 timer_.Reset();
112 } else {
113 // OneShotTimer destroys the posted task after running it, so Reset()
114 // isn't safe to call on a timer that's already fired.
115 timer_.Start(
116 FROM_HERE,
117 base::TimeDelta::FromMilliseconds(kIdleAppNameNotificationTimeoutMs),
118 base::Bind(&KioskModeIdleAppNameNotification::OnTimeout,
119 base::Unretained(this)));
123 void KioskModeIdleAppNameNotification::OnTimeout() {
124 show_notification_upon_next_user_activity_ = true;
127 } // namespace chromeos