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/extensions/extension_info_private_api_chromeos.h" | 5 #include "chrome/browser/extensions/extension_info_private_api_chromeos.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/chromeos/cros/cros_library.h" | 8 #include "chrome/browser/chromeos/cros/cros_library.h" |
9 #include "chrome/browser/chromeos/cros/network_library.h" | 9 #include "chrome/browser/chromeos/cros/network_library.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" |
10 #include "chrome/browser/chromeos/login/wizard_controller.h" | 11 #include "chrome/browser/chromeos/login/wizard_controller.h" |
11 #include "chrome/browser/chromeos/system/statistics_provider.h" | 12 #include "chrome/browser/chromeos/system/statistics_provider.h" |
12 | 13 |
13 using chromeos::CrosLibrary; | 14 using chromeos::CrosLibrary; |
14 using chromeos::NetworkLibrary; | 15 using chromeos::NetworkLibrary; |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Name of machine statistic property with HWID. | 19 // Name of machine statistic property with HWID. |
19 const char kHardwareClass[] = "hardware_class"; | 20 const char kHardwareClass[] = "hardware_class"; |
20 | 21 |
21 // Key which corresponds to the HWID setting. | 22 // Key which corresponds to the HWID setting. |
22 const char kPropertyHWID[] = "hwid"; | 23 const char kPropertyHWID[] = "hwid"; |
23 | 24 |
24 // Key which corresponds to the home provider property. | 25 // Key which corresponds to the home provider property. |
25 const char kPropertyHomeProvider[] = "homeProvider"; | 26 const char kPropertyHomeProvider[] = "homeProvider"; |
26 | 27 |
27 // Key which corresponds to the initial_locale property. | 28 // Key which corresponds to the initial_locale property. |
28 const char kPropertyInitialLocale[] = "initialLocale"; | 29 const char kPropertyInitialLocale[] = "initialLocale"; |
29 | 30 |
| 31 // Name of machine statistic property with board. |
| 32 const char kPropertyReleaseBoard[] = "CHROMEOS_RELEASE_BOARD"; |
| 33 |
| 34 // Key which corresponds to the board property in JS. |
| 35 const char kPropertyBoard[] = "board"; |
| 36 |
| 37 // Key which corresponds to the board property in JS. |
| 38 const char kPropertyOwner[] = "isOwner"; |
| 39 |
30 } // namespace | 40 } // namespace |
31 | 41 |
32 GetChromeosInfoFunction::GetChromeosInfoFunction() { | 42 GetChromeosInfoFunction::GetChromeosInfoFunction() { |
33 } | 43 } |
34 | 44 |
35 GetChromeosInfoFunction::~GetChromeosInfoFunction() { | 45 GetChromeosInfoFunction::~GetChromeosInfoFunction() { |
36 } | 46 } |
37 | 47 |
38 bool GetChromeosInfoFunction::RunImpl() { | 48 bool GetChromeosInfoFunction::RunImpl() { |
39 ListValue* list = NULL; | 49 ListValue* list = NULL; |
40 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list)); | 50 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list)); |
41 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 51 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
42 for (size_t i = 0; i < list->GetSize(); ++i) { | 52 for (size_t i = 0; i < list->GetSize(); ++i) { |
43 std::string property_name; | 53 std::string property_name; |
44 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); | 54 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); |
45 std::string value; | 55 Value* value = NULL; |
46 if (GetValue(property_name, &value)) | 56 if (GetValue(property_name, &value)) |
47 result->Set(property_name, Value::CreateStringValue(value)); | 57 result->Set(property_name, value); |
48 } | 58 } |
49 SetResult(result.release()); | 59 SetResult(result.release()); |
50 SendResponse(true); | 60 SendResponse(true); |
51 return true; | 61 return true; |
52 } | 62 } |
53 | 63 |
54 bool GetChromeosInfoFunction::GetValue(const std::string& property_name, | 64 bool GetChromeosInfoFunction::GetValue(const std::string& property_name, |
55 std::string* value) { | 65 Value** value) { |
56 value->clear(); | |
57 if (property_name == kPropertyHWID) { | 66 if (property_name == kPropertyHWID) { |
| 67 std::string hwid; |
58 chromeos::system::StatisticsProvider* provider = | 68 chromeos::system::StatisticsProvider* provider = |
59 chromeos::system::StatisticsProvider::GetInstance(); | 69 chromeos::system::StatisticsProvider::GetInstance(); |
60 provider->GetMachineStatistic(kHardwareClass, value); | 70 provider->GetMachineStatistic(kHardwareClass, &hwid); |
| 71 *value = Value::CreateStringValue(hwid); |
61 } else if (property_name == kPropertyHomeProvider) { | 72 } else if (property_name == kPropertyHomeProvider) { |
62 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 73 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
63 (*value) = netlib->GetCellularHomeCarrierId(); | 74 *value = Value::CreateStringValue(netlib->GetCellularHomeCarrierId()); |
64 } else if (property_name == kPropertyInitialLocale) { | 75 } else if (property_name == kPropertyInitialLocale) { |
65 *value = chromeos::WizardController::GetInitialLocale(); | 76 *value = Value::CreateStringValue( |
| 77 chromeos::WizardController::GetInitialLocale()); |
| 78 } else if (property_name == kPropertyBoard) { |
| 79 std::string board; |
| 80 chromeos::system::StatisticsProvider* provider = |
| 81 chromeos::system::StatisticsProvider::GetInstance(); |
| 82 provider->GetMachineStatistic(kPropertyReleaseBoard, &board); |
| 83 *value = Value::CreateStringValue(board); |
| 84 } else if (property_name == kPropertyOwner) { |
| 85 *value = Value::CreateBooleanValue( |
| 86 chromeos::UserManager::Get()->IsCurrentUserOwner()); |
66 } else { | 87 } else { |
67 LOG(ERROR) << "Unknown property request: " << property_name; | 88 LOG(ERROR) << "Unknown property request: " << property_name; |
68 return false; | 89 return false; |
69 } | 90 } |
70 return true; | 91 return true; |
71 } | 92 } |
OLD | NEW |