summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos')
-rw-r--r--chrome/browser/chromeos/extensions/echo_private_api.cc49
-rw-r--r--chrome/browser/chromeos/extensions/echo_private_api.h22
-rw-r--r--chrome/browser/chromeos/extensions/echo_private_apitest.cc (renamed from chrome/browser/chromeos/extensions/offers_private_apitest.cc)6
-rw-r--r--chrome/browser/chromeos/extensions/offers_private_api.cc206
-rw-r--r--chrome/browser/chromeos/extensions/offers_private_api.h41
-rw-r--r--chrome/browser/chromeos/system/statistics_provider.cc12
6 files changed, 80 insertions, 256 deletions
diff --git a/chrome/browser/chromeos/extensions/echo_private_api.cc b/chrome/browser/chromeos/extensions/echo_private_api.cc
new file mode 100644
index 0000000..a48c704
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/echo_private_api.cc
@@ -0,0 +1,49 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/extensions/echo_private_api.h"
+
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/system/statistics_provider.h"
+#include "chrome/common/extensions/extension.h"
+
+namespace {
+
+// For a given registration code type, returns the code value from the
+// underlying system. Caller owns the returned pointer.
+base::Value* GetValueForRegistrationCodeType(std::string& type) {
+ // Possible ECHO code type and corresponding key name in StatisticsProvider.
+ const std::string kCouponType = "COUPON_CODE";
+ const std::string kCouponCodeKey = "ubind_attribute";
+ const std::string kGroupType = "GROUP_CODE";
+ const std::string kGroupCodeKey = "gbind_attribute";
+
+ chromeos::system::StatisticsProvider* provider =
+ chromeos::system::StatisticsProvider::GetInstance();
+ std::string result;
+ if (type == kCouponType)
+ provider->GetMachineStatistic(kCouponCodeKey, &result);
+ else if (type == kGroupType)
+ provider->GetMachineStatistic(kGroupCodeKey, &result);
+ return Value::CreateStringValue(result);
+}
+
+} // namespace
+
+
+GetRegistrationCodeFunction::GetRegistrationCodeFunction() {
+}
+
+GetRegistrationCodeFunction::~GetRegistrationCodeFunction() {
+}
+
+bool GetRegistrationCodeFunction::RunImpl() {
+ std::string type;
+ EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &type));
+ result_.reset(GetValueForRegistrationCodeType(type));
+ return true;
+}
diff --git a/chrome/browser/chromeos/extensions/echo_private_api.h b/chrome/browser/chromeos/extensions/echo_private_api.h
new file mode 100644
index 0000000..e947eb3
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/echo_private_api.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_
+
+#include "base/compiler_specific.h"
+#include "chrome/browser/extensions/extension_function.h"
+
+class GetRegistrationCodeFunction : public SyncExtensionFunction {
+ public:
+ GetRegistrationCodeFunction();
+
+ protected:
+ virtual ~GetRegistrationCodeFunction();
+ virtual bool RunImpl() OVERRIDE;
+
+ private:
+ DECLARE_EXTENSION_FUNCTION_NAME("echoPrivate.getRegistrationCode");
+};
+#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_ECHO_PRIVATE_API_H_
diff --git a/chrome/browser/chromeos/extensions/offers_private_apitest.cc b/chrome/browser/chromeos/extensions/echo_private_apitest.cc
index 93db498..25886d7 100644
--- a/chrome/browser/chromeos/extensions/offers_private_apitest.cc
+++ b/chrome/browser/chromeos/extensions/echo_private_apitest.cc
@@ -4,10 +4,10 @@
#include "chrome/browser/extensions/extension_apitest.h"
-class ExtensionOffersPrivateApiTest : public ExtensionApiTest {
+class ExtensionEchoPrivateApiTest : public ExtensionApiTest {
};
-IN_PROC_BROWSER_TEST_F(ExtensionOffersPrivateApiTest, OffersTest) {
- EXPECT_TRUE(RunComponentExtensionTest("offers/component_extension"))
+IN_PROC_BROWSER_TEST_F(ExtensionEchoPrivateApiTest, EchoTest) {
+ EXPECT_TRUE(RunComponentExtensionTest("echo/component_extension"))
<< message_;
}
diff --git a/chrome/browser/chromeos/extensions/offers_private_api.cc b/chrome/browser/chromeos/extensions/offers_private_api.cc
deleted file mode 100644
index 6b9a54c..0000000
--- a/chrome/browser/chromeos/extensions/offers_private_api.cc
+++ /dev/null
@@ -1,206 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/chromeos/extensions/offers_private_api.h"
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/values.h"
-#include "chrome/browser/chromeos/system/statistics_provider.h"
-#include "chrome/browser/extensions/extension_host.h"
-#include "chrome/browser/extensions/extension_process_manager.h"
-#include "chrome/browser/extensions/extension_tab_util.h"
-#include "chrome/browser/extensions/extension_window_controller.h"
-#include "chrome/browser/infobars/infobar_tab_helper.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_list.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
-#include "chrome/common/chrome_notification_types.h"
-#include "chrome/common/extensions/extension.h"
-#include "content/public/browser/notification_details.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_source.h"
-#include "content/public/browser/web_contents.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-
-namespace {
-
-// For a given coupon type, returns the coupon code value from the underlying
-// system.
-std::string GetValueForCouponType(std::string& type) {
- // Possible ECHO code type and corresponding key name in StatisticsProvider.
- const std::string kCouponType = "COUPON_CODE";
- const std::string kCouponCodeKey = "ubind_attribute";
- const std::string kGroupType = "GROUP_CODE";
- const std::string kGroupCodeKey = "gbind_attribute";
-
- chromeos::system::StatisticsProvider* provider =
- chromeos::system::StatisticsProvider::GetInstance();
- std::string result;
- if (type == kCouponType)
- provider->GetMachineStatistic(kCouponCodeKey, &result);
- else if (type == kGroupType)
- provider->GetMachineStatistic(kGroupCodeKey, &result);
- return result;
-}
-
-} // namespace
-
-
-GetCouponCodeFunction::GetCouponCodeFunction() {
-}
-
-GetCouponCodeFunction::~GetCouponCodeFunction() {
-}
-
-bool GetCouponCodeFunction::RunImpl() {
- std::string type;
- EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &type));
- result_.reset(Value::CreateStringValue(GetValueForCouponType(type)));
- return true;
-}
-
-// Confirmation InfoBar displayed to ask user for consent for performing
-// the ECHO protocol transaction. Used by GetUserConsentFunction.
-class OffersConsentInfoBarDelegate
- : public ConfirmInfoBarDelegate,
- public content::NotificationObserver {
- public:
- OffersConsentInfoBarDelegate(Browser* browser,
- InfoBarTabHelper* infobar_helper,
- const GURL& url,
- GetUserConsentFunction* consent_receiver);
- private:
- virtual ~OffersConsentInfoBarDelegate();
-
- // ConfirmInfoBarDelegate:
- virtual string16 GetMessageText() const OVERRIDE;
- virtual int GetButtons() const OVERRIDE;
- virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
- virtual bool Accept() OVERRIDE;
- virtual bool Cancel() OVERRIDE;
- virtual void InfoBarDismissed() OVERRIDE;
-
- // content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
-
- content::NotificationRegistrar registrar_;
- Browser* browser_;
-
- // The extension host we are showing the InfoBar for. The delegate needs to
- // own this since the InfoBar gets deleted and recreated when you switch tabs
- // and come back (and we don't want the user's interaction with the InfoBar to
- // get lost at that point).
- scoped_ptr<ExtensionHost> extension_host_;
-
- scoped_refptr<GetUserConsentFunction> consent_receiver_;
-};
-
-OffersConsentInfoBarDelegate::OffersConsentInfoBarDelegate(
- Browser* browser,
- InfoBarTabHelper* infobar_helper,
- const GURL& url,
- GetUserConsentFunction* consent_receiver)
- : ConfirmInfoBarDelegate(infobar_helper),
- browser_(browser),
- consent_receiver_(consent_receiver) {
- ExtensionProcessManager* manager =
- browser->profile()->GetExtensionProcessManager();
- extension_host_.reset(manager->CreateInfobarHost(url, browser));
- extension_host_->SetAssociatedWebContents(infobar_helper->web_contents());
-
- registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
- content::Source<Profile>(browser->profile()));
- registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
- content::Source<Profile>(browser->profile()));
-}
-
-OffersConsentInfoBarDelegate::~OffersConsentInfoBarDelegate() {
-}
-
-string16 OffersConsentInfoBarDelegate::GetMessageText() const {
- return l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_LABEL);
-}
-
-int OffersConsentInfoBarDelegate::GetButtons() const {
- return BUTTON_OK | BUTTON_CANCEL;
-}
-
-string16 OffersConsentInfoBarDelegate::GetButtonLabel(
- InfoBarButton button) const {
- DCHECK(button == BUTTON_OK || button == BUTTON_CANCEL);
- if (button == BUTTON_OK)
- return l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_ENABLE_BUTTON);
- return l10n_util::GetStringUTF16(IDS_OFFERS_CONSENT_INFOBAR_DISABLE_BUTTON);
-}
-
-bool OffersConsentInfoBarDelegate::Accept() {
- consent_receiver_->SetConsent(true);
- return true;
-}
-
-bool OffersConsentInfoBarDelegate::Cancel() {
- consent_receiver_->SetConsent(false);
- return true;
-}
-
-void OffersConsentInfoBarDelegate::InfoBarDismissed() {
- // Assume no consent if the user closes the Info Bar without
- // pressing any of the buttons.
- consent_receiver_->SetConsent(false);
-}
-
-void OffersConsentInfoBarDelegate::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE ||
- type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
- if (extension_host_.get() == content::Details<ExtensionHost>(details).ptr())
- RemoveSelf();
- }
-}
-
-GetUserConsentFunction::GetUserConsentFunction() {
-}
-
-void GetUserConsentFunction::SetConsent(bool is_consent) {
- result_.reset(Value::CreateBooleanValue(is_consent));
- SendResponse(true);
- Release();
-}
-
-GetUserConsentFunction::~GetUserConsentFunction() {
-}
-
-bool GetUserConsentFunction::RunImpl() {
- AddRef(); // Balanced in SetConsent().
- ShowConsentInfoBar();
- return true;
-}
-
-void GetUserConsentFunction::ShowConsentInfoBar() {
- const Extension* extension = GetExtension();
- GURL url = extension->GetResourceURL("");
-
- Browser* browser = GetCurrentBrowser();
-
- TabContentsWrapper* tab_contents = NULL;
- tab_contents = browser->GetSelectedTabContentsWrapper();
- tab_contents->infobar_tab_helper()->AddInfoBar(
- new OffersConsentInfoBarDelegate(browser,
- tab_contents->infobar_tab_helper(),
- url,
- this));
- DCHECK(browser->extension_window_controller());
-}
diff --git a/chrome/browser/chromeos/extensions/offers_private_api.h b/chrome/browser/chromeos/extensions/offers_private_api.h
deleted file mode 100644
index df7a56a..0000000
--- a/chrome/browser/chromeos/extensions/offers_private_api.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_OFFERS_PRIVATE_API_H_
-#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_OFFERS_PRIVATE_API_H_
-
-#include "base/compiler_specific.h"
-#include "chrome/browser/extensions/extension_function.h"
-
-class GetCouponCodeFunction : public SyncExtensionFunction {
- public:
- GetCouponCodeFunction();
-
- protected:
- virtual ~GetCouponCodeFunction();
- virtual bool RunImpl() OVERRIDE;
-
- private:
- DECLARE_EXTENSION_FUNCTION_NAME("offersPrivate.getCouponCode");
-};
-
-class GetUserConsentFunction : public AsyncExtensionFunction {
- public:
- GetUserConsentFunction();
-
- // Called when user's consent response is known.
- void SetConsent(bool is_consent);
-
- protected:
- virtual ~GetUserConsentFunction();
- virtual bool RunImpl() OVERRIDE;
-
- private:
- // Show user consent confirmation bar.
- void ShowConsentInfoBar();
-
- DECLARE_EXTENSION_FUNCTION_NAME("offersPrivate.getUserConsent");
-};
-
-#endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_OFFERS_PRIVATE_API_H_
diff --git a/chrome/browser/chromeos/system/statistics_provider.cc b/chrome/browser/chromeos/system/statistics_provider.cc
index b973175..0d6798f 100644
--- a/chrome/browser/chromeos/system/statistics_provider.cc
+++ b/chrome/browser/chromeos/system/statistics_provider.cc
@@ -45,9 +45,9 @@ const char kMachineHardwareInfoDelim[] = " \n";
// File to get ECHO coupon info from, and key/value delimiters of
// the file.
-const char kOffersCouponFile[] = "/var/cache/offers/vpd_echo.txt";
-const char kOffersCouponEq[] = "=";
-const char kOffersCouponDelim[] = "\n";
+const char kEchoCouponFile[] = "/var/cache/echo/vpd_echo.txt";
+const char kEchoCouponEq[] = "=";
+const char kEchoCouponDelim[] = "\n";
// File to get machine OS info from, and key/value delimiters of the file.
const char kMachineOSInfoFile[] = "/etc/lsb-release";
@@ -154,9 +154,9 @@ void StatisticsProviderImpl::LoadMachineStatistics() {
parser.GetNameValuePairsFromFile(FilePath(kMachineHardwareInfoFile),
kMachineHardwareInfoEq,
kMachineHardwareInfoDelim);
- parser.GetNameValuePairsFromFile(FilePath(kOffersCouponFile),
- kOffersCouponEq,
- kOffersCouponDelim);
+ parser.GetNameValuePairsFromFile(FilePath(kEchoCouponFile),
+ kEchoCouponEq,
+ kEchoCouponDelim);
parser.GetNameValuePairsFromFile(FilePath(kMachineOSInfoFile),
kMachineOSInfoEq,
kMachineOSInfoDelim);