Commit ccc2add1 authored by xiyuan@chromium.org's avatar xiyuan@chromium.org

kiosk: Skip network check for offline enabled app.

BUG=333900

Review URL: https://codereview.chromium.org/149843004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250941 0039d316-1c4b-4281-b951-d872f2087c98
parent 4decf437
......@@ -39,6 +39,10 @@ class AppLaunchManager : public StartupAppLauncher::Delegate {
// network configure handling.
startup_app_launcher_->ContinueWithNetworkReady();
}
virtual bool IsNetworkReady() OVERRIDE {
// See comments above. Network is assumed to be online here.
return true;
}
virtual void OnLoadingOAuthFile() OVERRIDE {}
virtual void OnInitializingTokenService() OVERRIDE {}
virtual void OnInstallingApp() OVERRIDE {}
......
......@@ -34,6 +34,7 @@
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/kiosk_mode_info.h"
#include "extensions/common/manifest_handlers/offline_enabled_info.h"
#include "google_apis/gaia/gaia_auth_consumer.h"
#include "google_apis/gaia/gaia_constants.h"
#include "net/base/load_flags.h"
......@@ -134,10 +135,10 @@ class StartupAppLauncher::AppUpdateChecker
}
const Version& existing_version = *GetInstalledApp()->version();
Version update_version(update.version);
if (existing_version.IsValid() &&
update_version.IsValid() &&
update_version.CompareTo(existing_version) <= 0) {
const Version update_version(update.version);
if (!update_version.IsValid() ||
(existing_version.IsValid() &&
update_version.CompareTo(existing_version) <= 0)) {
launcher_->OnUpdateCheckNoUpdate();
return;
}
......@@ -261,8 +262,23 @@ void StartupAppLauncher::OnOAuthFileLoaded(KioskOAuthParams* auth_params) {
InitializeTokenService();
}
void StartupAppLauncher::InitializeNetwork() {
delegate_->InitializeNetwork();
void StartupAppLauncher::MaybeInitializeNetwork() {
const Extension* extension = extensions::ExtensionSystem::Get(profile_)->
extension_service()->GetInstalledExtension(app_id_);
const bool requires_network = !extension ||
!extensions::OfflineEnabledInfo::IsOfflineEnabled(extension);
if (requires_network) {
delegate_->InitializeNetwork();
return;
}
// Offline enabled app attempts update if network is ready. Otherwise,
// go directly to launch.
if (delegate_->IsNetworkReady())
ContinueWithNetworkReady();
else
OnReadyToLaunch();
}
void StartupAppLauncher::InitializeTokenService() {
......@@ -275,7 +291,7 @@ void StartupAppLauncher::InitializeTokenService() {
if (profile_token_service->RefreshTokenIsAvailable(
signin_manager->GetAuthenticatedAccountId()) ||
auth_params_.refresh_token.empty()) {
InitializeNetwork();
MaybeInitializeNetwork();
} else {
// Pass oauth2 refresh token from the auth file.
// TODO(zelidrag): We should probably remove this option after M27.
......@@ -301,13 +317,13 @@ void StartupAppLauncher::OnRefreshTokenAvailable(
const std::string& account_id) {
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
->RemoveObserver(this);
InitializeNetwork();
MaybeInitializeNetwork();
}
void StartupAppLauncher::OnRefreshTokensLoaded() {
ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)
->RemoveObserver(this);
InitializeNetwork();
MaybeInitializeNetwork();
}
void StartupAppLauncher::LaunchApp() {
......
......@@ -23,11 +23,12 @@ namespace chromeos {
// Launches the app at startup. The flow roughly looks like this:
// First call Initialize():
// - Checks if the app is installed in user profile (aka app profile);
// - If the app is installed, launch it and finish the flow;
// - If not installed, prepare to start install by checking network online
// state;
// - If network gets online, start to install the app from web store;
// - Attempts to load oauth token file. Stores the loaded tokens in
// |auth_params_|.
// - Initialize token service and inject |auth_params_| if needed.
// - Initialize network if app is not installed or not offline_enabled.
// - If network is online, install or update the app as needed.
// - After the app is installed/updated, launch it and finish the flow;
// Report OnLauncherInitialized() or OnLaunchFailed() to observers:
// - If all goes good, launches the app and finish the flow;
class StartupAppLauncher
......@@ -40,6 +41,9 @@ class StartupAppLauncher
// launch flow is paused until ContinueWithNetworkReady is called.
virtual void InitializeNetwork() = 0;
// Returns true if Internet is online.
virtual bool IsNetworkReady() = 0;
virtual void OnLoadingOAuthFile() = 0;
virtual void OnInitializingTokenService() = 0;
virtual void OnInstallingApp() = 0;
......@@ -96,7 +100,7 @@ class StartupAppLauncher
void UpdateAppData();
void InitializeTokenService();
void InitializeNetwork();
void MaybeInitializeNetwork();
void StartLoadingOAuthFile();
static void LoadOAuthFileOnBlockingPool(KioskOAuthParams* auth_params);
......
......@@ -304,6 +304,10 @@ void AppLaunchController::InitializeNetwork() {
AppLaunchSplashScreenActor::APP_LAUNCH_STATE_PREPARING_NETWORK);
}
bool AppLaunchController::IsNetworkReady() {
return app_launch_splash_screen_actor_->IsNetworkReady();
}
void AppLaunchController::OnLoadingOAuthFile() {
app_launch_splash_screen_actor_->UpdateAppLaunchState(
AppLaunchSplashScreenActor::APP_LAUNCH_STATE_LOADING_AUTH_FILE);
......
......@@ -91,6 +91,7 @@ class AppLaunchController
// StartupAppLauncher::Delegate overrides:
virtual void InitializeNetwork() OVERRIDE;
virtual bool IsNetworkReady() OVERRIDE;
virtual void OnLoadingOAuthFile() OVERRIDE;
virtual void OnInitializingTokenService() OVERRIDE;
virtual void OnInstallingApp() OVERRIDE;
......
......@@ -59,6 +59,9 @@ class AppLaunchSplashScreenActor {
// Shows the network error and configure UI.
virtual void ShowNetworkConfigureUI() = 0;
// Returns true if the default network has Internet access.
virtual bool IsNetworkReady() = 0;
};
} // namespace chromeos
......
......@@ -178,6 +178,10 @@ void AppLaunchSplashScreenHandler::ShowNetworkConfigureUI() {
error_screen_actor_->Show(OobeDisplay::SCREEN_APP_LAUNCH_SPLASH, NULL);
}
bool AppLaunchSplashScreenHandler::IsNetworkReady() {
return network_state_informer_->state() == NetworkStateInformer::ONLINE;
}
void AppLaunchSplashScreenHandler::OnNetworkReady() {
// Purposely leave blank because the online case is handled in UpdateState
// call below.
......
......@@ -43,6 +43,7 @@ class AppLaunchSplashScreenHandler
virtual void SetDelegate(
AppLaunchSplashScreenHandler::Delegate* delegate) OVERRIDE;
virtual void ShowNetworkConfigureUI() OVERRIDE;
virtual bool IsNetworkReady() OVERRIDE;
// NetworkStateInformer::NetworkStateInformerObserver implementation:
virtual void OnNetworkReady() OVERRIDE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment