diff options
author | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-08 22:55:55 +0000 |
---|---|---|
committer | vitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-08 22:55:55 +0000 |
commit | e0832490090b060c31ba3e93e74f6b8fed573dbd (patch) | |
tree | 85b8774a816cded4f45610bf4549d1b15d3fadef | |
parent | aa90589bdd060bb7df2d950e1d648c1a91cd6b4f (diff) | |
download | chromium_src-e0832490090b060c31ba3e93e74f6b8fed573dbd.zip chromium_src-e0832490090b060c31ba3e93e74f6b8fed573dbd.tar.gz chromium_src-e0832490090b060c31ba3e93e74f6b8fed573dbd.tar.bz2 |
New Cloud Print Private API.
Renamed cloudPrintPrivate.setCredentials -> cloudPrintPrivate.setupConnector
Added cloudPrintPrivate.getHostName
Added cloudPrintPrivate.getPrinters
Extracted test logic from cloud_print_private_api.cc
BUG=137129
Review URL: https://chromiumcodereview.appspot.com/11037005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160734 0039d316-1c4b-4281-b951-d872f2087c98
18 files changed, 328 insertions, 75 deletions
diff --git a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc index e5950de..2bb3a84 100644 --- a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc +++ b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc @@ -5,49 +5,114 @@ #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h" #include <string> -#include "base/values.h" -#include "chrome/browser/extensions/extension_service.h" + +#include "base/threading/sequenced_worker_pool.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h" -#include "chrome/browser/profiles/profile.h" - -namespace { +#include "chrome/common/extensions/api/cloud_print_private.h" +#include "net/base/net_util.h" +#include "printing/backend/print_backend.h" -bool test_mode = false; -} // namespace namespace extensions { -CloudPrintSetCredentialsFunction::CloudPrintSetCredentialsFunction() { +CloudPrintTestsDelegate* CloudPrintTestsDelegate::instance_ = NULL; + +CloudPrintTestsDelegate* CloudPrintTestsDelegate::instance() { + return instance_; +} + +CloudPrintTestsDelegate::CloudPrintTestsDelegate() { + instance_ = this; +} + +CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { + instance_ = NULL; +} + +CloudPrintSetupConnectorFunction::CloudPrintSetupConnectorFunction() { } -CloudPrintSetCredentialsFunction::~CloudPrintSetCredentialsFunction() { +CloudPrintSetupConnectorFunction::~CloudPrintSetupConnectorFunction() { } -bool CloudPrintSetCredentialsFunction::RunImpl() { - std::string user_email; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &user_email)); - std::string robot_email; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &robot_email)); - std::string credentials; - EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &credentials)); - if (test_mode) { - std::string test_response = user_email; - test_response.append(robot_email); - test_response.append(credentials); - SetResult(Value::CreateStringValue(test_response)); + +bool CloudPrintSetupConnectorFunction::RunImpl() { + using extensions::api::cloud_print_private::SetupConnector::Params; + scoped_ptr<Params> params(Params::Create(*args_)); + if (CloudPrintTestsDelegate::instance()) { + CloudPrintTestsDelegate::instance()->SetupConnector( + params->user_email, + params->robot_email, + params->credentials, + params->connect_new_printers, + params->printer_blacklist); } else { CloudPrintProxyServiceFactory::GetForProfile(profile_)-> - EnableForUserWithRobot(credentials, robot_email, user_email); + EnableForUserWithRobot(params->credentials, + params->robot_email, + params->user_email, + params->connect_new_printers, + params->printer_blacklist); } SendResponse(true); return true; } -// static -void CloudPrintSetCredentialsFunction::SetTestMode(bool test_mode_enabled) { - test_mode = test_mode_enabled; +CloudPrintGetHostNameFunction::CloudPrintGetHostNameFunction() { +} + +CloudPrintGetHostNameFunction::~CloudPrintGetHostNameFunction() { +} + +bool CloudPrintGetHostNameFunction::RunImpl() { + SetResult(Value::CreateStringValue( + CloudPrintTestsDelegate::instance() ? + CloudPrintTestsDelegate::instance()->GetHostName() : + net::GetHostName())); + SendResponse(true); + return true; +} + +CloudPrintGetPrintersFunction::CloudPrintGetPrintersFunction() { +} + +CloudPrintGetPrintersFunction::~CloudPrintGetPrintersFunction() { +} + +void CloudPrintGetPrintersFunction::ReturnResult( + const base::ListValue* printers) { + SetResult(printers->DeepCopy()); + SendResponse(true); +} + +void CloudPrintGetPrintersFunction::CollectPrinters() { + scoped_ptr<base::ListValue> result(new base::ListValue()); + if (CloudPrintTestsDelegate::instance()) { + std::vector<std::string> printers = + CloudPrintTestsDelegate::instance()->GetPrinters(); + for (size_t i = 0; i < printers.size(); ++i) + result->Append(Value::CreateStringValue(printers[i])); + } else { + printing::PrinterList printers; + scoped_refptr<printing::PrintBackend> backend( + printing::PrintBackend::CreateInstance(NULL)); + if (backend) + backend->EnumeratePrinters(&printers); + for (size_t i = 0; i < printers.size(); ++i) + result->Append(Value::CreateStringValue(printers[i].printer_name)); + } + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + base::Bind(&CloudPrintGetPrintersFunction::ReturnResult, this, + base::Owned(result.release()))); +} + + +bool CloudPrintGetPrintersFunction::RunImpl() { + content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, + base::Bind(&CloudPrintGetPrintersFunction::CollectPrinters, this)); + return true; } } // namespace extensions diff --git a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h index d5c9739..2a23b9e 100644 --- a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h +++ b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h @@ -6,23 +6,73 @@ #define CHROME_BROWSER_EXTENSIONS_API_CLOUD_PRINT_PRIVATE_CLOUD_PRINT_PRIVATE_API_H_ #include <string> +#include <vector> + #include "chrome/browser/extensions/extension_function.h" namespace extensions { -class CloudPrintSetCredentialsFunction : public AsyncExtensionFunction { +// For use only in tests. +class CloudPrintTestsDelegate { public: - DECLARE_EXTENSION_FUNCTION_NAME("cloudPrintPrivate.setCredentials"); + CloudPrintTestsDelegate(); + virtual ~CloudPrintTestsDelegate(); + + virtual void SetupConnector( + const std::string& user_email, + const std::string& robot_email, + const std::string& credentials, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist) = 0; + + virtual std::string GetHostName() = 0; + + virtual std::vector<std::string> GetPrinters() = 0; + + static CloudPrintTestsDelegate* instance(); + + private: + // Points to single instance of this class during testing. + static CloudPrintTestsDelegate* instance_; +}; - CloudPrintSetCredentialsFunction(); +class CloudPrintSetupConnectorFunction : public AsyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME("cloudPrintPrivate.setupConnector"); - // For use only in tests - sets a flag that can cause this function to not - // actually set the credentials but instead simply reflect the passed in - // arguments appended together as one string back in results_. - static void SetTestMode(bool test_mode_enabled); + CloudPrintSetupConnectorFunction(); protected: - virtual ~CloudPrintSetCredentialsFunction(); + virtual ~CloudPrintSetupConnectorFunction(); + + // ExtensionFunction: + virtual bool RunImpl() OVERRIDE; +}; + +class CloudPrintGetHostNameFunction : public AsyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME("cloudPrintPrivate.getHostName"); + + CloudPrintGetHostNameFunction(); + + protected: + virtual ~CloudPrintGetHostNameFunction(); + + // ExtensionFunction: + virtual bool RunImpl() OVERRIDE; +}; + +class CloudPrintGetPrintersFunction : public AsyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME("cloudPrintPrivate.getPrinters"); + + CloudPrintGetPrintersFunction(); + + protected: + virtual ~CloudPrintGetPrintersFunction(); + + void CollectPrinters(); + void ReturnResult(const base::ListValue* printers); // ExtensionFunction: virtual bool RunImpl() OVERRIDE; diff --git a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_apitest.cc b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_apitest.cc index 9fdc25b..bb59d3e 100644 --- a/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_apitest.cc +++ b/chrome/browser/extensions/api/cloud_print_private/cloud_print_private_apitest.cc @@ -2,14 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/stringprintf.h" #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h" + +#include "base/stringprintf.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/common/chrome_switches.h" #include "chrome/test/base/ui_test_utils.h" #include "net/base/mock_host_resolver.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using ::testing::Eq; +using ::testing::Property; +using ::testing::Return; +using ::testing::_; // A base class for tests below. class ExtensionCloudPrintPrivateApiTest : public ExtensionApiTest { @@ -46,15 +54,46 @@ class ExtensionCloudPrintPrivateApiTest : public ExtensionApiTest { }; #if !defined(OS_CHROMEOS) -IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, - CloudPrintSetCredentialsSuccessHosted) { + +class CloudPrintTestsDelegateMock : public extensions::CloudPrintTestsDelegate { + public: + CloudPrintTestsDelegateMock() {} + + MOCK_METHOD5(SetupConnector, + void(const std::string& user_email, + const std::string& robot_email, + const std::string& credentials, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist)); + MOCK_METHOD0(GetHostName, std::string()); + MOCK_METHOD0(GetPrinters, std::vector<std::string>()); + + private: + DISALLOW_COPY_AND_ASSIGN(CloudPrintTestsDelegateMock); +}; + +IN_PROC_BROWSER_TEST_F(ExtensionCloudPrintPrivateApiTest, CloudPrintHosted) { + CloudPrintTestsDelegateMock cloud_print_mock; + std::vector<std::string> printers; + printers.push_back("printer1"); + printers.push_back("printer2"); + + EXPECT_CALL(cloud_print_mock, + SetupConnector("foo@gmail.com", + "foorobot@googleusercontent.com", + "1/23546efa54", + true, + printers)); + EXPECT_CALL(cloud_print_mock, GetHostName()) + .WillRepeatedly(Return("TestHostName")); + EXPECT_CALL(cloud_print_mock, GetPrinters()) + .WillRepeatedly(Return(printers)); // Run this as a hosted app. Since we have overridden the cloud print service // URL in the command line, this URL should match the web extent for our // cloud print component app and it should work. - extensions::CloudPrintSetCredentialsFunction::SetTestMode(true); GURL page_url = GetTestServerURL( "enable_chrome_connector/cloud_print_success_tests.html"); ASSERT_TRUE(RunPageTest(page_url.spec())); - extensions::CloudPrintSetCredentialsFunction::SetTestMode(false); } + #endif // !defined(OS_CHROMEOS) diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc index 01711a4..d17c531 100644 --- a/chrome/browser/extensions/extension_function_registry.cc +++ b/chrome/browser/extensions/extension_function_registry.cc @@ -455,7 +455,9 @@ void ExtensionFunctionRegistry::ResetFunctions() { RegisterFunction<extensions::SetMinimumFontSizeFunction>(); // CloudPrint settings. - RegisterFunction<extensions::CloudPrintSetCredentialsFunction>(); + RegisterFunction<extensions::CloudPrintSetupConnectorFunction>(); + RegisterFunction<extensions::CloudPrintGetHostNameFunction>(); + RegisterFunction<extensions::CloudPrintGetPrintersFunction>(); // Experimental App API. RegisterFunction<extensions::AppNotifyFunction>(); diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc index a6acf71..49dadfb 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.cc @@ -118,12 +118,14 @@ void CloudPrintProxyService::EnableForUser(const std::string& lsid, void CloudPrintProxyService::EnableForUserWithRobot( const std::string& robot_auth_code, const std::string& robot_email, - const std::string& user_email) { + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist) { if (profile_->GetPrefs()->GetBoolean(prefs::kCloudPrintProxyEnabled)) { InvokeServiceTask( base::Bind(&CloudPrintProxyService::EnableCloudPrintProxyWithRobot, weak_factory_.GetWeakPtr(), robot_auth_code, robot_email, - user_email)); + user_email, connect_new_printers, printer_blacklist)); } } @@ -236,13 +238,15 @@ void CloudPrintProxyService::EnableCloudPrintProxy(const std::string& lsid, void CloudPrintProxyService::EnableCloudPrintProxyWithRobot( const std::string& robot_auth_code, const std::string& robot_email, - const std::string& user_email) { + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist) { ServiceProcessControl* process_control = GetServiceProcessControl(); DCHECK(process_control->IsConnected()); - process_control->Send(new ServiceMsg_EnableCloudPrintProxyWithRobot( - robot_auth_code, - robot_email, - user_email)); + process_control->Send( + new ServiceMsg_EnableCloudPrintProxyWithRobot( + robot_auth_code, robot_email, user_email, connect_new_printers, + printer_blacklist)); // Assume the IPC worked. profile_->GetPrefs()->SetString(prefs::kCloudPrintEmail, user_email); } diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h index 5d1e5dc..e880768 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h +++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_PRINTING_CLOUD_PRINT_CLOUD_PRINT_PROXY_SERVICE_H_ #include <string> +#include <vector> #include "base/basictypes.h" #include "base/callback_forward.h" @@ -39,9 +40,12 @@ class CloudPrintProxyService // Enables/disables cloud printing for the user virtual void EnableForUser(const std::string& lsid, const std::string& email); - virtual void EnableForUserWithRobot(const std::string& robot_auth_code, - const std::string& robot_email, - const std::string& user_email); + virtual void EnableForUserWithRobot( + const std::string& robot_auth_code, + const std::string& robot_email, + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist); virtual void DisableForUser(); // Query the service process for the status of the cloud print proxy and @@ -77,9 +81,12 @@ class CloudPrintProxyService // Methods that send an IPC to the service. void RefreshCloudPrintProxyStatus(); void EnableCloudPrintProxy(const std::string& lsid, const std::string& email); - void EnableCloudPrintProxyWithRobot(const std::string& robot_auth_code, - const std::string& robot_email, - const std::string& user_email); + void EnableCloudPrintProxyWithRobot( + const std::string& robot_auth_code, + const std::string& robot_email, + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist); void DisableCloudPrintProxy(); // Callback that gets the cloud print proxy info. diff --git a/chrome/common/extensions/api/api.gyp b/chrome/common/extensions/api/api.gyp index 59dc797..fed5d84 100644 --- a/chrome/common/extensions/api/api.gyp +++ b/chrome/common/extensions/api/api.gyp @@ -19,6 +19,7 @@ 'chromium_code': 1, 'json_schema_files': [ 'bookmarks.json', + 'cloud_print_private.json', 'content_settings.json', 'context_menus.json', 'cookies.json', diff --git a/chrome/common/extensions/api/cloud_print_private.json b/chrome/common/extensions/api/cloud_print_private.json index b208fc2..cf7714c 100644 --- a/chrome/common/extensions/api/cloud_print_private.json +++ b/chrome/common/extensions/api/cloud_print_private.json @@ -8,8 +8,8 @@ "nodoc": "true", "functions": [ { - "name": "setCredentials", - "description": "Sets the login credentials for Cloud Print.", + "name": "setupConnector", + "description": "Setup Cloud Print Connector.", "type": "function", "parameters": [ { @@ -28,16 +28,52 @@ "description": "The login credentials(OAuth2 Auth code)." }, { + "name": "connectNewPrinters", + "type": "boolean", + "description": "True if new printers should be connected." + }, + { + "name": "printerBlacklist", + "description": "Printers that should not be connected.", + "type": "array", + "items": {"type": "string"} + } + ] + }, + { + "name": "getHostName", + "description": "Returns local hostname.", + "type": "function", + "parameters": [ + { "name": "callback", "type": "function", - "description": "Called when a failure happens. Called upon success only in tests.", - "optional": "true", + "description": "Called to return host name.", "parameters": [ { "name": "result", "type": "string", - "description": "A string result code. The value is non-empty on success only in tests.", - "optional": "true" + "description": "Host name." + } + ] + } + ] + }, + { + "name": "getPrinters", + "description": "Returns local printers.", + "type": "function", + "parameters": [ + { + "name": "callback", + "type": "function", + "description": "Called to return printers.", + "parameters": [ + { + "name": "result", + "type": "array", + "items": {"type": "string"}, + "description": "List of printer names." } ] } diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 6f0d1d6..e335e1a 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -1907,6 +1907,7 @@ const char kFactoryResetRequested[] = "FactoryResetRequested"; // *************** SERVICE PREFS *************** // These are attached to the service process. +const char kCloudPrintRoot[] = "cloud_print"; const char kCloudPrintProxyEnabled[] = "cloud_print.enabled"; // The unique id for this instance of the cloud print proxy. const char kCloudPrintProxyId[] = "cloud_print.proxy_id"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 8966dea..aab4d19 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -626,6 +626,7 @@ extern const char kRemoteAccessHostTalkGadgetPrefix[]; extern const char kRemoteAccessHostRequireCurtain[]; extern const char kPrintPreviewStickySettings[]; +extern const char kCloudPrintRoot[]; extern const char kCloudPrintServiceURL[]; extern const char kCloudPrintSigninURL[]; extern const char kCloudPrintDialogWidth[]; diff --git a/chrome/common/service_messages.h b/chrome/common/service_messages.h index 68f208a..8dd3157 100644 --- a/chrome/common/service_messages.h +++ b/chrome/common/service_messages.h @@ -4,6 +4,7 @@ // Multiply-included message file, no traditional include guard. #include <string> +#include <vector> #include "chrome/common/cloud_print/cloud_print_proxy_info.h" #include "ipc/ipc_channel_handle.h" @@ -27,10 +28,12 @@ IPC_MESSAGE_CONTROL1(ServiceMsg_EnableCloudPrintProxy, // Tell the service process to enable the cloud proxy passing in the OAuth2 // auth code of a robot account. -IPC_MESSAGE_CONTROL3(ServiceMsg_EnableCloudPrintProxyWithRobot, +IPC_MESSAGE_CONTROL5(ServiceMsg_EnableCloudPrintProxyWithRobot, std::string /* robot_auth_code */, - std::string /* robot_email*/, - std::string /* user_email*/) + std::string /* robot_email */, + std::string /* user_email */, + bool /* connect_new_printers */, + std::vector<std::string> /* printer_blacklist */) // Tell the service process to disable the cloud proxy. IPC_MESSAGE_CONTROL0(ServiceMsg_DisableCloudPrintProxy) diff --git a/chrome/service/cloud_print/cloud_print_proxy.cc b/chrome/service/cloud_print/cloud_print_proxy.cc index c934fbe..d1c8cb8 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.cc +++ b/chrome/service/cloud_print/cloud_print_proxy.cc @@ -122,8 +122,29 @@ void CloudPrintProxy::EnableForUser(const std::string& lsid) { void CloudPrintProxy::EnableForUserWithRobot( const std::string& robot_auth_code, const std::string& robot_email, - const std::string& user_email) { + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist) { DCHECK(CalledOnValidThread()); + + ShutdownBackend(); + std::string proxy_id( + service_prefs_->GetString(prefs::kCloudPrintProxyId, "")); + service_prefs_->RemovePref(prefs::kCloudPrintRoot); + if (!proxy_id.empty()) { + // Keep only proxy id; + service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id); + } + service_prefs_->SetBoolean(prefs::kCloudPrintConnectNewPrinters, + connect_new_printers); + if (!printer_blacklist.empty()) { + scoped_ptr<base::ListValue> printers(new base::ListValue()); + printers->AppendStrings(printer_blacklist); + service_prefs_->SetValue(prefs::kCloudPrintConnectNewPrinters, + printers.release()); + } + service_prefs_->WritePrefs(); + if (!CreateBackend()) return; DCHECK(backend_.get()); diff --git a/chrome/service/cloud_print/cloud_print_proxy.h b/chrome/service/cloud_print/cloud_print_proxy.h index e844a9d..67ab4e7 100644 --- a/chrome/service/cloud_print/cloud_print_proxy.h +++ b/chrome/service/cloud_print/cloud_print_proxy.h @@ -7,6 +7,7 @@ #include <list> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" @@ -44,7 +45,9 @@ class CloudPrintProxy : public CloudPrintProxyFrontend, void EnableForUserWithRobot( const std::string& robot_auth_code, const std::string& robot_email, - const std::string& user_email); + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist); void UnregisterPrintersAndDisableForUser(); void DisableForUser(); // Returns the proxy info. diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index f25ce7b..4cca7ec 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -111,11 +111,12 @@ void ServiceIPCServer::OnEnableCloudPrintProxy(const std::string& lsid) { void ServiceIPCServer::OnEnableCloudPrintProxyWithRobot( const std::string& robot_auth_code, const std::string& robot_email, - const std::string& user_email) { + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist) { g_service_process->GetCloudPrintProxy()->EnableForUserWithRobot( - robot_auth_code, - robot_email, - user_email); + robot_auth_code, robot_email, user_email, connect_new_printers, + printer_blacklist); } void ServiceIPCServer::OnGetCloudPrintProxyInfo() { diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h index b2855be..4f7f5f7 100644 --- a/chrome/service/service_ipc_server.h +++ b/chrome/service/service_ipc_server.h @@ -6,6 +6,7 @@ #define CHROME_SERVICE_SERVICE_IPC_SERVER_H_ #include <string> +#include <vector> #include "base/memory/scoped_ptr.h" #include "ipc/ipc_channel_handle.h" @@ -47,7 +48,9 @@ class ServiceIPCServer : public IPC::Listener, public IPC::Sender { void OnEnableCloudPrintProxyWithRobot( const std::string& robot_auth_code, const std::string& robot_email, - const std::string& user_email); + const std::string& user_email, + bool connect_new_printers, + const std::vector<std::string>& printer_blacklist); void OnGetCloudPrintProxyInfo(); void OnDisableCloudPrintProxy(); diff --git a/chrome/service/service_process_prefs.cc b/chrome/service/service_process_prefs.cc index e1aca1a1..7de70a4 100644 --- a/chrome/service/service_process_prefs.cc +++ b/chrome/service/service_process_prefs.cc @@ -76,6 +76,10 @@ const base::ListValue* ServiceProcessPrefs::GetList( return static_cast<const ListValue*>(value); } +void ServiceProcessPrefs::SetValue(const std::string& key, base::Value* value) { + prefs_->SetValue(key, value); +} + void ServiceProcessPrefs::RemovePref(const std::string& key) { prefs_->RemoveValue(key); } diff --git a/chrome/service/service_process_prefs.h b/chrome/service/service_process_prefs.h index d03fda9..ef6d836 100644 --- a/chrome/service/service_process_prefs.h +++ b/chrome/service/service_process_prefs.h @@ -49,6 +49,9 @@ class ServiceProcessPrefs { // Returns a list for |key|. const base::ListValue* GetList(const std::string& key) const; + // Set a |value| for |key|. + void SetValue(const std::string& key, base::Value* value); + // Removes the pref specified by |key|. void RemovePref(const std::string& key); diff --git a/chrome/test/data/extensions/api_test/cloud_print_private/enable_chrome_connector/cloud_print_success_tests.js b/chrome/test/data/extensions/api_test/cloud_print_private/enable_chrome_connector/cloud_print_success_tests.js index 02f69e8..0178832 100644 --- a/chrome/test/data/extensions/api_test/cloud_print_private/enable_chrome_connector/cloud_print_success_tests.js +++ b/chrome/test/data/extensions/api_test/cloud_print_private/enable_chrome_connector/cloud_print_success_tests.js @@ -3,18 +3,27 @@ // found in the LICENSE file. var tests = [ - function successfulSetCreds() { + function successfulSetupConnector() { var userEmail = 'foo@gmail.com'; var robotEmail = 'foorobot@googleusercontent.com'; var credentials = '1/23546efa54'; - chrome.cloudPrintPrivate.setCredentials( - userEmail, robotEmail, credentials, + chrome.cloudPrintPrivate.setupConnector( + userEmail, robotEmail, credentials, true, ['printer1', 'printer2']); + chrome.test.succeed(); + }, + function getHostName() { + chrome.cloudPrintPrivate.getHostName( chrome.test.callbackPass(function(result) { - // In test mode, we expect the API to reflect the arguments back to - // us appended together. chrome.test.assertNoLastError(); - chrome.test.assertEq(result, userEmail + robotEmail + credentials); - })); + chrome.test.assertEq("TestHostName", result); + })); + }, + function getPrinters() { + chrome.cloudPrintPrivate.getPrinters( + chrome.test.callbackPass(function(result) { + chrome.test.assertNoLastError(); + chrome.test.assertEq(result, ['printer1', 'printer2']); + })); } ]; |