| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } // namespace echo_offer | 53 } // namespace echo_offer |
| 54 | 54 |
| 55 } // namespace chromeos | 55 } // namespace chromeos |
| 56 | 56 |
| 57 EchoPrivateGetRegistrationCodeFunction:: | 57 EchoPrivateGetRegistrationCodeFunction:: |
| 58 EchoPrivateGetRegistrationCodeFunction() {} | 58 EchoPrivateGetRegistrationCodeFunction() {} |
| 59 | 59 |
| 60 EchoPrivateGetRegistrationCodeFunction:: | 60 EchoPrivateGetRegistrationCodeFunction:: |
| 61 ~EchoPrivateGetRegistrationCodeFunction() {} | 61 ~EchoPrivateGetRegistrationCodeFunction() {} |
| 62 | 62 |
| 63 void EchoPrivateGetRegistrationCodeFunction::GetRegistrationCode( | 63 ExtensionFunction::ResponseValue |
| 64 EchoPrivateGetRegistrationCodeFunction::GetRegistrationCode( |
| 64 const std::string& type) { | 65 const std::string& type) { |
| 65 // Possible ECHO code type and corresponding key name in StatisticsProvider. | 66 // Possible ECHO code type and corresponding key name in StatisticsProvider. |
| 66 const std::string kCouponType = "COUPON_CODE"; | 67 const std::string kCouponType = "COUPON_CODE"; |
| 67 const std::string kGroupType = "GROUP_CODE"; | 68 const std::string kGroupType = "GROUP_CODE"; |
| 68 | 69 |
| 69 chromeos::system::StatisticsProvider* provider = | 70 chromeos::system::StatisticsProvider* provider = |
| 70 chromeos::system::StatisticsProvider::GetInstance(); | 71 chromeos::system::StatisticsProvider::GetInstance(); |
| 71 std::string result; | 72 std::string result; |
| 72 if (type == kCouponType) { | 73 if (type == kCouponType) { |
| 73 provider->GetMachineStatistic(chromeos::system::kOffersCouponCodeKey, | 74 provider->GetMachineStatistic(chromeos::system::kOffersCouponCodeKey, |
| 74 &result); | 75 &result); |
| 75 } else if (type == kGroupType) { | 76 } else if (type == kGroupType) { |
| 76 provider->GetMachineStatistic(chromeos::system::kOffersGroupCodeKey, | 77 provider->GetMachineStatistic(chromeos::system::kOffersGroupCodeKey, |
| 77 &result); | 78 &result); |
| 78 } | 79 } |
| 79 | 80 |
| 80 results_ = echo_api::GetRegistrationCode::Results::Create(result); | 81 return ArgumentList(echo_api::GetRegistrationCode::Results::Create(result)); |
| 81 } | 82 } |
| 82 | 83 |
| 83 bool EchoPrivateGetRegistrationCodeFunction::RunSync() { | 84 ExtensionFunction::ResponseAction |
| 85 EchoPrivateGetRegistrationCodeFunction::Run() { |
| 84 std::unique_ptr<echo_api::GetRegistrationCode::Params> params = | 86 std::unique_ptr<echo_api::GetRegistrationCode::Params> params = |
| 85 echo_api::GetRegistrationCode::Params::Create(*args_); | 87 echo_api::GetRegistrationCode::Params::Create(*args_); |
| 86 EXTENSION_FUNCTION_VALIDATE(params); | 88 EXTENSION_FUNCTION_VALIDATE(params); |
| 87 GetRegistrationCode(params->type); | 89 return RespondNow(GetRegistrationCode(params->type)); |
| 88 return true; | |
| 89 } | 90 } |
| 90 | 91 |
| 91 EchoPrivateSetOfferInfoFunction::EchoPrivateSetOfferInfoFunction() {} | 92 EchoPrivateSetOfferInfoFunction::EchoPrivateSetOfferInfoFunction() {} |
| 92 | 93 |
| 93 EchoPrivateSetOfferInfoFunction::~EchoPrivateSetOfferInfoFunction() {} | 94 EchoPrivateSetOfferInfoFunction::~EchoPrivateSetOfferInfoFunction() {} |
| 94 | 95 |
| 95 bool EchoPrivateSetOfferInfoFunction::RunSync() { | 96 ExtensionFunction::ResponseAction EchoPrivateSetOfferInfoFunction::Run() { |
| 96 std::unique_ptr<echo_api::SetOfferInfo::Params> params = | 97 std::unique_ptr<echo_api::SetOfferInfo::Params> params = |
| 97 echo_api::SetOfferInfo::Params::Create(*args_); | 98 echo_api::SetOfferInfo::Params::Create(*args_); |
| 98 EXTENSION_FUNCTION_VALIDATE(params); | 99 EXTENSION_FUNCTION_VALIDATE(params); |
| 99 | 100 |
| 100 const std::string& service_id = params->id; | 101 const std::string& service_id = params->id; |
| 101 std::unique_ptr<base::DictionaryValue> dict = | 102 std::unique_ptr<base::DictionaryValue> dict = |
| 102 params->offer_info.additional_properties.DeepCopyWithoutEmptyChildren(); | 103 params->offer_info.additional_properties.DeepCopyWithoutEmptyChildren(); |
| 103 | 104 |
| 104 PrefService* local_state = g_browser_process->local_state(); | 105 PrefService* local_state = g_browser_process->local_state(); |
| 105 DictionaryPrefUpdate offer_update(local_state, prefs::kEchoCheckedOffers); | 106 DictionaryPrefUpdate offer_update(local_state, prefs::kEchoCheckedOffers); |
| 106 offer_update->SetWithoutPathExpansion("echo." + service_id, std::move(dict)); | 107 offer_update->SetWithoutPathExpansion("echo." + service_id, std::move(dict)); |
| 107 return true; | 108 return RespondNow(NoArguments()); |
| 108 } | 109 } |
| 109 | 110 |
| 110 EchoPrivateGetOfferInfoFunction::EchoPrivateGetOfferInfoFunction() {} | 111 EchoPrivateGetOfferInfoFunction::EchoPrivateGetOfferInfoFunction() {} |
| 111 | 112 |
| 112 EchoPrivateGetOfferInfoFunction::~EchoPrivateGetOfferInfoFunction() {} | 113 EchoPrivateGetOfferInfoFunction::~EchoPrivateGetOfferInfoFunction() {} |
| 113 | 114 |
| 114 bool EchoPrivateGetOfferInfoFunction::RunSync() { | 115 ExtensionFunction::ResponseAction EchoPrivateGetOfferInfoFunction::Run() { |
| 115 std::unique_ptr<echo_api::GetOfferInfo::Params> params = | 116 std::unique_ptr<echo_api::GetOfferInfo::Params> params = |
| 116 echo_api::GetOfferInfo::Params::Create(*args_); | 117 echo_api::GetOfferInfo::Params::Create(*args_); |
| 117 EXTENSION_FUNCTION_VALIDATE(params); | 118 EXTENSION_FUNCTION_VALIDATE(params); |
| 118 | 119 |
| 119 const std::string& service_id = params->id; | 120 const std::string& service_id = params->id; |
| 120 PrefService* local_state = g_browser_process->local_state(); | 121 PrefService* local_state = g_browser_process->local_state(); |
| 121 const base::DictionaryValue* offer_infos = local_state-> | 122 const base::DictionaryValue* offer_infos = local_state-> |
| 122 GetDictionary(prefs::kEchoCheckedOffers); | 123 GetDictionary(prefs::kEchoCheckedOffers); |
| 123 | 124 |
| 124 const base::DictionaryValue* offer_info = NULL; | 125 const base::DictionaryValue* offer_info = NULL; |
| 125 if (!offer_infos->GetDictionaryWithoutPathExpansion( | 126 if (!offer_infos->GetDictionaryWithoutPathExpansion( |
| 126 "echo." + service_id, &offer_info)) { | 127 "echo." + service_id, &offer_info)) { |
| 127 error_ = "Not found"; | 128 return RespondNow(Error("Not found")); |
| 128 return false; | |
| 129 } | 129 } |
| 130 | 130 |
| 131 echo_api::GetOfferInfo::Results::Result result; | 131 echo_api::GetOfferInfo::Results::Result result; |
| 132 result.additional_properties.MergeDictionary(offer_info); | 132 result.additional_properties.MergeDictionary(offer_info); |
| 133 results_ = echo_api::GetOfferInfo::Results::Create(result); | 133 return RespondNow( |
| 134 return true; | 134 ArgumentList(echo_api::GetOfferInfo::Results::Create(result))); |
| 135 } | 135 } |
| 136 | 136 |
| 137 EchoPrivateGetOobeTimestampFunction::EchoPrivateGetOobeTimestampFunction() { | 137 EchoPrivateGetOobeTimestampFunction::EchoPrivateGetOobeTimestampFunction() { |
| 138 } | 138 } |
| 139 | 139 |
| 140 EchoPrivateGetOobeTimestampFunction::~EchoPrivateGetOobeTimestampFunction() { | 140 EchoPrivateGetOobeTimestampFunction::~EchoPrivateGetOobeTimestampFunction() { |
| 141 } | 141 } |
| 142 | 142 |
| 143 bool EchoPrivateGetOobeTimestampFunction::RunAsync() { | 143 bool EchoPrivateGetOobeTimestampFunction::RunAsync() { |
| 144 BrowserThread::PostTaskAndReplyWithResult( | 144 BrowserThread::PostTaskAndReplyWithResult( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 void EchoPrivateGetUserConsentFunction::Finalize(bool consent) { | 271 void EchoPrivateGetUserConsentFunction::Finalize(bool consent) { |
| 272 // Consent should not be true if offers redeeming is disabled. | 272 // Consent should not be true if offers redeeming is disabled. |
| 273 CHECK(redeem_offers_allowed_ || !consent); | 273 CHECK(redeem_offers_allowed_ || !consent); |
| 274 results_ = echo_api::GetUserConsent::Results::Create(consent); | 274 results_ = echo_api::GetUserConsent::Results::Create(consent); |
| 275 SendResponse(true); | 275 SendResponse(true); |
| 276 | 276 |
| 277 // Release the reference added in |OnRedeemOffersAllowedChecked|, before | 277 // Release the reference added in |OnRedeemOffersAllowedChecked|, before |
| 278 // showing the dialog. | 278 // showing the dialog. |
| 279 Release(); | 279 Release(); |
| 280 } | 280 } |
| OLD | NEW |