| OLD | NEW |
| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // | 168 // |
| 169 // FlagsUI | 169 // FlagsUI |
| 170 // | 170 // |
| 171 /////////////////////////////////////////////////////////////////////////////// | 171 /////////////////////////////////////////////////////////////////////////////// |
| 172 | 172 |
| 173 FlagsUI::FlagsUI(content::WebUI* web_ui) | 173 FlagsUI::FlagsUI(content::WebUI* web_ui) |
| 174 : WebUIController(web_ui), | 174 : WebUIController(web_ui), |
| 175 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 175 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 176 Profile* profile = Profile::FromWebUI(web_ui); | 176 Profile* profile = Profile::FromWebUI(web_ui); |
| 177 | 177 |
| 178 #ifdef OS_CHROMEOS | 178 #if defined(OS_CHROMEOS) |
| 179 chromeos::DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 179 chromeos::DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 180 base::Bind(&FlagsUI::FinishInitialization, | 180 base::Bind(&FlagsUI::FinishInitialization, |
| 181 weak_factory_.GetWeakPtr(), profile)); | 181 weak_factory_.GetWeakPtr(), profile)); |
| 182 #else | 182 #else |
| 183 web_ui->AddMessageHandler( | 183 web_ui->AddMessageHandler( |
| 184 new FlagsDOMHandler(g_browser_process->local_state())); | 184 new FlagsDOMHandler(g_browser_process->local_state())); |
| 185 | 185 |
| 186 // Set up the about:flags source. | 186 // Set up the about:flags source. |
| 187 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); | 187 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); |
| 188 #endif | 188 #endif |
| 189 } | 189 } |
| 190 | 190 |
| 191 FlagsUI::~FlagsUI() { | 191 FlagsUI::~FlagsUI() { |
| 192 } | 192 } |
| 193 | 193 |
| 194 // static | 194 // static |
| 195 base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( | 195 base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( |
| 196 ui::ScaleFactor scale_factor) { | 196 ui::ScaleFactor scale_factor) { |
| 197 return ResourceBundle::GetSharedInstance(). | 197 return ResourceBundle::GetSharedInstance(). |
| 198 LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); | 198 LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); |
| 199 } | 199 } |
| 200 | 200 |
| 201 // static | 201 // static |
| 202 void FlagsUI::RegisterPrefs(PrefRegistrySimple* registry) { | 202 void FlagsUI::RegisterPrefs(PrefRegistrySimple* registry) { |
| 203 registry->RegisterListPref(prefs::kEnabledLabsExperiments); | 203 registry->RegisterListPref(prefs::kEnabledLabsExperiments); |
| 204 } | 204 } |
| 205 | 205 |
| 206 #ifdef OS_CHROMEOS | 206 #if defined(OS_CHROMEOS) |
| 207 // static | 207 // static |
| 208 void FlagsUI::RegisterUserPrefs(PrefRegistrySyncable* registry) { | 208 void FlagsUI::RegisterUserPrefs(PrefRegistrySyncable* registry) { |
| 209 registry->RegisterListPref(prefs::kEnabledLabsExperiments, | 209 registry->RegisterListPref(prefs::kEnabledLabsExperiments, |
| 210 PrefRegistrySyncable::UNSYNCABLE_PREF); | 210 PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void FlagsUI::FinishInitialization( | 213 void FlagsUI::FinishInitialization( |
| 214 Profile* profile, | 214 Profile* profile, |
| 215 chromeos::DeviceSettingsService::OwnershipStatus status, | 215 chromeos::DeviceSettingsService::OwnershipStatus status, |
| 216 bool current_user_is_owner) { | 216 bool current_user_is_owner) { |
| 217 // On Chrome OS the owner can set system wide flags and other users can only | 217 // On Chrome OS the owner can set system wide flags and other users can only |
| 218 // set flags for their own session. | 218 // set flags for their own session. |
| 219 if (!current_user_is_owner) { | 219 if (!current_user_is_owner) { |
| 220 web_ui()->AddMessageHandler(new FlagsDOMHandler(profile->GetPrefs())); | 220 web_ui()->AddMessageHandler(new FlagsDOMHandler(profile->GetPrefs())); |
| 221 } else { | 221 } else { |
| 222 web_ui()->AddMessageHandler( | 222 web_ui()->AddMessageHandler( |
| 223 new FlagsDOMHandler(g_browser_process->local_state())); | 223 new FlagsDOMHandler(g_browser_process->local_state())); |
| 224 // If the owner managed to set the flags pref on his own profile clear it | 224 // If the owner managed to set the flags pref on his own profile clear it |
| 225 // because it will never be accessible anymore. | 225 // because it will never be accessible anymore. |
| 226 if (profile->GetPrefs()->HasPrefPath(prefs::kEnabledLabsExperiments)) | 226 if (profile->GetPrefs()->HasPrefPath(prefs::kEnabledLabsExperiments)) |
| 227 profile->GetPrefs()->ClearPref(prefs::kEnabledLabsExperiments); | 227 profile->GetPrefs()->ClearPref(prefs::kEnabledLabsExperiments); |
| 228 } | 228 } |
| 229 | 229 |
| 230 // Set up the about:flags source. | 230 // Set up the about:flags source. |
| 231 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); | 231 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); |
| 232 } | 232 } |
| 233 #endif | 233 #endif |
| OLD | NEW |