Chromium Code Reviews| Index: chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc |
| 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 2f590068b522982da0c1e9ebfe0a242cc3bfe831..e2d77d436db3891986b6ac101f92d150c43fd6bc 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 |
| @@ -15,18 +15,24 @@ |
| namespace extensions { |
| -CloudPrintTestsDelegate* CloudPrintTestsDelegate::instance_ = NULL; |
| +namespace { |
| -CloudPrintTestsDelegate* CloudPrintTestsDelegate::instance() { |
| - return instance_; |
| +const char kErrorIncognito[] = "Cannot access in incognito mode"; |
|
Lei Zhang
2016/04/21 01:08:40
Needed to add an error message to make chrome.test
|
| + |
| +CloudPrintTestsDelegate* g_instance = nullptr; |
| + |
| +} // namespace |
| + |
| +CloudPrintTestsDelegate* CloudPrintTestsDelegate::Get() { |
| + return g_instance; |
| } |
| CloudPrintTestsDelegate::CloudPrintTestsDelegate() { |
| - instance_ = this; |
| + g_instance = this; |
| } |
| CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { |
| - instance_ = NULL; |
| + g_instance = nullptr; |
| } |
| CloudPrintPrivateSetupConnectorFunction:: |
| @@ -41,23 +47,21 @@ bool CloudPrintPrivateSetupConnectorFunction::RunAsync() { |
| #if defined(ENABLE_PRINT_PREVIEW) |
| using api::cloud_print_private::SetupConnector::Params; |
| std::unique_ptr<Params> params(Params::Create(*args_)); |
| - if (CloudPrintTestsDelegate::instance()) { |
| - CloudPrintTestsDelegate::instance()->SetupConnector( |
| - params->user_email, |
| - params->robot_email, |
| - params->credentials, |
| + if (CloudPrintTestsDelegate::Get()) { |
| + CloudPrintTestsDelegate::Get()->SetupConnector( |
| + params->user_email, params->robot_email, params->credentials, |
| params->user_settings); |
| } else { |
| + std::unique_ptr<base::DictionaryValue> user_settings( |
| + params->user_settings.ToValue()); |
| CloudPrintProxyService* service = |
| CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); |
| - if (!service) |
| + if (!service) { |
| + error_ = kErrorIncognito; |
| return false; |
| - std::unique_ptr<base::DictionaryValue> user_setings( |
| - params->user_settings.ToValue()); |
| - service->EnableForUserWithRobot(params->credentials, |
| - params->robot_email, |
| - params->user_email, |
| - *user_setings); |
| + } |
| + service->EnableForUserWithRobot(params->credentials, params->robot_email, |
| + params->user_email, *user_settings); |
| } |
| SendResponse(true); |
| return true; |
| @@ -73,10 +77,10 @@ CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() { |
| } |
| bool CloudPrintPrivateGetHostNameFunction::RunAsync() { |
| - SetResult(new base::StringValue( |
| - CloudPrintTestsDelegate::instance() ? |
| - CloudPrintTestsDelegate::instance()->GetHostName() : |
| - net::GetHostName())); |
| + SetResult( |
| + new base::StringValue(CloudPrintTestsDelegate::Get() |
| + ? CloudPrintTestsDelegate::Get()->GetHostName() |
| + : net::GetHostName())); |
| SendResponse(true); |
| return true; |
| } |
| @@ -95,14 +99,15 @@ void CloudPrintPrivateGetPrintersFunction::SendResults( |
| bool CloudPrintPrivateGetPrintersFunction::RunAsync() { |
| #if defined(ENABLE_PRINT_PREVIEW) |
| - std::vector<std::string> result; |
| - if (CloudPrintTestsDelegate::instance()) { |
| - SendResults(CloudPrintTestsDelegate::instance()->GetPrinters()); |
| + if (CloudPrintTestsDelegate::Get()) { |
| + SendResults(CloudPrintTestsDelegate::Get()->GetPrinters()); |
| } else { |
| CloudPrintProxyService* service = |
| CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); |
| - if (!service) |
| + if (!service) { |
| + error_ = kErrorIncognito; |
| return false; |
| + } |
| service->GetPrinters( |
| base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this)); |
| } |
| @@ -121,9 +126,9 @@ CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() { |
| bool CloudPrintPrivateGetClientIdFunction::RunAsync() { |
| SetResult(new base::StringValue( |
| - CloudPrintTestsDelegate::instance() ? |
| - CloudPrintTestsDelegate::instance()->GetClientId() : |
| - google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); |
| + CloudPrintTestsDelegate::Get() |
| + ? CloudPrintTestsDelegate::Get()->GetClientId() |
| + : google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); |
| SendResponse(true); |
| return true; |
| } |