OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/lazy_instance.h" |
| 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chromeos/app_mode/kiosk_app_update_service.h" |
| 12 #include "chrome/browser/extensions/shell_window_registry.h" |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" |
| 14 #include "chrome/browser/policy/browser_policy_connector.h" |
| 15 #include "chrome/common/pref_names.h" |
| 16 |
| 17 using extensions::ShellWindowRegistry; |
| 18 |
| 19 namespace chromeos { |
| 20 |
| 21 namespace { |
| 22 |
| 23 // AppWindowWatcher watches for app window and exits the session when the |
| 24 // last app window is closed. |
| 25 class AppWindowWatcher : public ShellWindowRegistry::Observer { |
| 26 public: |
| 27 AppWindowWatcher() : window_registry_(NULL) {} |
| 28 virtual ~AppWindowWatcher() {} |
| 29 |
| 30 void Init(Profile* profile) { |
| 31 DCHECK(!window_registry_); |
| 32 window_registry_ = ShellWindowRegistry::Get(profile); |
| 33 if (window_registry_) |
| 34 window_registry_->AddObserver(this); |
| 35 } |
| 36 |
| 37 private: |
| 38 // extensions::ShellWindowRegistry::Observer overrides: |
| 39 virtual void OnShellWindowAdded(ShellWindow* shell_window) OVERRIDE {} |
| 40 virtual void OnShellWindowIconChanged(ShellWindow* shell_window) OVERRIDE {} |
| 41 virtual void OnShellWindowRemoved(ShellWindow* shell_window) OVERRIDE { |
| 42 if (window_registry_->shell_windows().empty()) { |
| 43 chrome::AttemptUserExit(); |
| 44 window_registry_->RemoveObserver(this); |
| 45 } |
| 46 } |
| 47 |
| 48 extensions::ShellWindowRegistry* window_registry_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(AppWindowWatcher); |
| 51 }; |
| 52 |
| 53 base::LazyInstance<AppWindowWatcher> app_window_watcher |
| 54 = LAZY_INSTANCE_INITIALIZER; |
| 55 |
| 56 } // namespace |
| 57 |
| 58 void InitAppSession(Profile* profile, const std::string& app_id) { |
| 59 // Binds the session lifetime with app window counts. |
| 60 CHECK(app_window_watcher == NULL); |
| 61 app_window_watcher.Get().Init(profile); |
| 62 |
| 63 // Set the app_id for the current instance of KioskAppUpdateService. |
| 64 KioskAppUpdateService* update_service = |
| 65 KioskAppUpdateServiceFactory::GetForProfile(profile); |
| 66 DCHECK(update_service); |
| 67 if (update_service) |
| 68 update_service->set_app_id(app_id); |
| 69 |
| 70 // If the device is not enterprise managed, set prefs to reboot after update. |
| 71 if (!g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) { |
| 72 PrefService* local_state = g_browser_process->local_state(); |
| 73 local_state->SetBoolean(prefs::kRebootAfterUpdate, true); |
| 74 } |
| 75 } |
| 76 |
| 77 } // namespace chromeos |
OLD | NEW |