| 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 |
| 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/app_mode/app_mode_utils.h" | 14 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/arc/arc_util.h" | 16 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 16 #include "chrome/browser/chromeos/login/startup_utils.h" | 17 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 19 #include "chrome/browser/chromeos/system/timezone_util.h" | 20 #include "chrome/browser/chromeos/system/timezone_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ChromeosInfoPrivateGetFunction::~ChromeosInfoPrivateGetFunction() { | 222 ChromeosInfoPrivateGetFunction::~ChromeosInfoPrivateGetFunction() { |
| 222 } | 223 } |
| 223 | 224 |
| 224 bool ChromeosInfoPrivateGetFunction::RunAsync() { | 225 bool ChromeosInfoPrivateGetFunction::RunAsync() { |
| 225 base::ListValue* list = NULL; | 226 base::ListValue* list = NULL; |
| 226 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list)); | 227 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list)); |
| 227 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 228 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| 228 for (size_t i = 0; i < list->GetSize(); ++i) { | 229 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 229 std::string property_name; | 230 std::string property_name; |
| 230 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); | 231 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); |
| 231 base::Value* value = GetValue(property_name); | 232 std::unique_ptr<base::Value> value = GetValue(property_name); |
| 232 if (value) | 233 if (value) |
| 233 result->Set(property_name, value); | 234 result->Set(property_name, std::move(value)); |
| 234 } | 235 } |
| 235 SetResult(std::move(result)); | 236 SetResult(std::move(result)); |
| 236 SendResponse(true); | 237 SendResponse(true); |
| 237 return true; | 238 return true; |
| 238 } | 239 } |
| 239 | 240 |
| 240 base::Value* ChromeosInfoPrivateGetFunction::GetValue( | 241 std::unique_ptr<base::Value> ChromeosInfoPrivateGetFunction::GetValue( |
| 241 const std::string& property_name) { | 242 const std::string& property_name) { |
| 242 if (property_name == kPropertyHWID) { | 243 if (property_name == kPropertyHWID) { |
| 243 std::string hwid; | 244 std::string hwid; |
| 244 chromeos::system::StatisticsProvider* provider = | 245 chromeos::system::StatisticsProvider* provider = |
| 245 chromeos::system::StatisticsProvider::GetInstance(); | 246 chromeos::system::StatisticsProvider::GetInstance(); |
| 246 provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid); | 247 provider->GetMachineStatistic(chromeos::system::kHardwareClassKey, &hwid); |
| 247 return new base::Value(hwid); | 248 return base::MakeUnique<base::Value>(hwid); |
| 248 } | 249 } |
| 249 | 250 |
| 250 if (property_name == kPropertyCustomizationID) { | 251 if (property_name == kPropertyCustomizationID) { |
| 251 std::string customization_id; | 252 std::string customization_id; |
| 252 chromeos::system::StatisticsProvider* provider = | 253 chromeos::system::StatisticsProvider* provider = |
| 253 chromeos::system::StatisticsProvider::GetInstance(); | 254 chromeos::system::StatisticsProvider::GetInstance(); |
| 254 provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey, | 255 provider->GetMachineStatistic(chromeos::system::kCustomizationIdKey, |
| 255 &customization_id); | 256 &customization_id); |
| 256 return new base::Value(customization_id); | 257 return base::MakeUnique<base::Value>(customization_id); |
| 257 } | 258 } |
| 258 | 259 |
| 259 if (property_name == kPropertyHomeProvider) { | 260 if (property_name == kPropertyHomeProvider) { |
| 260 const chromeos::DeviceState* cellular_device = | 261 const chromeos::DeviceState* cellular_device = |
| 261 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( | 262 NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType( |
| 262 chromeos::NetworkTypePattern::Cellular()); | 263 chromeos::NetworkTypePattern::Cellular()); |
| 263 std::string home_provider_id; | 264 std::string home_provider_id; |
| 264 if (cellular_device) | 265 if (cellular_device) |
| 265 home_provider_id = cellular_device->home_provider_id(); | 266 home_provider_id = cellular_device->home_provider_id(); |
| 266 return new base::Value(home_provider_id); | 267 return base::MakeUnique<base::Value>(home_provider_id); |
| 267 } | 268 } |
| 268 | 269 |
| 269 if (property_name == kPropertyInitialLocale) { | 270 if (property_name == kPropertyInitialLocale) { |
| 270 return new base::Value(chromeos::StartupUtils::GetInitialLocale()); | 271 return base::MakeUnique<base::Value>( |
| 272 chromeos::StartupUtils::GetInitialLocale()); |
| 271 } | 273 } |
| 272 | 274 |
| 273 if (property_name == kPropertyBoard) { | 275 if (property_name == kPropertyBoard) { |
| 274 return new base::Value(base::SysInfo::GetLsbReleaseBoard()); | 276 return base::MakeUnique<base::Value>(base::SysInfo::GetLsbReleaseBoard()); |
| 275 } | 277 } |
| 276 | 278 |
| 277 if (property_name == kPropertyOwner) { | 279 if (property_name == kPropertyOwner) { |
| 278 return new base::Value( | 280 return base::MakeUnique<base::Value>( |
| 279 user_manager::UserManager::Get()->IsCurrentUserOwner()); | 281 user_manager::UserManager::Get()->IsCurrentUserOwner()); |
| 280 } | 282 } |
| 281 | 283 |
| 282 if (property_name == kPropertySessionType) { | 284 if (property_name == kPropertySessionType) { |
| 283 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()) | 285 if (ExtensionsBrowserClient::Get()->IsRunningInForcedAppMode()) |
| 284 return new base::Value(kSessionTypeKiosk); | 286 return base::MakeUnique<base::Value>(kSessionTypeKiosk); |
| 285 if (ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount()) | 287 if (ExtensionsBrowserClient::Get()->IsLoggedInAsPublicAccount()) |
| 286 return new base::Value(kSessionTypePublicSession); | 288 return base::MakeUnique<base::Value>(kSessionTypePublicSession); |
| 287 return new base::Value(kSessionTypeNormal); | 289 return base::MakeUnique<base::Value>(kSessionTypeNormal); |
| 288 } | 290 } |
| 289 | 291 |
| 290 if (property_name == kPropertyPlayStoreStatus) { | 292 if (property_name == kPropertyPlayStoreStatus) { |
| 291 if (arc::IsArcAllowedForProfile(Profile::FromBrowserContext(context_))) | 293 if (arc::IsArcAllowedForProfile(Profile::FromBrowserContext(context_))) |
| 292 return new base::Value(kPlayStoreStatusEnabled); | 294 return base::MakeUnique<base::Value>(kPlayStoreStatusEnabled); |
| 293 if (arc::IsArcAvailable()) | 295 if (arc::IsArcAvailable()) |
| 294 return new base::Value(kPlayStoreStatusAvailable); | 296 return base::MakeUnique<base::Value>(kPlayStoreStatusAvailable); |
| 295 return new base::Value(kPlayStoreStatusNotAvailable); | 297 return base::MakeUnique<base::Value>(kPlayStoreStatusNotAvailable); |
| 296 } | 298 } |
| 297 | 299 |
| 298 if (property_name == kPropertyManagedDeviceStatus) { | 300 if (property_name == kPropertyManagedDeviceStatus) { |
| 299 policy::BrowserPolicyConnectorChromeOS* connector = | 301 policy::BrowserPolicyConnectorChromeOS* connector = |
| 300 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 302 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 301 if (connector->IsEnterpriseManaged()) { | 303 if (connector->IsEnterpriseManaged()) { |
| 302 return new base::Value(kManagedDeviceStatusManaged); | 304 return base::MakeUnique<base::Value>(kManagedDeviceStatusManaged); |
| 303 } | 305 } |
| 304 return new base::Value(kManagedDeviceStatusNotManaged); | 306 return base::MakeUnique<base::Value>(kManagedDeviceStatusNotManaged); |
| 305 } | 307 } |
| 306 | 308 |
| 307 if (property_name == kPropertyDeviceType) { | 309 if (property_name == kPropertyDeviceType) { |
| 308 switch (chromeos::GetDeviceType()) { | 310 switch (chromeos::GetDeviceType()) { |
| 309 case chromeos::DeviceType::kChromebox: | 311 case chromeos::DeviceType::kChromebox: |
| 310 return new base::Value(kDeviceTypeChromebox); | 312 return base::MakeUnique<base::Value>(kDeviceTypeChromebox); |
| 311 case chromeos::DeviceType::kChromebase: | 313 case chromeos::DeviceType::kChromebase: |
| 312 return new base::Value(kDeviceTypeChromebase); | 314 return base::MakeUnique<base::Value>(kDeviceTypeChromebase); |
| 313 case chromeos::DeviceType::kChromebit: | 315 case chromeos::DeviceType::kChromebit: |
| 314 return new base::Value(kDeviceTypeChromebit); | 316 return base::MakeUnique<base::Value>(kDeviceTypeChromebit); |
| 315 case chromeos::DeviceType::kChromebook: | 317 case chromeos::DeviceType::kChromebook: |
| 316 return new base::Value(kDeviceTypeChromebook); | 318 return base::MakeUnique<base::Value>(kDeviceTypeChromebook); |
| 317 default: | 319 default: |
| 318 return new base::Value(kDeviceTypeChromedevice); | 320 return base::MakeUnique<base::Value>(kDeviceTypeChromedevice); |
| 319 } | 321 } |
| 320 } | 322 } |
| 321 | 323 |
| 322 if (property_name == kPropertyClientId) { | 324 if (property_name == kPropertyClientId) { |
| 323 return new base::Value(GetClientId()); | 325 return base::MakeUnique<base::Value>(GetClientId()); |
| 324 } | 326 } |
| 325 | 327 |
| 326 if (property_name == kPropertyTimezone) { | 328 if (property_name == kPropertyTimezone) { |
| 327 return chromeos::CrosSettings::Get()->GetPref( | 329 // TODO(crbug.com/697817): Convert CrosSettings::Get to take a unique_ptr. |
| 328 chromeos::kSystemTimezone)->DeepCopy(); | 330 return base::WrapUnique<base::Value>( |
| 331 chromeos::CrosSettings::Get() |
| 332 ->GetPref(chromeos::kSystemTimezone) |
| 333 ->DeepCopy()); |
| 329 } | 334 } |
| 330 | 335 |
| 331 if (property_name == kPropertySupportedTimezones) { | 336 if (property_name == kPropertySupportedTimezones) { |
| 332 std::unique_ptr<base::ListValue> values = | 337 std::unique_ptr<base::ListValue> values = |
| 333 chromeos::system::GetTimezoneList(); | 338 chromeos::system::GetTimezoneList(); |
| 334 return values.release(); | 339 // TODO(crbug.com/703565): remove std::move() once Xcode 9.0+ is required. |
| 340 return std::move(values); |
| 335 } | 341 } |
| 336 | 342 |
| 337 const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str()); | 343 const char* pref_name = GetBoolPrefNameForApiProperty(property_name.c_str()); |
| 338 if (pref_name) { | 344 if (pref_name) { |
| 339 return new base::Value( | 345 return base::MakeUnique<base::Value>( |
| 340 Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean( | 346 Profile::FromBrowserContext(context_)->GetPrefs()->GetBoolean( |
| 341 pref_name)); | 347 pref_name)); |
| 342 } | 348 } |
| 343 | 349 |
| 344 DLOG(ERROR) << "Unknown property request: " << property_name; | 350 DLOG(ERROR) << "Unknown property request: " << property_name; |
| 345 return NULL; | 351 return nullptr; |
| 346 } | 352 } |
| 347 | 353 |
| 348 ChromeosInfoPrivateSetFunction::ChromeosInfoPrivateSetFunction() { | 354 ChromeosInfoPrivateSetFunction::ChromeosInfoPrivateSetFunction() { |
| 349 } | 355 } |
| 350 | 356 |
| 351 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() { | 357 ChromeosInfoPrivateSetFunction::~ChromeosInfoPrivateSetFunction() { |
| 352 } | 358 } |
| 353 | 359 |
| 354 ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { | 360 ExtensionFunction::ResponseAction ChromeosInfoPrivateSetFunction::Run() { |
| 355 std::string param_name; | 361 std::string param_name; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 369 param_value); | 375 param_value); |
| 370 } else { | 376 } else { |
| 371 return RespondNow(Error(kPropertyNotFound, param_name)); | 377 return RespondNow(Error(kPropertyNotFound, param_name)); |
| 372 } | 378 } |
| 373 } | 379 } |
| 374 | 380 |
| 375 return RespondNow(NoArguments()); | 381 return RespondNow(NoArguments()); |
| 376 } | 382 } |
| 377 | 383 |
| 378 } // namespace extensions | 384 } // namespace extensions |
| OLD | NEW |