Chromium Code Reviews| 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/chromeos/extensions/info_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/info_private_api.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 207 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 208 return connector->IsEnterpriseManaged(); | 208 return connector->IsEnterpriseManaged(); |
| 209 } | 209 } |
| 210 | 210 |
| 211 std::string GetClientId() { | 211 std::string GetClientId() { |
| 212 return IsEnterpriseKiosk() | 212 return IsEnterpriseKiosk() |
| 213 ? g_browser_process->metrics_service()->GetClientId() | 213 ? g_browser_process->metrics_service()->GetClientId() |
| 214 : std::string(); | 214 : std::string(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 std::unique_ptr<base::Value> GetUserTimezoneValue( | |
| 218 content::BrowserContext* browser_context) { | |
| 219 if (chromeos::system::PerUserTimezoneEnabled()) { | |
| 220 return base::WrapUnique<base::Value>( | |
| 221 Profile::FromBrowserContext(browser_context) | |
| 222 ->GetPrefs() | |
| 223 ->GetUserPrefValue(prefs::kUserTimezone) | |
| 224 ->DeepCopy()); | |
| 225 } else { | |
|
stevenjb
2017/05/30 16:47:18
no else after return
Alexander Alekseev
2017/07/06 06:30:28
Done.
| |
| 226 // TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr. | |
| 227 return base::WrapUnique<base::Value>( | |
| 228 chromeos::CrosSettings::Get() | |
| 229 ->GetPref(chromeos::kSystemTimezone) | |
| 230 ->DeepCopy()); | |
| 231 } | |
| 232 } | |
|
stevenjb
2017/05/30 16:47:18
I actually think this code would be better off in
Alexander Alekseev
2017/07/06 06:30:28
This is very UI-specific. I'd leave it here.
| |
| 233 | |
| 217 } // namespace | 234 } // namespace |
| 218 | 235 |
| 219 ChromeosInfoPrivateGetFunction::ChromeosInfoPrivateGetFunction() { | 236 ChromeosInfoPrivateGetFunction::ChromeosInfoPrivateGetFunction() { |
| 220 } | 237 } |
| 221 | 238 |
| 222 ChromeosInfoPrivateGetFunction::~ChromeosInfoPrivateGetFunction() { | 239 ChromeosInfoPrivateGetFunction::~ChromeosInfoPrivateGetFunction() { |
| 223 } | 240 } |
| 224 | 241 |
| 225 bool ChromeosInfoPrivateGetFunction::RunAsync() { | 242 bool ChromeosInfoPrivateGetFunction::RunAsync() { |
| 226 base::ListValue* list = NULL; | 243 base::ListValue* list = NULL; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 return base::MakeUnique<base::Value>(kDeviceTypeChromebook); | 335 return base::MakeUnique<base::Value>(kDeviceTypeChromebook); |
| 319 default: | 336 default: |
| 320 return base::MakeUnique<base::Value>(kDeviceTypeChromedevice); | 337 return base::MakeUnique<base::Value>(kDeviceTypeChromedevice); |
| 321 } | 338 } |
| 322 } | 339 } |
| 323 | 340 |
| 324 if (property_name == kPropertyClientId) { | 341 if (property_name == kPropertyClientId) { |
| 325 return base::MakeUnique<base::Value>(GetClientId()); | 342 return base::MakeUnique<base::Value>(GetClientId()); |
| 326 } | 343 } |
| 327 | 344 |
| 328 if (property_name == kPropertyTimezone) { | 345 if (property_name == kPropertyTimezone) |
| 329 // TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr. | 346 return GetUserTimezoneValue(context_); |
| 330 return base::WrapUnique<base::Value>( | |
| 331 chromeos::CrosSettings::Get() | |
| 332 ->GetPref(chromeos::kSystemTimezone) | |
| 333 ->DeepCopy()); | |
| 334 } | |
| 335 | 347 |
| 336 if (property_name == kPropertySupportedTimezones) { | 348 if (property_name == kPropertySupportedTimezones) { |
| 337 std::unique_ptr<base::ListValue> values = | 349 std::unique_ptr<base::ListValue> values = |
| 338 chromeos::system::GetTimezoneList(); | 350 chromeos::system::GetTimezoneList(); |
| 339 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required. | 351 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required. |
| 340 return std::move(values); | 352 return std::move(values); |
| 341 } | 353 } |
| 342 | 354 |
| 343 const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str()); | 355 const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str()); |
| 344 if (pref_name) { | 356 if (pref_name) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 356 | 368 |
| 357 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() { | 369 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() { |
| 358 } | 370 } |
| 359 | 371 |
| 360 ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { | 372 ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { |
| 361 std::string param_name; | 373 std::string param_name; |
| 362 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, ¶m_name)); | 374 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, ¶m_name)); |
| 363 if (param_name == kPropertyTimezone) { | 375 if (param_name == kPropertyTimezone) { |
| 364 std::string param_value; | 376 std::string param_value; |
| 365 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, ¶m_value)); | 377 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, ¶m_value)); |
| 366 chromeos::CrosSettings::Get()->Set(chromeos::kSystemTimezone, | 378 if (chromeos::system::PerUserTimezoneEnabled()) { |
| 367 base::Value(param_value)); | 379 Profile::FromBrowserContext(context_)->GetPrefs()->SetString( |
| 380 prefs::kUserTimezone, param_value); | |
| 381 } else { | |
| 382 chromeos::CrosSettings::Get()->Set(chromeos::kSystemTimezone, | |
| 383 base::Value(param_value)); | |
| 384 } | |
| 368 } else { | 385 } else { |
| 369 const char* pref_name = GetBoolPrefNameForApiProperty(param_name.c_str()); | 386 const char* pref_name = GetBoolPrefNameForApiProperty(param_name.c_str()); |
| 370 if (pref_name) { | 387 if (pref_name) { |
| 371 bool param_value; | 388 bool param_value; |
| 372 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, ¶m_value)); | 389 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, ¶m_value)); |
| 373 Profile::FromBrowserContext(context_)->GetPrefs()->SetBoolean( | 390 Profile::FromBrowserContext(context_)->GetPrefs()->SetBoolean( |
| 374 pref_name, | 391 pref_name, |
| 375 param_value); | 392 param_value); |
| 376 } else { | 393 } else { |
| 377 return RespondNow(Error(kPropertyNotFound, param_name)); | 394 return RespondNow(Error(kPropertyNotFound, param_name)); |
| 378 } | 395 } |
| 379 } | 396 } |
| 380 | 397 |
| 381 return RespondNow(NoArguments()); | 398 return RespondNow(NoArguments()); |
| 382 } | 399 } |
| 383 | 400 |
| 384 } // namespace extensions | 401 } // namespace extensions |
| OLD | NEW |