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

Unified Diff: chrome/browser/chromeos/login/app_launch_controller.cc

Issue 22914008: Refactor kiosk app launch to be part of login screen UI flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/app_launch_controller.cc
diff --git a/chrome/browser/chromeos/app_mode/startup_app_launcher.cc b/chrome/browser/chromeos/login/app_launch_controller.cc
similarity index 73%
rename from chrome/browser/chromeos/app_mode/startup_app_launcher.cc
rename to chrome/browser/chromeos/login/app_launch_controller.cc
index 8308bf05ba7566771231d1b25fc3d5df79840646..df23cdb121e98eb7c9970108f3db13f6bbee9863 100644
--- a/chrome/browser/chromeos/app_mode/startup_app_launcher.cc
+++ b/chrome/browser/chromeos/login/app_launch_controller.cc
@@ -2,10 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/chromeos/app_mode/startup_app_launcher.h"
+#include "chrome/browser/chromeos/login/app_launch_controller.h"
-#include "ash/shell.h"
-#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
@@ -14,17 +12,20 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/app_mode/app_session_lifetime.h"
#include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
+#include "chrome/browser/chromeos/login/login_display_host.h"
+#include "chrome/browser/chromeos/login/oobe_display.h"
#include "chrome/browser/chromeos/login/user_manager.h"
-#include "chrome/browser/chromeos/ui/app_launch_view.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/webstore_startup_installer.h"
#include "chrome/browser/lifetime/application_lifetime.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/profile_oauth2_token_service.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/token_service.h"
#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/browser/ui/extensions/application_launch.h"
+#include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
@@ -33,6 +34,7 @@
#include "content/public/browser/notification_service.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/gaia_constants.h"
+#include "ui/base/events/event.h"
using content::BrowserThread;
using extensions::Extension;
@@ -59,43 +61,50 @@ bool IsAppInstalled(Profile* profile, const std::string& app_id) {
} // namespace
-StartupAppLauncher::StartupAppLauncher(Profile* profile,
- const std::string& app_id)
- : profile_(profile),
+AppLaunchController::AppLaunchController(const std::string& app_id,
+ LoginDisplayHost* host,
+ OobeDisplay* oobe_display)
+ : profile_(NULL),
app_id_(app_id),
+ host_(host),
+ oobe_display_(oobe_display),
launch_splash_start_time_(0) {
- DCHECK(profile_);
+ app_launch_splash_screen_actor_=
+ oobe_display_->GetAppLaunchSplashScreenActor();
xiyuan 2013/08/15 18:19:42 nit: This can be part of the member initializer li
Tim Song 2013/08/16 19:07:59 Done.
DCHECK(Extension::IdIsValid(app_id_));
- DCHECK(ash::Shell::HasInstance());
- ash::Shell::GetInstance()->AddPreTargetHandler(this);
}
-StartupAppLauncher::~StartupAppLauncher() {
- DCHECK(ash::Shell::HasInstance());
- ash::Shell::GetInstance()->RemovePreTargetHandler(this);
+AppLaunchController::~AppLaunchController() {
}
-void StartupAppLauncher::Start() {
+void AppLaunchController::StartAppLaunch() {
launch_splash_start_time_ = base::TimeTicks::Now().ToInternalValue();
- DVLOG(1) << "Starting... connection = "
+ DVLOG(1) << "Starting app launch... connection = "
<< net::NetworkChangeNotifier::GetConnectionType();
- chromeos::ShowAppLaunchSplashScreen(app_id_);
- StartLoadingOAuthFile();
+
+ // TODO(tengs): Add a loading profile app launch state.
+ app_launch_splash_screen_actor_->SetDelegate(this);
+ app_launch_splash_screen_actor_->Show(app_id_);
+
+ // KioskProfileLoader manages its own lifetime.
+ (new KioskProfileLoader(KioskAppManager::Get(), app_id_, this))->Start();
xiyuan 2013/08/15 18:19:42 I know I started this managing-its-own-life thing
Tim Song 2013/08/16 19:07:59 Done. Now using a scoped_ptr.
}
-void StartupAppLauncher::StartLoadingOAuthFile() {
+void AppLaunchController::StartLoadingOAuthFile() {
+ app_launch_splash_screen_actor_->UpdateAppLaunchState(
+ AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE);
KioskOAuthParams* auth_params = new KioskOAuthParams();
BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE,
- base::Bind(&StartupAppLauncher::LoadOAuthFileOnBlockingPool,
+ base::Bind(&AppLaunchController::LoadOAuthFileOnBlockingPool,
auth_params),
- base::Bind(&StartupAppLauncher::OnOAuthFileLoaded,
+ base::Bind(&AppLaunchController::OnOAuthFileLoaded,
AsWeakPtr(),
base::Owned(auth_params)));
}
// static.
-void StartupAppLauncher::LoadOAuthFileOnBlockingPool(
+void AppLaunchController::LoadOAuthFileOnBlockingPool(
KioskOAuthParams* auth_params) {
int error_code = JSONFileValueSerializer::JSON_NO_ERROR;
std::string error_msg;
@@ -109,7 +118,6 @@ void StartupAppLauncher::LoadOAuthFileOnBlockingPool(
base::DictionaryValue* dict = NULL;
if (error_code != JSONFileValueSerializer::JSON_NO_ERROR ||
!value.get() || !value->GetAsDictionary(&dict)) {
- LOG(WARNING) << "Can't find auth file at " << auth_file.value();
return;
}
@@ -118,7 +126,7 @@ void StartupAppLauncher::LoadOAuthFileOnBlockingPool(
dict->GetString(kOAuthClientSecret, &auth_params->client_secret);
}
-void StartupAppLauncher::OnOAuthFileLoaded(KioskOAuthParams* auth_params) {
+void AppLaunchController::OnOAuthFileLoaded(KioskOAuthParams* auth_params) {
auth_params_ = *auth_params;
// Override chrome client_id and secret that will be used for identity
// API token minting.
@@ -133,23 +141,24 @@ void StartupAppLauncher::OnOAuthFileLoaded(KioskOAuthParams* auth_params) {
InitializeTokenService();
}
-void StartupAppLauncher::InitializeNetwork() {
- chromeos::UpdateAppLaunchSplashScreenState(
- chromeos::APP_LAUNCH_STATE_PREPARING_NETWORK);
+void AppLaunchController::InitializeNetwork() {
+ app_launch_splash_screen_actor_->UpdateAppLaunchState(
+ AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK);
+
// Set a maximum allowed wait time for network.
const int kMaxNetworkWaitSeconds = 5 * 60;
network_wait_timer_.Start(
FROM_HERE,
base::TimeDelta::FromSeconds(kMaxNetworkWaitSeconds),
- this, &StartupAppLauncher::OnNetworkWaitTimedout);
+ this, &AppLaunchController::OnNetworkWaitTimedout);
net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
OnNetworkChanged(net::NetworkChangeNotifier::GetConnectionType());
}
-void StartupAppLauncher::InitializeTokenService() {
- chromeos::UpdateAppLaunchSplashScreenState(
- chromeos::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE);
+void AppLaunchController::InitializeTokenService() {
+ app_launch_splash_screen_actor_->UpdateAppLaunchState(
+ AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_TOKEN_SERVICE);
ProfileOAuth2TokenService* profile_token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
if (profile_token_service->RefreshTokenIsAvailable()) {
@@ -163,7 +172,7 @@ void StartupAppLauncher::InitializeTokenService() {
// whichever comes first, both handlers call RemoveObserver on PO2TS. Handling
// any of the two events is the only way to resume the execution and enable
// Cleanup method to be called, self-invoking a destructor. In destructor
- // StartupAppLauncher is no longer an observer of PO2TS and there is no need
+ // AppLaunchController is no longer an observer of PO2TS and there is no need
// to call RemoveObserver again.
profile_token_service->AddObserver(this);
@@ -186,26 +195,46 @@ void StartupAppLauncher::InitializeTokenService() {
}
}
-void StartupAppLauncher::OnRefreshTokenAvailable(
+void AppLaunchController::OnRefreshTokenAvailable(
const std::string& account_id) {
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
->RemoveObserver(this);
InitializeNetwork();
}
-void StartupAppLauncher::OnRefreshTokensLoaded() {
+void AppLaunchController::OnRefreshTokensLoaded() {
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
->RemoveObserver(this);
InitializeNetwork();
}
-void StartupAppLauncher::Cleanup() {
- chromeos::CloseAppLaunchSplashScreen();
+void AppLaunchController::OnConfigureNetwork() {
+ // TODO(tengs): Implement network configuration in app launch.
+}
+
+void AppLaunchController::OnCancelAppLaunch() {
+ if (KioskAppManager::Get()->GetDisableBailoutShortcut())
+ return;
+
+ OnLaunchFailure(KioskAppLaunchError::USER_CANCEL);
+}
+
+void AppLaunchController::OnProfileLoaded(Profile* profile) {
+ profile_ = profile;
+ StartLoadingOAuthFile();
+}
- delete this;
+void AppLaunchController::OnProfileLoadFailed(
+ KioskAppLaunchError::Error error) {
+ OnLaunchFailure(error);
}
-void StartupAppLauncher::OnLaunchSuccess() {
+void AppLaunchController::Cleanup() {
+ if (host_)
+ host_->Finalize();
+}
+
+void AppLaunchController::OnLaunchSuccess() {
const int64 time_taken_ms = (base::TimeTicks::Now() -
base::TimeTicks::FromInternalValue(launch_splash_start_time_)).
InMilliseconds();
@@ -216,7 +245,7 @@ void StartupAppLauncher::OnLaunchSuccess() {
BrowserThread::PostDelayedTask(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&StartupAppLauncher::OnLaunchSuccess, AsWeakPtr()),
+ base::Bind(&AppLaunchController::OnLaunchSuccess, AsWeakPtr()),
base::TimeDelta::FromMilliseconds(
kAppInstallSplashScreenMinTimeMS - time_taken_ms));
return;
@@ -225,7 +254,7 @@ void StartupAppLauncher::OnLaunchSuccess() {
Cleanup();
}
-void StartupAppLauncher::OnLaunchFailure(KioskAppLaunchError::Error error) {
+void AppLaunchController::OnLaunchFailure(KioskAppLaunchError::Error error) {
DCHECK_NE(KioskAppLaunchError::NONE, error);
// Saves the error and ends the session to go back to login screen.
@@ -235,7 +264,7 @@ void StartupAppLauncher::OnLaunchFailure(KioskAppLaunchError::Error error) {
Cleanup();
}
-void StartupAppLauncher::Launch() {
+void AppLaunchController::Launch() {
const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
extension_service()->GetInstalledExtension(app_id_);
CHECK(extension);
@@ -260,12 +289,12 @@ void StartupAppLauncher::Launch() {
OnLaunchSuccess();
}
-void StartupAppLauncher::BeginInstall() {
+void AppLaunchController::BeginInstall() {
DVLOG(1) << "BeginInstall... connection = "
<< net::NetworkChangeNotifier::GetConnectionType();
- chromeos::UpdateAppLaunchSplashScreenState(
- chromeos::APP_LAUNCH_STATE_INSTALLING_APPLICATION);
+ app_launch_splash_screen_actor_->UpdateAppLaunchState(
+ AppLaunchSplashScreenActor::APP_LAUNCH_STATE_INSTALLING_APPLICATION);
if (IsAppInstalled(profile_, app_id_)) {
Launch();
@@ -276,11 +305,11 @@ void StartupAppLauncher::BeginInstall() {
app_id_,
profile_,
false,
- base::Bind(&StartupAppLauncher::InstallCallback, AsWeakPtr()));
+ base::Bind(&AppLaunchController::InstallCallback, AsWeakPtr()));
installer_->BeginInstall();
}
-void StartupAppLauncher::InstallCallback(bool success,
+void AppLaunchController::InstallCallback(bool success,
const std::string& error) {
installer_ = NULL;
if (success) {
@@ -289,7 +318,7 @@ void StartupAppLauncher::InstallCallback(bool success,
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
- base::Bind(&StartupAppLauncher::Launch, AsWeakPtr()));
+ base::Bind(&AppLaunchController::Launch, AsWeakPtr()));
return;
}
@@ -297,7 +326,7 @@ void StartupAppLauncher::InstallCallback(bool success,
OnLaunchFailure(KioskAppLaunchError::UNABLE_TO_INSTALL);
}
-void StartupAppLauncher::OnNetworkWaitTimedout() {
+void AppLaunchController::OnNetworkWaitTimedout() {
LOG(WARNING) << "OnNetworkWaitTimedout... connection = "
<< net::NetworkChangeNotifier::GetConnectionType();
// Timeout in waiting for online. Try the install anyway.
@@ -305,7 +334,7 @@ void StartupAppLauncher::OnNetworkWaitTimedout() {
BeginInstall();
}
-void StartupAppLauncher::OnNetworkChanged(
+void AppLaunchController::OnNetworkChanged(
net::NetworkChangeNotifier::ConnectionType type) {
DVLOG(1) << "OnNetworkChanged... connection = "
<< net::NetworkChangeNotifier::GetConnectionType();
@@ -320,20 +349,4 @@ void StartupAppLauncher::OnNetworkChanged(
}
}
-void StartupAppLauncher::OnKeyEvent(ui::KeyEvent* event) {
- if (event->type() != ui::ET_KEY_PRESSED)
- return;
-
- if (KioskAppManager::Get()->GetDisableBailoutShortcut())
- return;
-
- if (event->key_code() != ui::VKEY_S ||
- !(event->flags() & ui::EF_CONTROL_DOWN) ||
- !(event->flags() & ui::EF_ALT_DOWN)) {
- return;
- }
-
- OnLaunchFailure(KioskAppLaunchError::USER_CANCEL);
-}
-
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698