| 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/echo_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/echo_private_api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 16 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/chromeos/system/statistics_provider.h" | 18 #include "chrome/browser/chromeos/system/statistics_provider.h" |
| 18 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace { | 24 GetRegistrationCodeFunction::GetRegistrationCodeFunction() { |
| 25 } |
| 24 | 26 |
| 25 // For a given registration code type, returns the code value from the | 27 GetRegistrationCodeFunction::~GetRegistrationCodeFunction() { |
| 26 // underlying system. Caller owns the returned pointer. | 28 } |
| 27 base::Value* GetValueForRegistrationCodeType(std::string& type) { | 29 |
| 30 void GetRegistrationCodeFunction::GetRegistrationCode(const std::string& type) { |
| 31 if (!chromeos::KioskModeSettings::Get()->is_initialized()) { |
| 32 chromeos::KioskModeSettings::Get()->Initialize(base::Bind( |
| 33 &GetRegistrationCodeFunction::GetRegistrationCode, |
| 34 base::Unretained(this), |
| 35 type)); |
| 36 return; |
| 37 } |
| 28 // Possible ECHO code type and corresponding key name in StatisticsProvider. | 38 // Possible ECHO code type and corresponding key name in StatisticsProvider. |
| 29 const std::string kCouponType = "COUPON_CODE"; | 39 const std::string kCouponType = "COUPON_CODE"; |
| 30 const std::string kCouponCodeKey = "ubind_attribute"; | 40 const std::string kCouponCodeKey = "ubind_attribute"; |
| 31 const std::string kGroupType = "GROUP_CODE"; | 41 const std::string kGroupType = "GROUP_CODE"; |
| 32 const std::string kGroupCodeKey = "gbind_attribute"; | 42 const std::string kGroupCodeKey = "gbind_attribute"; |
| 33 | 43 |
| 34 chromeos::system::StatisticsProvider* provider = | 44 chromeos::system::StatisticsProvider* provider = |
| 35 chromeos::system::StatisticsProvider::GetInstance(); | 45 chromeos::system::StatisticsProvider::GetInstance(); |
| 36 std::string result; | 46 std::string result; |
| 37 if (!chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) { | 47 if (!chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) { |
| 38 // In Kiosk mode, we effectively disable the registration API | 48 // In Kiosk mode, we effectively disable the registration API |
| 39 // by always returning an empty code. | 49 // by always returning an empty code. |
| 40 if (type == kCouponType) | 50 if (type == kCouponType) |
| 41 provider->GetMachineStatistic(kCouponCodeKey, &result); | 51 provider->GetMachineStatistic(kCouponCodeKey, &result); |
| 42 else if (type == kGroupType) | 52 else if (type == kGroupType) |
| 43 provider->GetMachineStatistic(kGroupCodeKey, &result); | 53 provider->GetMachineStatistic(kGroupCodeKey, &result); |
| 44 } | 54 } |
| 45 return new base::StringValue(result); | 55 SetResult(new base::StringValue(result)); |
| 46 } | 56 SendResponse(true); |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 | |
| 51 GetRegistrationCodeFunction::GetRegistrationCodeFunction() { | |
| 52 } | |
| 53 | |
| 54 GetRegistrationCodeFunction::~GetRegistrationCodeFunction() { | |
| 55 } | 57 } |
| 56 | 58 |
| 57 bool GetRegistrationCodeFunction::RunImpl() { | 59 bool GetRegistrationCodeFunction::RunImpl() { |
| 58 std::string type; | 60 std::string type; |
| 59 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &type)); | 61 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &type)); |
| 60 SetResult(GetValueForRegistrationCodeType(type)); | 62 GetRegistrationCode(type); |
| 61 return true; | 63 return true; |
| 62 } | 64 } |
| 63 | 65 |
| 64 GetOobeTimestampFunction::GetOobeTimestampFunction() { | 66 GetOobeTimestampFunction::GetOobeTimestampFunction() { |
| 65 } | 67 } |
| 66 | 68 |
| 67 GetOobeTimestampFunction::~GetOobeTimestampFunction() { | 69 GetOobeTimestampFunction::~GetOobeTimestampFunction() { |
| 68 } | 70 } |
| 69 | 71 |
| 70 bool GetOobeTimestampFunction::RunImpl() { | 72 bool GetOobeTimestampFunction::RunImpl() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 91 base::Time::Exploded ctime; | 93 base::Time::Exploded ctime; |
| 92 fileInfo.creation_time.UTCExplode(&ctime); | 94 fileInfo.creation_time.UTCExplode(&ctime); |
| 93 timestamp += base::StringPrintf("%u-%u-%u", | 95 timestamp += base::StringPrintf("%u-%u-%u", |
| 94 ctime.year, | 96 ctime.year, |
| 95 ctime.month, | 97 ctime.month, |
| 96 ctime.day_of_month); | 98 ctime.day_of_month); |
| 97 } | 99 } |
| 98 SetResult(new base::StringValue(timestamp)); | 100 SetResult(new base::StringValue(timestamp)); |
| 99 return true; | 101 return true; |
| 100 } | 102 } |
| 103 |
| 104 CheckAllowRedeemOffersFunction::CheckAllowRedeemOffersFunction() { |
| 105 } |
| 106 |
| 107 CheckAllowRedeemOffersFunction::~CheckAllowRedeemOffersFunction() { |
| 108 } |
| 109 |
| 110 void CheckAllowRedeemOffersFunction::CheckAllowRedeemOffers() { |
| 111 chromeos::CrosSettingsProvider::TrustedStatus status = |
| 112 chromeos::CrosSettings::Get()->PrepareTrustedValues( |
| 113 base::Bind(&CheckAllowRedeemOffersFunction::CheckAllowRedeemOffers, |
| 114 base::Unretained(this))); |
| 115 if (status == chromeos::CrosSettingsProvider::TEMPORARILY_UNTRUSTED) |
| 116 return; |
| 117 |
| 118 bool allow; |
| 119 if (!chromeos::CrosSettings::Get()->GetBoolean( |
| 120 chromeos::kAllowRedeemChromeOsRegistrationOffers, &allow)) { |
| 121 allow = true; |
| 122 } |
| 123 SetResult(new base::FundamentalValue(allow)); |
| 124 SendResponse(true); |
| 125 } |
| 126 |
| 127 // Check the enterprise policy kAllowRedeemChromeOsRegistrationOffers flag |
| 128 // value. This policy is used to control whether user can redeem offers using |
| 129 // enterprise device. |
| 130 bool CheckAllowRedeemOffersFunction::RunImpl() { |
| 131 CheckAllowRedeemOffers(); |
| 132 return true; |
| 133 } |
| OLD | NEW |