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

Side by Side Diff: chrome/browser/ui/webui/options/managed_user_settings_handler.cc

Issue 13778004: Start in elevated mode when creating a new managed user profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nit. Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/options/managed_user_settings_handler.h ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/options/managed_user_settings_handler.h" 5 #include "chrome/browser/ui/webui/options/managed_user_settings_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/first_run/first_run.h"
17 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" 16 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
18 #include "chrome/browser/managed_mode/managed_user_service.h" 17 #include "chrome/browser/managed_mode/managed_user_service.h"
19 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 18 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/user_metrics.h" 22 #include "content/public/browser/user_metrics.h"
24 #include "content/public/browser/web_ui.h" 23 #include "content/public/browser/web_ui.h"
25 #include "googleurl/src/url_canon.h" 24 #include "googleurl/src/url_canon.h"
26 #include "grit/chromium_strings.h" 25 #include "grit/chromium_strings.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 DCHECK(result); 84 DCHECK(result);
86 entries->Append( 85 entries->Append(
87 GetEntryForPattern(it.key(), allow ? "allow" : "block")); 86 GetEntryForPattern(it.key(), allow ? "allow" : "block"));
88 } 87 }
89 } 88 }
90 89
91 } // namespace 90 } // namespace
92 91
93 namespace options { 92 namespace options {
94 93
95 ManagedUserSettingsHandler::ManagedUserSettingsHandler() { 94 ManagedUserSettingsHandler::ManagedUserSettingsHandler()
95 : has_seen_settings_dialog_(false) {
96 } 96 }
97 97
98 ManagedUserSettingsHandler::~ManagedUserSettingsHandler() { 98 ManagedUserSettingsHandler::~ManagedUserSettingsHandler() {
99 } 99 }
100 100
101 void ManagedUserSettingsHandler::InitializeHandler() { 101 void ManagedUserSettingsHandler::InitializeHandler() {
102 pref_change_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs()); 102 pref_change_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs());
103 pref_change_registrar_.Add( 103 pref_change_registrar_.Add(
104 prefs::kManagedModeLocalPassphrase, 104 prefs::kManagedModeLocalPassphrase,
105 base::Bind(&ManagedUserSettingsHandler::OnLocalPassphraseChanged, 105 base::Bind(&ManagedUserSettingsHandler::OnLocalPassphraseChanged,
106 base::Unretained(this))); 106 base::Unretained(this)));
107 } 107 }
108 108
109 void ManagedUserSettingsHandler::InitializePage() { 109 void ManagedUserSettingsHandler::InitializePage() {
110 if (!CommandLine::ForCurrentProcess()->HasSwitch( 110 if (!CommandLine::ForCurrentProcess()->HasSwitch(
111 switches::kEnableManagedUsers)) { 111 switches::kEnableManagedUsers)) {
112 return; 112 return;
113 } 113 }
114
114 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 115 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
115 base::FundamentalValue is_passphrase_set(!pref_service->GetString( 116 bool passphrase_empty =
116 prefs::kManagedModeLocalPassphrase).empty()); 117 pref_service->GetString(prefs::kManagedModeLocalPassphrase).empty();
118 base::FundamentalValue is_passphrase_set(!passphrase_empty);
117 web_ui()->CallJavascriptFunction( 119 web_ui()->CallJavascriptFunction(
118 "ManagedUserSettings.passphraseChanged", 120 "ManagedUserSettings.passphraseChanged",
119 is_passphrase_set); 121 is_passphrase_set);
120 if ((first_run::IsChromeFirstRun() &&
121 !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoFirstRun)) ||
122 CommandLine::ForCurrentProcess()->HasSwitch(
123 switches::kResetLocalPassphrase)) {
124 ManagedModeNavigationObserver::FromWebContents(
125 web_ui()->GetWebContents())->set_elevated(true);
126 }
127 122
128 // Populate the list. 123 // Populate the list.
129 UpdateViewFromModel(); 124 UpdateViewFromModel();
130 } 125 }
131 126
132 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) { 127 void ManagedUserSettingsHandler::HandlePageOpened(const base::ListValue* args) {
133 start_time_ = base::TimeTicks::Now(); 128 start_time_ = base::TimeTicks::Now();
134 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings")); 129 content::RecordAction(UserMetricsAction("ManagedMode_OpenSettings"));
135 if (ManagedModeNavigationObserver::FromWebContents( 130 ManagedUserService* service = ManagedUserServiceFactory::GetForProfile(
136 web_ui()->GetWebContents())->is_elevated()) { 131 Profile::FromWebUI(web_ui()));
132 ManagedModeNavigationObserver* observer =
133 ManagedModeNavigationObserver::FromWebContents(
134 web_ui()->GetWebContents());
135
136 // Check if we need to give initial elevation for startup of a new profile.
137 if (service->startup_elevation()) {
138 service->set_startup_elevation(false);
139 observer->set_elevated(true);
140 } else {
141 has_seen_settings_dialog_ = true;
142 }
143
144 if (observer->is_elevated()) {
137 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated", 145 web_ui()->CallJavascriptFunction("ManagedUserSettings.isAuthenticated",
138 base::FundamentalValue(true)); 146 base::FundamentalValue(true));
139 } 147 }
140 } 148 }
141 149
142 void ManagedUserSettingsHandler::GetLocalizedValues( 150 void ManagedUserSettingsHandler::GetLocalizedValues(
143 base::DictionaryValue* localized_strings) { 151 base::DictionaryValue* localized_strings) {
144 DCHECK(localized_strings); 152 DCHECK(localized_strings);
145 153
146 static OptionsStringResource resources[] = { 154 static OptionsStringResource resources[] = {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 web_ui()->RegisterMessageCallback("setManualException", 208 web_ui()->RegisterMessageCallback("setManualException",
201 base::Bind(&ManagedUserSettingsHandler::SetManualException, 209 base::Bind(&ManagedUserSettingsHandler::SetManualException,
202 base::Unretained(this))); 210 base::Unretained(this)));
203 web_ui()->RegisterMessageCallback("checkManualExceptionValidity", 211 web_ui()->RegisterMessageCallback("checkManualExceptionValidity",
204 base::Bind( 212 base::Bind(
205 &ManagedUserSettingsHandler::CheckManualExceptionValidity, 213 &ManagedUserSettingsHandler::CheckManualExceptionValidity,
206 base::Unretained(this))); 214 base::Unretained(this)));
207 } 215 }
208 216
209 void ManagedUserSettingsHandler::SaveMetrics(const ListValue* args) { 217 void ManagedUserSettingsHandler::SaveMetrics(const ListValue* args) {
210 if (first_run::IsChromeFirstRun()) { 218 if (!has_seen_settings_dialog_) {
219 has_seen_settings_dialog_ = true;
211 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsFirstRunTime", 220 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsFirstRunTime",
212 base::TimeTicks::Now() - start_time_); 221 base::TimeTicks::Now() - start_time_);
213 } else { 222 } else {
214 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsModifyTime", 223 UMA_HISTOGRAM_LONG_TIMES("ManagedMode.UserSettingsModifyTime",
215 base::TimeTicks::Now() - start_time_); 224 base::TimeTicks::Now() - start_time_);
216 } 225 }
217 } 226 }
218 227
219 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() { 228 void ManagedUserSettingsHandler::OnLocalPassphraseChanged() {
220 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); 229 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 void ManagedUserSettingsHandler::UpdateViewFromModel() { 319 void ManagedUserSettingsHandler::UpdateViewFromModel() {
311 ListValue entries; 320 ListValue entries;
312 AddCurrentURLEntries(web_ui(), &entries); 321 AddCurrentURLEntries(web_ui(), &entries);
313 322
314 web_ui()->CallJavascriptFunction( 323 web_ui()->CallJavascriptFunction(
315 "ManagedUserSettings.setManualExceptions", 324 "ManagedUserSettings.setManualExceptions",
316 entries); 325 entries);
317 } 326 }
318 327
319 } // namespace options 328 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/managed_user_settings_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698