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

Side by Side Diff: chrome/browser/ui/webui/flags_ui.cc

Issue 13467023: Add differentiation between owner only and common flags on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make the owner param an enum. 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
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/flags_ui.h" 5 #include "chrome/browser/ui/webui/flags_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 //////////////////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////////////////
83 // 83 //
84 // FlagsDOMHandler 84 // FlagsDOMHandler
85 // 85 //
86 //////////////////////////////////////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////////
87 87
88 // The handler for Javascript messages for the about:flags page. 88 // The handler for Javascript messages for the about:flags page.
89 class FlagsDOMHandler : public WebUIMessageHandler { 89 class FlagsDOMHandler : public WebUIMessageHandler {
90 public: 90 public:
91 explicit FlagsDOMHandler(PrefService* prefs) : prefs_(prefs) {} 91 explicit FlagsDOMHandler(PrefService* prefs, bool owner)
92 : prefs_(prefs), owner_(owner) {}
92 virtual ~FlagsDOMHandler() {} 93 virtual ~FlagsDOMHandler() {}
93 94
94 // WebUIMessageHandler implementation. 95 // WebUIMessageHandler implementation.
95 virtual void RegisterMessages() OVERRIDE; 96 virtual void RegisterMessages() OVERRIDE;
96 97
97 // Callback for the "requestFlagsExperiments" message. 98 // Callback for the "requestFlagsExperiments" message.
98 void HandleRequestFlagsExperiments(const ListValue* args); 99 void HandleRequestFlagsExperiments(const ListValue* args);
99 100
100 // Callback for the "enableFlagsExperiment" message. 101 // Callback for the "enableFlagsExperiment" message.
101 void HandleEnableFlagsExperimentMessage(const ListValue* args); 102 void HandleEnableFlagsExperimentMessage(const ListValue* args);
102 103
103 // Callback for the "restartBrowser" message. Restores all tabs on restart. 104 // Callback for the "restartBrowser" message. Restores all tabs on restart.
104 void HandleRestartBrowser(const ListValue* args); 105 void HandleRestartBrowser(const ListValue* args);
105 106
106 // Callback for the "resetAllFlags" message. 107 // Callback for the "resetAllFlags" message.
107 void HandleResetAllFlags(const ListValue* args); 108 void HandleResetAllFlags(const ListValue* args);
108 109
109 private: 110 private:
110 PrefService* prefs_; 111 PrefService* prefs_;
112 bool owner_;
Nico 2013/04/16 21:40:24 Use your new enum for this too, instead of having
pastarmovj 2013/04/17 16:03:22 Done.
111 113
112 DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler); 114 DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler);
113 }; 115 };
114 116
115 void FlagsDOMHandler::RegisterMessages() { 117 void FlagsDOMHandler::RegisterMessages() {
116 web_ui()->RegisterMessageCallback("requestFlagsExperiments", 118 web_ui()->RegisterMessageCallback("requestFlagsExperiments",
117 base::Bind(&FlagsDOMHandler::HandleRequestFlagsExperiments, 119 base::Bind(&FlagsDOMHandler::HandleRequestFlagsExperiments,
118 base::Unretained(this))); 120 base::Unretained(this)));
119 web_ui()->RegisterMessageCallback("enableFlagsExperiment", 121 web_ui()->RegisterMessageCallback("enableFlagsExperiment",
120 base::Bind(&FlagsDOMHandler::HandleEnableFlagsExperimentMessage, 122 base::Bind(&FlagsDOMHandler::HandleEnableFlagsExperimentMessage,
121 base::Unretained(this))); 123 base::Unretained(this)));
122 web_ui()->RegisterMessageCallback("restartBrowser", 124 web_ui()->RegisterMessageCallback("restartBrowser",
123 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, 125 base::Bind(&FlagsDOMHandler::HandleRestartBrowser,
124 base::Unretained(this))); 126 base::Unretained(this)));
125 web_ui()->RegisterMessageCallback("resetAllFlags", 127 web_ui()->RegisterMessageCallback("resetAllFlags",
126 base::Bind(&FlagsDOMHandler::HandleResetAllFlags, 128 base::Bind(&FlagsDOMHandler::HandleResetAllFlags,
127 base::Unretained(this))); 129 base::Unretained(this)));
128 } 130 }
129 131
130 void FlagsDOMHandler::HandleRequestFlagsExperiments(const ListValue* args) { 132 void FlagsDOMHandler::HandleRequestFlagsExperiments(const ListValue* args) {
131 DictionaryValue results; 133 DictionaryValue results;
134 about_flags::FlagAccess access =
135 owner_ ? about_flags::kOwnerAccessToFlags :
136 about_flags::kGeneralAccessFlagsOnly;
132 results.Set("flagsExperiments", 137 results.Set("flagsExperiments",
133 about_flags::GetFlagsExperimentsData(prefs_)); 138 about_flags::GetFlagsExperimentsData(prefs_, access));
134 results.SetBoolean("needsRestart", 139 results.SetBoolean("needsRestart",
135 about_flags::IsRestartNeededToCommitChanges()); 140 about_flags::IsRestartNeededToCommitChanges());
136 web_ui()->CallJavascriptFunction("returnFlagsExperiments", results); 141 web_ui()->CallJavascriptFunction("returnFlagsExperiments", results);
137 } 142 }
138 143
139 void FlagsDOMHandler::HandleEnableFlagsExperimentMessage( 144 void FlagsDOMHandler::HandleEnableFlagsExperimentMessage(
140 const ListValue* args) { 145 const ListValue* args) {
141 DCHECK_EQ(2u, args->GetSize()); 146 DCHECK_EQ(2u, args->GetSize());
142 if (args->GetSize() != 2) 147 if (args->GetSize() != 2)
143 return; 148 return;
(...skipping 30 matching lines...) Expand all
174 : WebUIController(web_ui), 179 : WebUIController(web_ui),
175 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 180 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
176 Profile* profile = Profile::FromWebUI(web_ui); 181 Profile* profile = Profile::FromWebUI(web_ui);
177 182
178 #if defined(OS_CHROMEOS) 183 #if defined(OS_CHROMEOS)
179 chromeos::DeviceSettingsService::Get()->GetOwnershipStatusAsync( 184 chromeos::DeviceSettingsService::Get()->GetOwnershipStatusAsync(
180 base::Bind(&FlagsUI::FinishInitialization, 185 base::Bind(&FlagsUI::FinishInitialization,
181 weak_factory_.GetWeakPtr(), profile)); 186 weak_factory_.GetWeakPtr(), profile));
182 #else 187 #else
183 web_ui->AddMessageHandler( 188 web_ui->AddMessageHandler(
184 new FlagsDOMHandler(g_browser_process->local_state())); 189 new FlagsDOMHandler(g_browser_process->local_state(), true));
185 190
186 // Set up the about:flags source. 191 // Set up the about:flags source.
187 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); 192 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource());
188 #endif 193 #endif
189 } 194 }
190 195
191 FlagsUI::~FlagsUI() { 196 FlagsUI::~FlagsUI() {
192 } 197 }
193 198
194 // static 199 // static
(...skipping 15 matching lines...) Expand all
210 PrefRegistrySyncable::UNSYNCABLE_PREF); 215 PrefRegistrySyncable::UNSYNCABLE_PREF);
211 } 216 }
212 217
213 void FlagsUI::FinishInitialization( 218 void FlagsUI::FinishInitialization(
214 Profile* profile, 219 Profile* profile,
215 chromeos::DeviceSettingsService::OwnershipStatus status, 220 chromeos::DeviceSettingsService::OwnershipStatus status,
216 bool current_user_is_owner) { 221 bool current_user_is_owner) {
217 // On Chrome OS the owner can set system wide flags and other users can only 222 // On Chrome OS the owner can set system wide flags and other users can only
218 // set flags for their own session. 223 // set flags for their own session.
219 if (!current_user_is_owner) { 224 if (!current_user_is_owner) {
220 web_ui()->AddMessageHandler(new FlagsDOMHandler(profile->GetPrefs())); 225 web_ui()->AddMessageHandler(
226 new FlagsDOMHandler(profile->GetPrefs(), false));
221 } else { 227 } else {
222 web_ui()->AddMessageHandler( 228 web_ui()->AddMessageHandler(
223 new FlagsDOMHandler(g_browser_process->local_state())); 229 new FlagsDOMHandler(g_browser_process->local_state(), true));
224 // If the owner managed to set the flags pref on his own profile clear it 230 // If the owner managed to set the flags pref on his own profile clear it
225 // because it will never be accessible anymore. 231 // because it will never be accessible anymore.
226 if (profile->GetPrefs()->HasPrefPath(prefs::kEnabledLabsExperiments)) 232 if (profile->GetPrefs()->HasPrefPath(prefs::kEnabledLabsExperiments))
227 profile->GetPrefs()->ClearPref(prefs::kEnabledLabsExperiments); 233 profile->GetPrefs()->ClearPref(prefs::kEnabledLabsExperiments);
228 } 234 }
229 235
230 // Set up the about:flags source. 236 // Set up the about:flags source.
231 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); 237 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource());
232 } 238 }
233 #endif 239 #endif
OLDNEW
« chrome/browser/about_flags.cc ('K') | « chrome/browser/about_flags_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698