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 "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/user_manager.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 GetChromeosInfoFunction::~GetChromeosInfoFunction() { | 47 GetChromeosInfoFunction::~GetChromeosInfoFunction() { |
48 } | 48 } |
49 | 49 |
50 bool GetChromeosInfoFunction::RunImpl() { | 50 bool GetChromeosInfoFunction::RunImpl() { |
51 ListValue* list = NULL; | 51 ListValue* list = NULL; |
52 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list)); | 52 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &list)); |
53 scoped_ptr<DictionaryValue> result(new DictionaryValue()); | 53 scoped_ptr<DictionaryValue> result(new DictionaryValue()); |
54 for (size_t i = 0; i < list->GetSize(); ++i) { | 54 for (size_t i = 0; i < list->GetSize(); ++i) { |
55 std::string property_name; | 55 std::string property_name; |
56 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); | 56 EXTENSION_FUNCTION_VALIDATE(list->GetString(i, &property_name)); |
57 Value* value = NULL; | 57 Value* value = GetValue(property_name); |
58 if (GetValue(property_name, &value)) | 58 if (value) |
59 result->Set(property_name, value); | 59 result->Set(property_name, value); |
60 } | 60 } |
61 SetResult(result.release()); | 61 SetResult(result.release()); |
62 SendResponse(true); | 62 SendResponse(true); |
63 return true; | 63 return true; |
64 } | 64 } |
65 | 65 |
66 bool GetChromeosInfoFunction::GetValue(const std::string& property_name, | 66 base::Value* GetChromeosInfoFunction::GetValue( |
67 Value** value) { | 67 const std::string& property_name) { |
68 if (property_name == kPropertyHWID) { | 68 if (property_name == kPropertyHWID) { |
69 std::string hwid; | 69 std::string hwid; |
70 chromeos::system::StatisticsProvider* provider = | 70 chromeos::system::StatisticsProvider* provider = |
71 chromeos::system::StatisticsProvider::GetInstance(); | 71 chromeos::system::StatisticsProvider::GetInstance(); |
72 provider->GetMachineStatistic(kHardwareClass, &hwid); | 72 provider->GetMachineStatistic(kHardwareClass, &hwid); |
73 *value = Value::CreateStringValue(hwid); | 73 return new base::StringValue(hwid); |
74 } else if (property_name == kPropertyHomeProvider) { | 74 } else if (property_name == kPropertyHomeProvider) { |
75 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 75 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
76 *value = Value::CreateStringValue(netlib->GetCellularHomeCarrierId()); | 76 return new base::StringValue(netlib->GetCellularHomeCarrierId()); |
77 } else if (property_name == kPropertyInitialLocale) { | 77 } else if (property_name == kPropertyInitialLocale) { |
78 *value = Value::CreateStringValue( | 78 return new base::StringValue( |
79 chromeos::WizardController::GetInitialLocale()); | 79 chromeos::WizardController::GetInitialLocale()); |
80 } else if (property_name == kPropertyBoard) { | 80 } else if (property_name == kPropertyBoard) { |
81 std::string board; | 81 std::string board; |
82 chromeos::system::StatisticsProvider* provider = | 82 chromeos::system::StatisticsProvider* provider = |
83 chromeos::system::StatisticsProvider::GetInstance(); | 83 chromeos::system::StatisticsProvider::GetInstance(); |
84 provider->GetMachineStatistic(kPropertyReleaseBoard, &board); | 84 provider->GetMachineStatistic(kPropertyReleaseBoard, &board); |
85 *value = Value::CreateStringValue(board); | 85 return new base::StringValue(board); |
86 } else if (property_name == kPropertyOwner) { | 86 } else if (property_name == kPropertyOwner) { |
87 *value = Value::CreateBooleanValue( | 87 return Value::CreateBooleanValue( |
88 chromeos::UserManager::Get()->IsCurrentUserOwner()); | 88 chromeos::UserManager::Get()->IsCurrentUserOwner()); |
89 } else { | |
90 LOG(ERROR) << "Unknown property request: " << property_name; | |
91 return false; | |
92 } | 89 } |
93 return true; | 90 |
| 91 DLOG(ERROR) << "Unknown property request: " << property_name; |
| 92 return NULL; |
94 } | 93 } |
95 | 94 |
96 } // namespace extensions | 95 } // namespace extensions |
OLD | NEW |