Commit c27752d0 authored by akuegel@chromium.org's avatar akuegel@chromium.org

Start in elevated mode when creating a new managed user profile.

BUG=222364
TEST=browser_tests


Review URL: https://chromiumcodereview.appspot.com/13778004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193433 0039d316-1c4b-4281-b951-d872f2087c98
parent 56be8f58
...@@ -104,7 +104,8 @@ void ManagedUserService::URLFilterContext::SetManualURLs( ...@@ -104,7 +104,8 @@ void ManagedUserService::URLFilterContext::SetManualURLs(
io_url_filter_, base::Owned(url_map.release()))); io_url_filter_, base::Owned(url_map.release())));
} }
ManagedUserService::ManagedUserService(Profile* profile) : profile_(profile) { ManagedUserService::ManagedUserService(Profile* profile)
: profile_(profile), startup_elevation_(false) {
} }
ManagedUserService::~ManagedUserService() { ManagedUserService::~ManagedUserService() {
......
...@@ -106,6 +106,14 @@ class ManagedUserService : public ProfileKeyedService, ...@@ -106,6 +106,14 @@ class ManagedUserService : public ProfileKeyedService,
// managed. // managed.
void Init(); void Init();
void set_startup_elevation(bool elevation) {
startup_elevation_ = elevation;
}
bool startup_elevation() const {
return startup_elevation_;
}
// extensions::ManagementPolicy::Provider implementation: // extensions::ManagementPolicy::Provider implementation:
virtual std::string GetDebugPolicyProviderName() const OVERRIDE; virtual std::string GetDebugPolicyProviderName() const OVERRIDE;
virtual bool UserMayLoad(const extensions::Extension* extension, virtual bool UserMayLoad(const extensions::Extension* extension,
...@@ -179,6 +187,9 @@ class ManagedUserService : public ProfileKeyedService, ...@@ -179,6 +187,9 @@ class ManagedUserService : public ProfileKeyedService,
// Owns us via the ProfileKeyedService mechanism. // Owns us via the ProfileKeyedService mechanism.
Profile* profile_; Profile* profile_;
// Is true if the managed user should start in elevated mode.
bool startup_elevation_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
PrefChangeRegistrar pref_change_registrar_; PrefChangeRegistrar pref_change_registrar_;
......
...@@ -108,7 +108,6 @@ cr.define('options', function() { ...@@ -108,7 +108,6 @@ cr.define('options', function() {
} }
if (!$('use-passphrase-checkbox').checked) if (!$('use-passphrase-checkbox').checked)
chrome.send('resetPassphrase'); chrome.send('resetPassphrase');
chrome.send('confirmManagedUserSettings');
SettingsDialog.prototype.handleConfirm.call(this); SettingsDialog.prototype.handleConfirm.call(this);
}, },
...@@ -161,6 +160,7 @@ cr.define('options', function() { ...@@ -161,6 +160,7 @@ cr.define('options', function() {
// Reset the authentication of the custodian. // Reset the authentication of the custodian.
this.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED; this.authenticationState = ManagedUserAuthentication.UNAUTHENTICATED;
chrome.send('setElevated', [false]); chrome.send('setElevated', [false]);
chrome.send('confirmManagedUserSettings');
}, },
}; };
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
#endif
using extensions::Extension; using extensions::Extension;
namespace { namespace {
...@@ -903,6 +907,7 @@ class ManagedModeBrowserCreatorTest : public InProcessBrowserTest { ...@@ -903,6 +907,7 @@ class ManagedModeBrowserCreatorTest : public InProcessBrowserTest {
} }
}; };
#if defined(ENABLE_MANAGED_USERS)
IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest, IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest,
StartupManagedModeProfile) { StartupManagedModeProfile) {
// Make this a managed profile. // Make this a managed profile.
...@@ -913,6 +918,9 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest, ...@@ -913,6 +918,9 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest,
CommandLine dummy(CommandLine::NO_PROGRAM); CommandLine dummy(CommandLine::NO_PROGRAM);
StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator, StartupBrowserCreatorImpl launch(base::FilePath(), dummy, &browser_creator,
chrome::startup::IS_FIRST_RUN); chrome::startup::IS_FIRST_RUN);
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false)); ASSERT_TRUE(launch.Launch(browser()->profile(), std::vector<GURL>(), false));
// This should have created a new browser window. // This should have created a new browser window.
...@@ -928,6 +936,14 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest, ...@@ -928,6 +936,14 @@ IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest,
GURL expected(GURL(std::string(chrome::kChromeUISettingsURL) + GURL expected(GURL(std::string(chrome::kChromeUISettingsURL) +
chrome::kManagedUserSettingsSubPage)); chrome::kManagedUserSettingsSubPage));
EXPECT_EQ(GURL(expected), web_contents->GetURL()); EXPECT_EQ(GURL(expected), web_contents->GetURL());
observer.Wait();
// Managed user should be in elevated state.
bool is_elevated = ManagedModeNavigationObserver::FromWebContents(
web_contents)->is_elevated();
EXPECT_TRUE(is_elevated);
} }
#endif // ENABLE_MANAGED_USERS
#endif // !OS_CHROMEOS #endif // !OS_CHROMEOS
...@@ -106,6 +106,11 @@ ...@@ -106,6 +106,11 @@
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#endif #endif
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h"
#endif
using content::ChildProcessSecurityPolicy; using content::ChildProcessSecurityPolicy;
using content::WebContents; using content::WebContents;
using extensions::Extension; using extensions::Extension;
...@@ -924,6 +929,7 @@ void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary( ...@@ -924,6 +929,7 @@ void StartupBrowserCreatorImpl::AddInfoBarsIfNecessary(
void StartupBrowserCreatorImpl::AddStartupURLs( void StartupBrowserCreatorImpl::AddStartupURLs(
std::vector<GURL>* startup_urls) const { std::vector<GURL>* startup_urls) const {
#if defined(ENABLE_MANAGED_USERS)
PrefService* prefs = profile_->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
bool has_reset_local_passphrase_switch = bool has_reset_local_passphrase_switch =
command_line_.HasSwitch(switches::kResetLocalPassphrase); command_line_.HasSwitch(switches::kResetLocalPassphrase);
...@@ -932,11 +938,15 @@ void StartupBrowserCreatorImpl::AddStartupURLs( ...@@ -932,11 +938,15 @@ void StartupBrowserCreatorImpl::AddStartupURLs(
startup_urls->insert(startup_urls->begin(), startup_urls->insert(startup_urls->begin(),
GURL(std::string(chrome::kChromeUISettingsURL) + GURL(std::string(chrome::kChromeUISettingsURL) +
chrome::kManagedUserSettingsSubPage)); chrome::kManagedUserSettingsSubPage));
ManagedUserService* service = ManagedUserServiceFactory::GetForProfile(
profile_);
service->set_startup_elevation(true);
if (has_reset_local_passphrase_switch) { if (has_reset_local_passphrase_switch) {
prefs->SetString(prefs::kManagedModeLocalPassphrase, std::string()); prefs->SetString(prefs::kManagedModeLocalPassphrase, std::string());
prefs->SetString(prefs::kManagedModeLocalSalt, std::string()); prefs->SetString(prefs::kManagedModeLocalSalt, std::string());
} }
} }
#endif
// If we have urls specified by the first run master preferences use them // If we have urls specified by the first run master preferences use them
// and nothing else. // and nothing else.
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/prefs/pref_service.h" #include "base/prefs/pref_service.h"
#include "base/time.h" #include "base/time.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
#include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service.h"
#include "chrome/browser/managed_mode/managed_user_service_factory.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h"
...@@ -92,7 +91,8 @@ void AddCurrentURLEntries(content::WebUI* web_ui, ListValue* entries) { ...@@ -92,7 +91,8 @@ void AddCurrentURLEntries(content::WebUI* web_ui, ListValue* entries) {
namespace options { namespace options {
ManagedUserSettingsHandler::ManagedUserSettingsHandler() { ManagedUserSettingsHandler::ManagedUserSettingsHandler()
: has_seen_settings_dialog_(false) {
} }
ManagedUserSettingsHandler::~ManagedUserSettingsHandler() { ManagedUserSettingsHandler::~ManagedUserSettingsHandler() {
...@@ -111,19 +111,14 @@ void ManagedUserSettingsHandler::InitializePage() { ...@@ -111,19 +111,14 @@ void ManagedUserSettingsHandler::InitializePage() {
switches::kEnableManagedUsers)) { switches::kEnableManagedUsers)) {
return; return;
} }
PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
base::FundamentalValue is_passphrase_set(!pref_service->GetString( bool passphrase_empty =
prefs::kManagedModeLocalPassphrase).empty()); pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty();
base::FundamentalValue is_passphrase_set(!passphrase_empty);
web_ui()->CallJavascriptFunction( web_ui()->CallJavascriptFunction(
"ManagedUserSettings.passphraseChanged", "ManagedUserSettings.passphraseChanged",
is_passphrase_set); is_passphrase_set);
if ((first_run::IsChromeFirstRun() &&
!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoFirstRun)) ||
CommandLine::ForCurrentProcess()->HasSwitch(
switches::kResetLocalPassphrase)) {
ManagedModeNavigationObserver::FromWebContents(
web_ui()->GetWebContents())->set_elevated(true);
}
// Populate the list. // Populate the list.
UpdateViewFromModel(); UpdateViewFromModel();
...@@ -132,8 +127,21 @@ void ManagedUserSettingsHandler::InitializePage() { ...@@ -132,8 +127,21 @@ void ManagedUserSettingsHandler::InitializePage() {
void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) {
start_time_ = base::TimeTicks::Now(); start_time_ = base::TimeTicks::Now();
content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings"));
if (ManagedModeNavigationObserver::FromWebContents( ManagedUserService* service = ManagedUserServiceFactory::GetForProfile(
web_ui()->GetWebContents())->is_elevated()) { Profile::FromWebUI(web_ui()));
ManagedModeNavigationObserver* observer =
ManagedModeNavigationObserver::FromWebContents(
web_ui()->GetWebContents());
// Check if we need to give initial elevation for startup of a new profile.
if (service->startup_elevation()) {
service->set_startup_elevation(false);
observer->set_elevated(true);
} else {
has_seen_settings_dialog_ = true;
}
if (observer->is_elevated()) {
web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated", web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated",
base::FundamentalValue(true)); base::FundamentalValue(true));
} }
...@@ -207,7 +215,8 @@ void ManagedUserSettingsHandler::RegisterMessages() { ...@@ -207,7 +215,8 @@ void ManagedUserSettingsHandler::RegisterMessages() {
} }
void ManagedUserSettingsHandler::SaveMetrics(const ListValue* args) { void ManagedUserSettingsHandler::SaveMetrics(const ListValue* args) {
if (first_run::IsChromeFirstRun()) { if (!has_seen_settings_dialog_) {
has_seen_settings_dialog_ = true;
UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsFirstRunTime", UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsFirstRunTime",
base::TimeTicks::Now() - start_time_); base::TimeTicks::Now() - start_time_);
} else { } else {
......
...@@ -58,6 +58,10 @@ class ManagedUserSettingsHandler : public OptionsPageUIHandler { ...@@ -58,6 +58,10 @@ class ManagedUserSettingsHandler : public OptionsPageUIHandler {
// service and updating the WebUI model. // service and updating the WebUI model.
void UpdateViewFromModel(); void UpdateViewFromModel();
// Stores if the user has already seen the managed user settings dialog. Is
// set to true when the page is opened, and the page had been opened before.
bool has_seen_settings_dialog_;
// For tracking how long the user spends on this page. // For tracking how long the user spends on this page.
base::TimeTicks start_time_; base::TimeTicks start_time_;
......
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