| 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/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/prefs/pref_registry_simple.h" | 12 #include "base/prefs/pref_registry_simple.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | |
| 21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 22 #include "chrome/browser/chromeos/ui/echo_dialog_view.h" | 21 #include "chrome/browser/chromeos/ui/echo_dialog_view.h" |
| 23 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/common/extensions/api/echo_private.h" | 24 #include "chrome/common/extensions/api/echo_private.h" |
| 26 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 27 #include "chromeos/system/statistics_provider.h" | 26 #include "chromeos/system/statistics_provider.h" |
| 28 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 29 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 30 | 29 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 54 } // namespace chromeos | 53 } // namespace chromeos |
| 55 | 54 |
| 56 EchoPrivateGetRegistrationCodeFunction:: | 55 EchoPrivateGetRegistrationCodeFunction:: |
| 57 EchoPrivateGetRegistrationCodeFunction() {} | 56 EchoPrivateGetRegistrationCodeFunction() {} |
| 58 | 57 |
| 59 EchoPrivateGetRegistrationCodeFunction:: | 58 EchoPrivateGetRegistrationCodeFunction:: |
| 60 ~EchoPrivateGetRegistrationCodeFunction() {} | 59 ~EchoPrivateGetRegistrationCodeFunction() {} |
| 61 | 60 |
| 62 void EchoPrivateGetRegistrationCodeFunction::GetRegistrationCode( | 61 void EchoPrivateGetRegistrationCodeFunction::GetRegistrationCode( |
| 63 const std::string& type) { | 62 const std::string& type) { |
| 64 if (!chromeos::KioskModeSettings::Get()->is_initialized()) { | |
| 65 chromeos::KioskModeSettings::Get()->Initialize(base::Bind( | |
| 66 &EchoPrivateGetRegistrationCodeFunction::GetRegistrationCode, | |
| 67 this, type)); | |
| 68 return; | |
| 69 } | |
| 70 // Possible ECHO code type and corresponding key name in StatisticsProvider. | 63 // Possible ECHO code type and corresponding key name in StatisticsProvider. |
| 71 const std::string kCouponType = "COUPON_CODE"; | 64 const std::string kCouponType = "COUPON_CODE"; |
| 72 const std::string kGroupType = "GROUP_CODE"; | 65 const std::string kGroupType = "GROUP_CODE"; |
| 73 | 66 |
| 74 chromeos::system::StatisticsProvider* provider = | 67 chromeos::system::StatisticsProvider* provider = |
| 75 chromeos::system::StatisticsProvider::GetInstance(); | 68 chromeos::system::StatisticsProvider::GetInstance(); |
| 76 std::string result; | 69 std::string result; |
| 77 if (!chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) { | 70 if (type == kCouponType) { |
| 78 // In Kiosk mode, we effectively disable the registration API | 71 provider->GetMachineStatistic(chromeos::system::kOffersCouponCodeKey, |
| 79 // by always returning an empty code. | 72 &result); |
| 80 if (type == kCouponType) { | 73 } else if (type == kGroupType) { |
| 81 provider->GetMachineStatistic(chromeos::system::kOffersCouponCodeKey, | 74 provider->GetMachineStatistic(chromeos::system::kOffersGroupCodeKey, |
| 82 &result); | 75 &result); |
| 83 } else if (type == kGroupType) { | |
| 84 provider->GetMachineStatistic(chromeos::system::kOffersGroupCodeKey, | |
| 85 &result); | |
| 86 } | |
| 87 } | 76 } |
| 88 | 77 |
| 89 results_ = echo_api::GetRegistrationCode::Results::Create(result); | 78 results_ = echo_api::GetRegistrationCode::Results::Create(result); |
| 90 SendResponse(true); | 79 SendResponse(true); |
| 91 } | 80 } |
| 92 | 81 |
| 93 bool EchoPrivateGetRegistrationCodeFunction::RunSync() { | 82 bool EchoPrivateGetRegistrationCodeFunction::RunSync() { |
| 94 scoped_ptr<echo_api::GetRegistrationCode::Params> params = | 83 scoped_ptr<echo_api::GetRegistrationCode::Params> params = |
| 95 echo_api::GetRegistrationCode::Params::Create(*args_); | 84 echo_api::GetRegistrationCode::Params::Create(*args_); |
| 96 EXTENSION_FUNCTION_VALIDATE(params); | 85 EXTENSION_FUNCTION_VALIDATE(params); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 void EchoPrivateGetUserConsentFunction::Finalize(bool consent) { | 263 void EchoPrivateGetUserConsentFunction::Finalize(bool consent) { |
| 275 // Consent should not be true if offers redeeming is disabled. | 264 // Consent should not be true if offers redeeming is disabled. |
| 276 CHECK(redeem_offers_allowed_ || !consent); | 265 CHECK(redeem_offers_allowed_ || !consent); |
| 277 results_ = echo_api::GetUserConsent::Results::Create(consent); | 266 results_ = echo_api::GetUserConsent::Results::Create(consent); |
| 278 SendResponse(true); | 267 SendResponse(true); |
| 279 | 268 |
| 280 // Release the reference added in |OnRedeemOffersAllowedChecked|, before | 269 // Release the reference added in |OnRedeemOffersAllowedChecked|, before |
| 281 // showing the dialog. | 270 // showing the dialog. |
| 282 Release(); | 271 Release(); |
| 283 } | 272 } |
| OLD | NEW |