Add board and isOwner properties to chromeosInfoPrivate

BUG=chrome-os-partner:9659
TEST=browser_tests:ExtensionApiTest.CustomizationPrivateTest


Review URL: https://chromiumcodereview.appspot.com/10832204

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150737 0039d316-1c4b-4281-b951-d872f2087c98
parent 7c7a4275
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/cros/network_library.h" #include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/login/wizard_controller.h"
#include "chrome/browser/chromeos/system/statistics_provider.h" #include "chrome/browser/chromeos/system/statistics_provider.h"
...@@ -27,6 +28,15 @@ const char kPropertyHomeProvider[] = "homeProvider"; ...@@ -27,6 +28,15 @@ const char kPropertyHomeProvider[] = "homeProvider";
// Key which corresponds to the initial_locale property. // Key which corresponds to the initial_locale property.
const char kPropertyInitialLocale[] = "initialLocale"; const char kPropertyInitialLocale[] = "initialLocale";
// Name of machine statistic property with board.
const char kPropertyReleaseBoard[] = "CHROMEOS_RELEASE_BOARD";
// Key which corresponds to the board property in JS.
const char kPropertyBoard[] = "board";
// Key which corresponds to the board property in JS.
const char kPropertyOwner[] = "isOwner";
} // namespace } // namespace
GetChromeosInfoFunction::GetChromeosInfoFunction() { GetChromeosInfoFunction::GetChromeosInfoFunction() {
...@@ -42,9 +52,9 @@ bool GetChromeosInfoFunction::RunImpl() { ...@@ -42,9 +52,9 @@ bool GetChromeosInfoFunction::RunImpl() {
for (size_t i = 0; i < list->GetSize(); ++i) { for (size_t i = 0; i < list->GetSize(); ++i) {
std::string property_name; std::string property_name;
EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name));
std::string value; Value* value = NULL;
if (GetValue(property_name, &value)) if (GetValue(property_name, &value))
result->Set(property_name, Value::CreateStringValue(value)); result->Set(property_name, value);
} }
SetResult(result.release()); SetResult(result.release());
SendResponse(true); SendResponse(true);
...@@ -52,17 +62,28 @@ bool GetChromeosInfoFunction::RunImpl() { ...@@ -52,17 +62,28 @@ bool GetChromeosInfoFunction::RunImpl() {
} }
bool GetChromeosInfoFunction::GetValue(const std::string& property_name, bool GetChromeosInfoFunction::GetValue(const std::string& property_name,
std::string* value) { Value** value) {
value->clear();
if (property_name == kPropertyHWID) { if (property_name == kPropertyHWID) {
std::string hwid;
chromeos::system::StatisticsProvider* provider = chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance(); chromeos::system::StatisticsProvider::GetInstance();
provider->GetMachineStatistic(kHardwareClass, value); provider->GetMachineStatistic(kHardwareClass, &hwid);
*value = Value::CreateStringValue(hwid);
} else if (property_name == kPropertyHomeProvider) { } else if (property_name == kPropertyHomeProvider) {
NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary();
(*value) = netlib->GetCellularHomeCarrierId(); *value = Value::CreateStringValue(netlib->GetCellularHomeCarrierId());
} else if (property_name == kPropertyInitialLocale) { } else if (property_name == kPropertyInitialLocale) {
*value = chromeos::WizardController::GetInitialLocale(); *value = Value::CreateStringValue(
chromeos::WizardController::GetInitialLocale());
} else if (property_name == kPropertyBoard) {
std::string board;
chromeos::system::StatisticsProvider* provider =
chromeos::system::StatisticsProvider::GetInstance();
provider->GetMachineStatistic(kPropertyReleaseBoard, &board);
*value = Value::CreateStringValue(board);
} else if (property_name == kPropertyOwner) {
*value = Value::CreateBooleanValue(
chromeos::UserManager::Get()->IsCurrentUserOwner());
} else { } else {
LOG(ERROR) << "Unknown property request: " << property_name; LOG(ERROR) << "Unknown property request: " << property_name;
return false; return false;
......
...@@ -20,7 +20,7 @@ class GetChromeosInfoFunction : public AsyncExtensionFunction { ...@@ -20,7 +20,7 @@ class GetChromeosInfoFunction : public AsyncExtensionFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
private: private:
bool GetValue(const std::string& property_name, std::string* value); bool GetValue(const std::string& property_name, Value** value);
DECLARE_EXTENSION_FUNCTION_NAME("chromeosInfoPrivate.get"); DECLARE_EXTENSION_FUNCTION_NAME("chromeosInfoPrivate.get");
}; };
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
"properties": { "properties": {
"hwid": {"type": "string", "optional": "true", "description": "Hardware ID"}, "hwid": {"type": "string", "optional": "true", "description": "Hardware ID"},
"homeProvider" : {"type": "string", "optional": "true", "description": "Home provider which is used by the cellular device"}, "homeProvider" : {"type": "string", "optional": "true", "description": "Home provider which is used by the cellular device"},
"initialLocale" : {"type": "string", "optional": "true", "description": "Initial locale for the device"} "initialLocale" : {"type": "string", "optional": "true", "description": "Initial locale for the device"},
"board" : {"type": "string", "optional": "true", "description": "Board name"},
"isOwner" : {"type": "boolean", "optional": "true", "description": "True if current logged in user is device owner"}
} }
} }
] ]
......
...@@ -56,5 +56,9 @@ function generateTestsForKeys(keys) { ...@@ -56,5 +56,9 @@ function generateTestsForKeys(keys) {
return tests; return tests;
} }
var tests = generateTestsForKeys(["hwid", "homeProvider", "initialLocale"]) var tests = generateTestsForKeys(["hwid",
"homeProvider",
"initialLocale",
"board",
"isOwner"])
chrome.test.runTests(tests); chrome.test.runTests(tests);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment