diff options
author | sanjoy.pal@samsung.com <sanjoy.pal@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 09:26:29 +0000 |
---|---|---|
committer | sanjoy.pal@samsung.com <sanjoy.pal@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-19 09:26:29 +0000 |
commit | bd9f1113310363a7022d02b75d0f4c7c58eae141 (patch) | |
tree | 7e5b87cd70ed6974742756e270f28b69276a3edc /chrome/browser/rlz | |
parent | 9117de760196434e5d52f12bc67c3f315e129fc0 (diff) | |
download | chromium_src-bd9f1113310363a7022d02b75d0f4c7c58eae141.zip chromium_src-bd9f1113310363a7022d02b75d0f4c7c58eae141.tar.gz chromium_src-bd9f1113310363a7022d02b75d0f4c7c58eae141.tar.bz2 |
Remove experimental.rlz extension api completely
BUG=278556
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/23452008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/rlz')
-rw-r--r-- | chrome/browser/rlz/rlz_extension_api.cc | 229 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz_extension_api.h | 81 | ||||
-rw-r--r-- | chrome/browser/rlz/rlz_extension_apitest.cc | 128 |
3 files changed, 0 insertions, 438 deletions
diff --git a/chrome/browser/rlz/rlz_extension_api.cc b/chrome/browser/rlz/rlz_extension_api.cc deleted file mode 100644 index 7447ce7..0000000 --- a/chrome/browser/rlz/rlz_extension_api.cc +++ /dev/null @@ -1,229 +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/rlz/rlz_extension_api.h" - -#include "base/bind.h" -#include "base/memory/scoped_ptr.h" -#include "base/threading/sequenced_worker_pool.h" -#include "base/threading/thread_restrictions.h" -#include "base/values.h" -#include "chrome/browser/browser_process.h" -#include "chrome/common/extensions/extension.h" -#include "rlz/lib/lib_values.h" -#include "rlz/lib/rlz_lib.h" - -namespace { - -bool GetProductFromName(const std::string& product_name, - rlz_lib::Product* product) { - bool success = true; - switch (product_name[0]) { - case 'B': - *product = rlz_lib::FF_TOOLBAR; - break; - case 'C': - *product = rlz_lib::CHROME; - break; - case 'D': - *product = rlz_lib::DESKTOP; - break; - case 'K': - *product = rlz_lib::QSB_WIN; - break; - case 'N': - *product = rlz_lib::PINYIN_IME; - break; - case 'P': - *product = rlz_lib::TOOLBAR_NOTIFIER; - break; - case 'T': - *product = rlz_lib::IE_TOOLBAR; - break; - case 'U': - *product = rlz_lib::PACK; - break; - case 'W': - *product = rlz_lib::WEBAPPS; - break; - default: - success = false; - break; - } - - return success; -} - -bool GetEventFromName(const std::string& event_name, - rlz_lib::Event* event_id) { - *event_id = rlz_lib::INVALID_EVENT; - - if (event_name == "install") { - *event_id = rlz_lib::INSTALL; - } else if (event_name == "set-to-google") { - *event_id = rlz_lib::SET_TO_GOOGLE; - } else if (event_name == "first-search") { - *event_id = rlz_lib::FIRST_SEARCH; - } else if (event_name == "activate") { - *event_id = rlz_lib::ACTIVATE; - } - - return *event_id != rlz_lib::INVALID_EVENT; -} - -} // namespace - -bool RlzRecordProductEventFunction::RunImpl() { - // This can be slow if registry access goes to disk. Should preferably - // perform registry operations on the File thread. - // http://code.google.com/p/chromium/issues/detail?id=62098 - base::ThreadRestrictions::ScopedAllowIO allow_io; - - std::string product_name; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); - rlz_lib::Product product; - EXTENSION_FUNCTION_VALIDATE(GetProductFromName(product_name, &product)); - - std::string ap_name; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &ap_name)); - rlz_lib::AccessPoint access_point; - EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName(ap_name.c_str(), - &access_point)); - - std::string event_name; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &event_name)); - rlz_lib::Event event_id; - EXTENSION_FUNCTION_VALIDATE(GetEventFromName(event_name, &event_id)); - - return rlz_lib::RecordProductEvent(product, access_point, event_id); -} - -bool RlzGetAccessPointRlzFunction::RunImpl() { - // This can be slow if registry access goes to disk. Should preferably - // perform registry operations on the File thread. - // http://code.google.com/p/chromium/issues/detail?id=62098 - base::ThreadRestrictions::ScopedAllowIO allow_io; - - std::string ap_name; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &ap_name)); - rlz_lib::AccessPoint access_point; - EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName(ap_name.c_str(), - &access_point)); - - char rlz[rlz_lib::kMaxRlzLength + 1]; - rlz_lib::GetAccessPointRlz(access_point, rlz, rlz_lib::kMaxRlzLength); - SetResult(Value::CreateStringValue(rlz)); - return true; -} - -RlzSendFinancialPingFunction::RlzSendFinancialPingFunction() - : product_(rlz_lib::CHROME), - exclude_machine_id_(true) { -} - -RlzSendFinancialPingFunction::~RlzSendFinancialPingFunction() { -} - -bool RlzSendFinancialPingFunction::RunImpl() { - std::string product_name; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); - EXTENSION_FUNCTION_VALIDATE(GetProductFromName(product_name, &product_)); - - ListValue* access_points_list; - EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &access_points_list)); - if (access_points_list->GetSize() < 1) { - EXTENSION_FUNCTION_ERROR("Access point array should not be empty."); - } - - // Allocate an access point array to pass to ClearProductState(). The array - // must be terminated with the value rlz_lib::NO_ACCESS_POINT, hence + 1 - // when allocating the array. - access_points_.reset( - new rlz_lib::AccessPoint[access_points_list->GetSize() + 1]); - - size_t i; - for (i = 0; i < access_points_list->GetSize(); ++i) { - std::string ap_name; - EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name)); - EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName( - ap_name.c_str(), &access_points_[i])); - } - access_points_[i] = rlz_lib::NO_ACCESS_POINT; - - EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &signature_)); - EXTENSION_FUNCTION_VALIDATE(args_->GetString(3, &brand_)); - EXTENSION_FUNCTION_VALIDATE(args_->GetString(4, &id_)); - EXTENSION_FUNCTION_VALIDATE(args_->GetString(5, &lang_)); - EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(6, &exclude_machine_id_)); - - // |system_request_context| needs to run on the UI thread. - rlz_lib::SetURLRequestContext(g_browser_process->system_request_context()); - - content::BrowserThread::GetBlockingPool()->PostTask( - FROM_HERE, - base::Bind(&RlzSendFinancialPingFunction::WorkOnWorkerThread, this)); - - return true; -} - -void RlzSendFinancialPingFunction::WorkOnWorkerThread() { - // rlz_lib::SendFinancialPing() will not send a ping more often than once in - // any 24-hour period. Calling it more often has no effect. If a ping is - // not sent false is returned, but this is not an error, so we should not - // use the return value of rlz_lib::SendFinancialPing() as the return value - // of this function. Callers interested in the return value can register - // an optional callback function. - bool sent = rlz_lib::SendFinancialPing(product_, access_points_.get(), - signature_.c_str(), brand_.c_str(), - id_.c_str(), lang_.c_str(), - exclude_machine_id_); - - SetResult(Value::CreateBooleanValue(sent)); - - bool post_task_result = content::BrowserThread::PostTask( - content::BrowserThread::UI, FROM_HERE, - base::Bind(&RlzSendFinancialPingFunction::RespondOnUIThread, this)); - DCHECK(post_task_result); -} - -void RlzSendFinancialPingFunction::RespondOnUIThread() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); - SendResponse(true); -} - -bool RlzClearProductStateFunction::RunImpl() { - // This can be slow if registry access goes to disk. Should preferably - // perform registry operations on the File thread. - // http://code.google.com/p/chromium/issues/detail?id=62098 - base::ThreadRestrictions::ScopedAllowIO allow_io; - - std::string product_name; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &product_name)); - rlz_lib::Product product; - EXTENSION_FUNCTION_VALIDATE(GetProductFromName(product_name, &product)); - - ListValue* access_points_list; - EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &access_points_list)); - if (access_points_list->GetSize() < 1) { - EXTENSION_FUNCTION_ERROR("Access point array should not be empty."); - } - - // Allocate an access point array to pass to ClearProductState(). The array - // must be termindated with the value rlz_lib::NO_ACCESS_POINT, hence + 1 - // when allocating the array. - scoped_ptr<rlz_lib::AccessPoint[]> access_points( - new rlz_lib::AccessPoint[access_points_list->GetSize() + 1]); - - size_t i; - for (i = 0; i < access_points_list->GetSize(); ++i) { - std::string ap_name; - EXTENSION_FUNCTION_VALIDATE(access_points_list->GetString(i, &ap_name)); - EXTENSION_FUNCTION_VALIDATE(rlz_lib::GetAccessPointFromName( - ap_name.c_str(), &access_points[i])); - } - access_points[i] = rlz_lib::NO_ACCESS_POINT; - - rlz_lib::ClearProductState(product, access_points.get()); - return true; -} diff --git a/chrome/browser/rlz/rlz_extension_api.h b/chrome/browser/rlz/rlz_extension_api.h deleted file mode 100644 index a077e59..0000000 --- a/chrome/browser/rlz/rlz_extension_api.h +++ /dev/null @@ -1,81 +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_RLZ_RLZ_EXTENSION_API_H_ -#define CHROME_BROWSER_RLZ_RLZ_EXTENSION_API_H_ - -#include "build/build_config.h" - -#if defined(ENABLE_RLZ) - -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/extensions/extension_function.h" -#include "rlz/lib/lib_values.h" - -class RlzRecordProductEventFunction : public SyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("experimental.rlz.recordProductEvent", - EXPERIMENTAL_RLZ_RECORDPRODUCTEVENT) - - protected: - virtual ~RlzRecordProductEventFunction() {} - - // ExtensionFunction: - virtual bool RunImpl() OVERRIDE; -}; - -class RlzGetAccessPointRlzFunction : public SyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("experimental.rlz.getAccessPointRlz", - EXPERIMENTAL_RLZ_GETACCESSPOINTRLZ) - - protected: - virtual ~RlzGetAccessPointRlzFunction() {} - - // ExtensionFunction: - virtual bool RunImpl() OVERRIDE; -}; - -class RlzSendFinancialPingFunction : public AsyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("experimental.rlz.sendFinancialPing", - EXPERIMENTAL_RLZ_SENDFINANCIALPING) - - RlzSendFinancialPingFunction(); - - protected: - friend class MockRlzSendFinancialPingFunction; - virtual ~RlzSendFinancialPingFunction(); - - // ExtensionFunction: - virtual bool RunImpl() OVERRIDE; - - private: - void WorkOnWorkerThread(); - void RespondOnUIThread(); - - rlz_lib::Product product_; - scoped_ptr<rlz_lib::AccessPoint[]> access_points_; - std::string signature_; - std::string brand_; - std::string id_; - std::string lang_; - bool exclude_machine_id_; -}; - -class RlzClearProductStateFunction : public SyncExtensionFunction { - public: - DECLARE_EXTENSION_FUNCTION("experimental.rlz.clearProductState", - EXPERIMENTAL_RLZ_CLEARPRODUCTSTATE) - - protected: - virtual ~RlzClearProductStateFunction() {} - - // ExtensionFunction: - virtual bool RunImpl() OVERRIDE; -}; - -#endif // defined(ENABLE_RLZ) - -#endif // CHROME_BROWSER_RLZ_RLZ_EXTENSION_API_H_ diff --git a/chrome/browser/rlz/rlz_extension_apitest.cc b/chrome/browser/rlz/rlz_extension_apitest.cc deleted file mode 100644 index 3cf21c2..0000000 --- a/chrome/browser/rlz/rlz_extension_apitest.cc +++ /dev/null @@ -1,128 +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 <map> - -#include "chrome/browser/browser_process.h" -#include "chrome/browser/extensions/extension_apitest.h" -#include "chrome/browser/extensions/extension_function.h" -#include "chrome/browser/extensions/extension_function_dispatcher.h" -#include "chrome/browser/rlz/rlz_extension_api.h" -#include "chrome/common/extensions/extension.h" -#include "extensions/common/switches.h" -#include "net/dns/mock_host_resolver.h" -#include "rlz/lib/rlz_lib.h" - -#if (OS_WIN) -#include "base/win/registry.h" -#endif - -class MockRlzSendFinancialPingFunction : public RlzSendFinancialPingFunction { - public: - static int expected_count() { - return expected_count_; - } - - protected: - virtual ~MockRlzSendFinancialPingFunction() {} - - // ExtensionFunction - virtual bool RunImpl() OVERRIDE; - - private: - static int expected_count_; -}; - -int MockRlzSendFinancialPingFunction::expected_count_ = 0; - -bool MockRlzSendFinancialPingFunction::RunImpl() { - EXPECT_TRUE(RlzSendFinancialPingFunction::RunImpl()); - ++expected_count_; - return true; -} - -ExtensionFunction* MockRlzSendFinancialPingFunctionFactory() { - return new MockRlzSendFinancialPingFunction(); -} - -// Mac is flaky - http://crbug.com/137834. ChromeOS is not supported yet. -#if defined(OS_MACOSX) || defined(OS_CHROMEOS) -#define MAYBE_Rlz DISABLED_Rlz -#else -#define MAYBE_Rlz Rlz -#endif - -IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_Rlz) { - // The default test resolver doesn't allow lookups to *.google.com. That - // makes sense, but it does make RLZ's SendFinancialPing() fail -- so allow - // connections to google.com in this test. - scoped_refptr<net::RuleBasedHostResolverProc> resolver = - new net::RuleBasedHostResolverProc(host_resolver()); - resolver->AllowDirectLookup("*.google.com"); - net::ScopedDefaultHostResolverProc scoper(resolver); - - CommandLine::ForCurrentProcess()->AppendSwitch( - extensions::switches::kEnableExperimentalExtensionApis); - - // Before running the tests, clear the state of the RLZ products used. - rlz_lib::AccessPoint access_points[] = { - rlz_lib::GD_WEB_SERVER, - rlz_lib::GD_OUTLOOK, - rlz_lib::NO_ACCESS_POINT, - }; - rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); - rlz_lib::ClearProductState(rlz_lib::DESKTOP, access_points); - -#if defined(OS_WIN) - // Check that the state has really been cleared. - base::win::RegKey key(HKEY_CURRENT_USER, - L"Software\\Google\\Common\\Rlz\\Events\\N", - KEY_READ); - ASSERT_FALSE(key.Valid()); - - key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D", - KEY_READ); - ASSERT_FALSE(key.Valid()); -#endif - - // Mock out experimental.rlz.sendFinancialPing(). - ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( - "experimental.rlz.sendFinancialPing", - MockRlzSendFinancialPingFunctionFactory)); - - // Set the access point that the test code is expecting. - ASSERT_TRUE(rlz_lib::SetAccessPointRlz(rlz_lib::GD_DESKBAND, "rlz_apitest")); - - // Now run all the tests. - ASSERT_TRUE(RunExtensionTest("rlz")) << message_; - - ASSERT_EQ(3, MockRlzSendFinancialPingFunction::expected_count()); - ExtensionFunctionDispatcher::ResetFunctions(); - -#if defined(OS_WIN) - // Now make sure we recorded what was expected. If the code in test.js - // changes, need to make appropriate changes here. - key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\N", - KEY_READ); - ASSERT_TRUE(key.Valid()); - - DWORD value; - ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3I", &value)); - ASSERT_EQ(1, value); - ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3S", &value)); - ASSERT_EQ(1, value); - ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D3F", &value)); - ASSERT_EQ(1, value); - - ASSERT_EQ(ERROR_SUCCESS, key.ReadValueDW(L"D4I", &value)); - ASSERT_EQ(1, value); - - key.Open(HKEY_CURRENT_USER, L"Software\\Google\\Common\\Rlz\\Events\\D", - KEY_READ); - ASSERT_FALSE(key.Valid()); -#endif - - // Cleanup. - rlz_lib::ClearProductState(rlz_lib::PINYIN_IME, access_points); -} |