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

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

Issue 873873002: kiosk: Close on the last window of kiosk app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/app_session_lifetime.h" 5 #include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 20 matching lines...) Expand all
31 #include "extensions/browser/app_window/app_window_registry.h" 31 #include "extensions/browser/app_window/app_window_registry.h"
32 32
33 using extensions::AppWindow; 33 using extensions::AppWindow;
34 using extensions::AppWindowRegistry; 34 using extensions::AppWindowRegistry;
35 35
36 namespace chromeos { 36 namespace chromeos {
37 37
38 namespace { 38 namespace {
39 39
40 // AppWindowHandler watches for app window and exits the session when the 40 // AppWindowHandler watches for app window and exits the session when the
41 // last app window is closed. 41 // last window of a given app is closed.
42 class AppWindowHandler : public AppWindowRegistry::Observer { 42 class AppWindowHandler : public AppWindowRegistry::Observer {
43 public: 43 public:
44 AppWindowHandler() : window_registry_(NULL) {} 44 AppWindowHandler() : window_registry_(NULL) {}
45 ~AppWindowHandler() override {} 45 ~AppWindowHandler() override {}
46 46
47 void Init(Profile* profile) { 47 void Init(Profile* profile, const std::string& app_id) {
48 DCHECK(!window_registry_); 48 DCHECK(!window_registry_);
49 window_registry_ = AppWindowRegistry::Get(profile); 49 window_registry_ = AppWindowRegistry::Get(profile);
50 if (window_registry_) 50 if (window_registry_)
51 window_registry_->AddObserver(this); 51 window_registry_->AddObserver(this);
52 app_id_ = app_id;
52 } 53 }
53 54
54 private: 55 private:
55 // extensions::AppWindowRegistry::Observer overrides: 56 // extensions::AppWindowRegistry::Observer overrides:
56 void OnAppWindowRemoved(AppWindow* app_window) override { 57 void OnAppWindowRemoved(AppWindow* app_window) override {
57 if (window_registry_->app_windows().empty()) { 58 if (window_registry_->GetAppWindowsForApp(app_id_).empty()) {
58 if (DemoAppLauncher::IsDemoAppSession( 59 if (DemoAppLauncher::IsDemoAppSession(
59 user_manager::UserManager::Get()->GetActiveUser()->email())) { 60 user_manager::UserManager::Get()->GetActiveUser()->email())) {
60 // If we were in demo mode, we disabled all our network technologies, 61 // If we were in demo mode, we disabled all our network technologies,
61 // re-enable them. 62 // re-enable them.
62 NetworkStateHandler* handler = 63 NetworkStateHandler* handler =
63 NetworkHandler::Get()->network_state_handler(); 64 NetworkHandler::Get()->network_state_handler();
64 handler->SetTechnologyEnabled( 65 handler->SetTechnologyEnabled(
65 NetworkTypePattern::NonVirtual(), 66 NetworkTypePattern::NonVirtual(),
66 true, 67 true,
67 chromeos::network_handler::ErrorCallback()); 68 chromeos::network_handler::ErrorCallback());
68 } 69 }
69 chrome::AttemptUserExit(); 70 chrome::AttemptUserExit();
70 window_registry_->RemoveObserver(this); 71 window_registry_->RemoveObserver(this);
71 } 72 }
72 } 73 }
73 74
74 AppWindowRegistry* window_registry_; 75 AppWindowRegistry* window_registry_;
76 std::string app_id_;
bartfab (slow) 2015/01/26 15:59:46 Nit: const.
xiyuan 2015/01/26 17:21:32 Cannot use const here because we use it as a AppWi
75 77
76 DISALLOW_COPY_AND_ASSIGN(AppWindowHandler); 78 DISALLOW_COPY_AND_ASSIGN(AppWindowHandler);
77 }; 79 };
78 80
79 base::LazyInstance<AppWindowHandler> app_window_handler 81 base::LazyInstance<AppWindowHandler> app_window_handler
80 = LAZY_INSTANCE_INITIALIZER; 82 = LAZY_INSTANCE_INITIALIZER;
81 83
82 // BrowserWindowHandler monitors Browser object being created during 84 // BrowserWindowHandler monitors Browser object being created during
83 // a kiosk session, log info such as URL so that the code path could be 85 // a kiosk session, log info such as URL so that the code path could be
84 // fixed and closes the just opened browser window. 86 // fixed and closes the just opened browser window.
(...skipping 29 matching lines...) Expand all
114 }; 116 };
115 117
116 base::LazyInstance<BrowserWindowHandler> browser_window_handler 118 base::LazyInstance<BrowserWindowHandler> browser_window_handler
117 = LAZY_INSTANCE_INITIALIZER; 119 = LAZY_INSTANCE_INITIALIZER;
118 120
119 } // namespace 121 } // namespace
120 122
121 void InitAppSession(Profile* profile, const std::string& app_id) { 123 void InitAppSession(Profile* profile, const std::string& app_id) {
122 // Binds the session lifetime with app window counts. 124 // Binds the session lifetime with app window counts.
123 CHECK(app_window_handler == NULL); 125 CHECK(app_window_handler == NULL);
124 app_window_handler.Get().Init(profile); 126 app_window_handler.Get().Init(profile, app_id);
125 127
126 CHECK(browser_window_handler == NULL); 128 CHECK(browser_window_handler == NULL);
127 browser_window_handler.Get(); 129 browser_window_handler.Get();
128 130
129 // For a demo app, we don't need to either setup the update service or 131 // For a demo app, we don't need to either setup the update service or
130 // the idle app name notification. 132 // the idle app name notification.
131 if (DemoAppLauncher::IsDemoAppSession( 133 if (DemoAppLauncher::IsDemoAppSession(
132 user_manager::UserManager::Get()->GetActiveUser()->email())) 134 user_manager::UserManager::Get()->GetActiveUser()->email()))
133 return; 135 return;
134 136
(...skipping 13 matching lines...) Expand all
148 policy::BrowserPolicyConnectorChromeOS* connector = 150 policy::BrowserPolicyConnectorChromeOS* connector =
149 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 151 g_browser_process->platform_part()->browser_policy_connector_chromeos();
150 if (!connector->IsEnterpriseManaged()) { 152 if (!connector->IsEnterpriseManaged()) {
151 PrefService* local_state = g_browser_process->local_state(); 153 PrefService* local_state = g_browser_process->local_state();
152 local_state->SetBoolean(prefs::kRebootAfterUpdate, true); 154 local_state->SetBoolean(prefs::kRebootAfterUpdate, true);
153 KioskModeIdleAppNameNotification::Initialize(); 155 KioskModeIdleAppNameNotification::Initialize();
154 } 156 }
155 } 157 }
156 158
157 } // namespace chromeos 159 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698