Commit 6340b5d5 authored by atwilson's avatar atwilson Committed by Commit bot

Updated KioskAppManager to track whether an app was auto-launched.

We want to restrict certain behavior (such as network reporting) to
auto-launched kiosk apps. This change updates KioskAppManager to track
whether a given app was auto-launched (which is different from whether a
given app is *currently* set to auto-launch, because policies can change
while an app is running).

BUG=452968

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

Cr-Commit-Position: refs/heads/master@{#315110}
parent 609de457
......@@ -100,15 +100,21 @@ void KioskAppManager::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(kKioskDictionaryName);
}
KioskAppManager::App::App(const KioskAppData& data, bool is_extension_pending)
KioskAppManager::App::App(
const KioskAppData& data,
bool is_extension_pending,
bool auto_launched_with_zero_delay)
: app_id(data.app_id()),
user_id(data.user_id()),
name(data.name()),
icon(data.icon()),
is_loading(data.IsLoading() || is_extension_pending) {
is_loading(data.IsLoading() || is_extension_pending),
was_auto_launched_with_zero_delay(auto_launched_with_zero_delay) {
}
KioskAppManager::App::App() : is_loading(false) {}
KioskAppManager::App::App() : is_loading(false),
was_auto_launched_with_zero_delay(false) {}
KioskAppManager::App::~App() {}
std::string KioskAppManager::GetAutoLaunchApp() const {
......@@ -131,6 +137,12 @@ void KioskAppManager::SetAutoLaunchApp(const std::string& app_id) {
kAccountsPrefDeviceLocalAccountAutoLoginDelay, 0);
}
void KioskAppManager::SetAppWasAutoLaunchedWithZeroDelay(
const std::string& app_id) {
DCHECK_EQ(auto_launch_app_id_, app_id);
currently_auto_launched_with_zero_delay_app_ = app_id;
}
void KioskAppManager::EnableConsumerKioskAutoLaunch(
const KioskAppManager::EnableKioskAutoLaunchCallback& callback) {
policy::BrowserPolicyConnectorChromeOS* connector =
......@@ -311,9 +323,11 @@ void KioskAppManager::GetApps(Apps* apps) const {
apps->reserve(apps_.size());
for (size_t i = 0; i < apps_.size(); ++i) {
const KioskAppData& app_data = *apps_[i];
if (app_data.status() != KioskAppData::STATUS_ERROR)
if (app_data.status() != KioskAppData::STATUS_ERROR) {
apps->push_back(App(
app_data, external_cache_->IsExtensionPending(app_data.app_id())));
app_data, external_cache_->IsExtensionPending(app_data.app_id()),
app_data.app_id() == currently_auto_launched_with_zero_delay_app_));
}
}
}
......@@ -322,7 +336,8 @@ bool KioskAppManager::GetApp(const std::string& app_id, App* app) const {
if (!data)
return false;
*app = App(*data, external_cache_->IsExtensionPending(app_id));
*app = App(*data, external_cache_->IsExtensionPending(app_id),
app_id == currently_auto_launched_with_zero_delay_app_);
return true;
}
......
......@@ -59,7 +59,9 @@ class KioskAppManager : public KioskAppDataDelegate,
// Struct to hold app info returned from GetApps() call.
struct App {
App(const KioskAppData& data, bool is_extension_pending);
App(const KioskAppData& data,
bool is_extension_pending,
bool was_auto_launched_with_zero_delay);
App();
~App();
......@@ -68,6 +70,7 @@ class KioskAppManager : public KioskAppDataDelegate,
std::string name;
gfx::ImageSkia icon;
bool is_loading;
bool was_auto_launched_with_zero_delay;
};
typedef std::vector<App> Apps;
......@@ -123,6 +126,9 @@ class KioskAppManager : public KioskAppDataDelegate,
// Returns true if owner/policy enabled auto launch.
bool IsAutoLaunchEnabled() const;
// Returns true if current app was auto launched with zero delay.
bool IsCurrentAppAutoLaunchedWithZeroDelay() const;
// Enable auto launch setter.
void SetEnableAutoLaunch(bool value);
......@@ -195,6 +201,12 @@ class KioskAppManager : public KioskAppDataDelegate,
bool external_loader_created() const { return external_loader_created_; }
// Notifies the KioskAppManager that a given app was auto-launched
// automatically with no delay on startup. Certain privacy-sensitive
// kiosk-mode behavior (such as network reporting) is only enabled for
// kiosk apps that are immediately auto-launched on startup.
void SetAppWasAutoLaunchedWithZeroDelay(const std::string& app_id);
private:
friend struct base::DefaultLazyInstanceTraits<KioskAppManager>;
friend struct base::DefaultDeleter<KioskAppManager>;
......@@ -261,6 +273,7 @@ class KioskAppManager : public KioskAppDataDelegate,
bool ownership_established_;
ScopedVector<KioskAppData> apps_;
std::string auto_launch_app_id_;
std::string currently_auto_launched_with_zero_delay_app_;
ObserverList<KioskAppManagerObserver, true> observers_;
scoped_ptr<CrosSettings::ObserverSubscription>
......
......@@ -361,11 +361,26 @@ IN_PROC_BROWSER_TEST_F(KioskAppManagerTest, Basic) {
manager()->SetAutoLaunchApp("fake_app_1");
EXPECT_EQ("fake_app_1", manager()->GetAutoLaunchApp());
// Make sure that if an app was auto launched with zero delay, it is reflected
// in the app data.
KioskAppManager::App app;
manager()->GetApp("fake_app_1", &app);
EXPECT_FALSE(app.was_auto_launched_with_zero_delay);
manager()->SetAppWasAutoLaunchedWithZeroDelay("fake_app_1");
manager()->GetApp("fake_app_1", &app);
EXPECT_TRUE(app.was_auto_launched_with_zero_delay);
// Clear the auto launch app.
manager()->SetAutoLaunchApp("");
EXPECT_EQ("", manager()->GetAutoLaunchApp());
EXPECT_FALSE(manager()->IsAutoLaunchEnabled());
// App should still report it was auto launched with zero delay, even though
// it is no longer set to auto launch in the future.
manager()->GetApp("fake_app_1", &app);
EXPECT_TRUE(app.was_auto_launched_with_zero_delay);
// Set another auto launch app.
manager()->SetAutoLaunchApp("fake_app_2");
EXPECT_EQ("fake_app_2", manager()->GetAutoLaunchApp());
......
......@@ -29,6 +29,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chromeos/login/app_launch_splash_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "chromeos/settings/cros_settings_names.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h"
#include "extensions/browser/app_window/app_window.h"
......@@ -126,7 +127,7 @@ AppLaunchController::~AppLaunchController() {
app_launch_splash_screen_actor_->SetDelegate(NULL);
}
void AppLaunchController::StartAppLaunch() {
void AppLaunchController::StartAppLaunch(bool is_auto_launch) {
DVLOG(1) << "Starting kiosk mode...";
webui_visible_ = host_->GetWebUILoginView()->webui_visible();
......@@ -143,6 +144,20 @@ void AppLaunchController::StartAppLaunch() {
KioskAppManager::App app;
CHECK(KioskAppManager::Get());
CHECK(KioskAppManager::Get()->GetApp(app_id_, &app));
if (is_auto_launch) {
int delay;
if (!CrosSettings::Get()->GetInteger(
kAccountsPrefDeviceLocalAccountAutoLoginDelay, &delay)) {
delay = 0;
}
DCHECK_EQ(0, delay) << "Kiosks do not support non-zero auto-login delays";
// If we are launching a kiosk app with zero delay, mark it appropriately.
if (delay == 0)
KioskAppManager::Get()->SetAppWasAutoLaunchedWithZeroDelay(app_id_);
}
kiosk_profile_loader_.reset(
new KioskProfileLoader(app.user_id, false, this));
kiosk_profile_loader_->Start();
......
......@@ -45,7 +45,9 @@ class AppLaunchController
~AppLaunchController() override;
void StartAppLaunch();
// Starts launching an app - set |auto_launch| to true if the app is being
// auto-launched with zero delay.
void StartAppLaunch(bool auto_launch);
bool waiting_for_network() { return waiting_for_network_; }
bool network_wait_timedout() { return network_wait_timedout_; }
......
......@@ -926,7 +926,8 @@ void ExistingUserController::LoginAsPublicSession(
void ExistingUserController::LoginAsKioskApp(const std::string& app_id,
bool diagnostic_mode) {
host_->StartAppLaunch(app_id, diagnostic_mode);
const bool auto_start = false;
host_->StartAppLaunch(app_id, diagnostic_mode, auto_start);
}
void ExistingUserController::ConfigurePublicSessionAutoLogin() {
......
......@@ -807,6 +807,9 @@ class KioskTest : public OobeBaseTest {
IN_PROC_BROWSER_TEST_F(KioskTest, InstallAndLaunchApp) {
StartAppLaunchFromLoginScreen(SimulateNetworkOnlineClosure());
WaitForAppLaunchSuccess();
KioskAppManager::App app;
ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app));
EXPECT_FALSE(app.was_auto_launched_with_zero_delay);
}
IN_PROC_BROWSER_TEST_F(KioskTest, ZoomSupport) {
......@@ -1082,6 +1085,10 @@ IN_PROC_BROWSER_TEST_F(KioskTest, AutolaunchWarningConfirm) {
EXPECT_TRUE(KioskAppManager::Get()->IsAutoLaunchEnabled());
WaitForAppLaunchSuccess();
KioskAppManager::App app;
ASSERT_TRUE(KioskAppManager::Get()->GetApp(test_app_id(), &app));
EXPECT_TRUE(app.was_auto_launched_with_zero_delay);
}
IN_PROC_BROWSER_TEST_F(KioskTest, KioskEnableCancel) {
......@@ -1256,10 +1263,10 @@ IN_PROC_BROWSER_TEST_F(KioskTest, NoEnterpriseAutoLaunchWhenUntrusted) {
// Trigger the code that handles auto-launch on enterprise devices. This would
// normally be called from ShowLoginWizard(), which runs so early that it is
// not to inject an auto-launch policy before it runs.
// not possible to inject an auto-launch policy before it runs.
LoginDisplayHost* login_display_host = LoginDisplayHostImpl::default_host();
ASSERT_TRUE(login_display_host);
login_display_host->StartAppLaunch(test_app_id(), false);
login_display_host->StartAppLaunch(test_app_id(), false, true);
// Check that no launch has started.
EXPECT_FALSE(login_display_host->GetAppLaunchController());
......
......@@ -89,9 +89,11 @@ class LoginDisplayHost {
// Initiates authentication network prewarming.
virtual void PrewarmAuthentication() = 0;
// Starts app launch splash screen.
// Starts app launch splash screen. If |is_auto_launch| is true, the app is
// being auto-launched with no delay.
virtual void StartAppLaunch(const std::string& app_id,
bool diagnostic_mode) = 0;
bool diagnostic_mode,
bool is_auto_launch) = 0;
// Starts the demo app launch.
virtual void StartDemoAppLaunch() = 0;
......
......@@ -667,7 +667,8 @@ void LoginDisplayHostImpl::StartDemoAppLaunch() {
}
void LoginDisplayHostImpl::StartAppLaunch(const std::string& app_id,
bool diagnostic_mode) {
bool diagnostic_mode,
bool auto_launch) {
VLOG(1) << "Login WebUI >> start app launch.";
SetStatusAreaVisible(false);
......@@ -678,7 +679,8 @@ void LoginDisplayHostImpl::StartAppLaunch(const std::string& app_id,
&LoginDisplayHostImpl::StartAppLaunch,
pointer_factory_.GetWeakPtr(),
app_id,
diagnostic_mode));
diagnostic_mode,
auto_launch));
if (status == CrosSettingsProvider::TEMPORARILY_UNTRUSTED)
return;
......@@ -708,7 +710,7 @@ void LoginDisplayHostImpl::StartAppLaunch(const std::string& app_id,
app_launch_controller_.reset(new AppLaunchController(
app_id, diagnostic_mode, this, GetOobeUI()));
app_launch_controller_->StartAppLaunch();
app_launch_controller_->StartAppLaunch(auto_launch);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -1189,8 +1191,11 @@ void ShowLoginWizard(const std::string& first_screen_name) {
if (show_app_launch_splash_screen) {
const std::string& auto_launch_app_id =
KioskAppManager::Get()->GetAutoLaunchApp();
const bool diagnostic_mode = false;
const bool auto_launch = true;
display_host->StartAppLaunch(auto_launch_app_id,
false /* diagnostic_mode */);
diagnostic_mode,
auto_launch);
return;
}
......
......@@ -83,7 +83,10 @@ class LoginDisplayHostImpl : public LoginDisplayHost,
void StartSignInScreen(const LoginScreenContext& context) override;
void OnPreferencesChanged() override;
void PrewarmAuthentication() override;
void StartAppLaunch(const std::string& app_id, bool diagnostic_mode) override;
void StartAppLaunch(
const std::string& app_id,
bool diagnostic_mode,
bool auto_launch) override;
void StartDemoAppLaunch() override;
// Creates WizardController instance.
......
......@@ -35,7 +35,7 @@ class MockLoginDisplayHost : public LoginDisplayHost {
MOCK_METHOD0(ResumeSignInScreen, void(void));
MOCK_METHOD0(OnPreferencesChanged, void(void));
MOCK_METHOD0(PrewarmAuthentication, void(void));
MOCK_METHOD2(StartAppLaunch, void(const std::string&, bool));
MOCK_METHOD3(StartAppLaunch, void(const std::string&, bool, bool));
MOCK_METHOD0(StartDemoAppLaunch, void(void));
private:
......
......@@ -1111,7 +1111,9 @@ void WizardController::AutoLaunchKioskApp() {
return;
}
host_->StartAppLaunch(app_id, false /* diagnostic_mode */);
const bool diagnostic_mode = false;
const bool auto_launch = true;
host_->StartAppLaunch(app_id, diagnostic_mode, auto_launch);
}
// static
......
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