| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/extensions/echo_private_api.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 12 #include "chrome/common/extensions/extension.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 // For a given registration code type, returns the code value from the |
| 17 // underlying system. Caller owns the returned pointer. |
| 18 base::Value* GetValueForRegistrationCodeType(std::string& type) { |
| 19 // Possible ECHO code type and corresponding key name in StatisticsProvider. |
| 20 const std::string kCouponType = "COUPON_CODE"; |
| 21 const std::string kCouponCodeKey = "ubind_attribute"; |
| 22 const std::string kGroupType = "GROUP_CODE"; |
| 23 const std::string kGroupCodeKey = "gbind_attribute"; |
| 24 |
| 25 chromeos::system::StatisticsProvider* provider = |
| 26 chromeos::system::StatisticsProvider::GetInstance(); |
| 27 std::string result; |
| 28 if (type == kCouponType) |
| 29 provider->GetMachineStatistic(kCouponCodeKey, &result); |
| 30 else if (type == kGroupType) |
| 31 provider->GetMachineStatistic(kGroupCodeKey, &result); |
| 32 return Value::CreateStringValue(result); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 |
| 38 GetRegistrationCodeFunction::GetRegistrationCodeFunction() { |
| 39 } |
| 40 |
| 41 GetRegistrationCodeFunction::~GetRegistrationCodeFunction() { |
| 42 } |
| 43 |
| 44 bool GetRegistrationCodeFunction::RunImpl() { |
| 45 std::string type; |
| 46 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &type)); |
| 47 result_.reset(GetValueForRegistrationCodeType(type)); |
| 48 return true; |
| 49 } |
| OLD | NEW |