Chromium Code Reviews| 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/extensions/api/cloud_print_private/cloud_print_private_ api.h" | 5 #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_ api.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 10 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 #if defined(ENABLE_PRINT_PREVIEW) | 41 #if defined(ENABLE_PRINT_PREVIEW) |
| 42 using api::cloud_print_private::SetupConnector::Params; | 42 using api::cloud_print_private::SetupConnector::Params; |
| 43 std::unique_ptr<Params> params(Params::Create(*args_)); | 43 std::unique_ptr<Params> params(Params::Create(*args_)); |
| 44 if (CloudPrintTestsDelegate::instance()) { | 44 if (CloudPrintTestsDelegate::instance()) { |
| 45 CloudPrintTestsDelegate::instance()->SetupConnector( | 45 CloudPrintTestsDelegate::instance()->SetupConnector( |
| 46 params->user_email, | 46 params->user_email, |
| 47 params->robot_email, | 47 params->robot_email, |
| 48 params->credentials, | 48 params->credentials, |
| 49 params->user_settings); | 49 params->user_settings); |
| 50 } else { | 50 } else { |
| 51 std::unique_ptr<base::DictionaryValue> user_settings( | |
| 52 params->user_settings.ToValue()); | |
| 51 CloudPrintProxyService* service = | 53 CloudPrintProxyService* service = |
| 52 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); | 54 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); |
| 53 if (!service) | |
| 54 return false; | |
|
Vitaly Buka (NO REVIEWS)
2016/04/16 01:33:52
I guess this could be NULL for for incognito.
Lei Zhang
2016/04/16 01:53:19
Ok, I will look into this. How is this API used an
Vitaly Buka (NO REVIEWS)
2016/04/16 02:17:56
Test would be nice.
This API used only by https:/
| |
| 55 std::unique_ptr<base::DictionaryValue> user_setings( | |
| 56 params->user_settings.ToValue()); | |
| 57 service->EnableForUserWithRobot(params->credentials, | 55 service->EnableForUserWithRobot(params->credentials, |
| 58 params->robot_email, | 56 params->robot_email, |
| 59 params->user_email, | 57 params->user_email, |
| 60 *user_setings); | 58 *user_settings); |
| 61 } | 59 } |
| 62 SendResponse(true); | 60 SendResponse(true); |
| 63 return true; | 61 return true; |
| 64 #else | 62 #else |
| 65 return false; | 63 return false; |
| 66 #endif | 64 #endif |
| 67 } | 65 } |
| 68 | 66 |
| 69 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() { | 67 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() { |
| 70 } | 68 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 92 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers); | 90 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers); |
| 93 SendResponse(true); | 91 SendResponse(true); |
| 94 } | 92 } |
| 95 | 93 |
| 96 bool CloudPrintPrivateGetPrintersFunction::RunAsync() { | 94 bool CloudPrintPrivateGetPrintersFunction::RunAsync() { |
| 97 #if defined(ENABLE_PRINT_PREVIEW) | 95 #if defined(ENABLE_PRINT_PREVIEW) |
| 98 std::vector<std::string> result; | 96 std::vector<std::string> result; |
| 99 if (CloudPrintTestsDelegate::instance()) { | 97 if (CloudPrintTestsDelegate::instance()) { |
| 100 SendResults(CloudPrintTestsDelegate::instance()->GetPrinters()); | 98 SendResults(CloudPrintTestsDelegate::instance()->GetPrinters()); |
| 101 } else { | 99 } else { |
| 102 CloudPrintProxyService* service = | 100 CloudPrintProxyServiceFactory::GetForProfile(GetProfile())->GetPrinters( |
| 103 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); | |
| 104 if (!service) | |
| 105 return false; | |
| 106 service->GetPrinters( | |
| 107 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this)); | 101 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this)); |
| 108 } | 102 } |
| 109 return true; | 103 return true; |
| 110 #else | 104 #else |
| 111 return false; | 105 return false; |
| 112 #endif | 106 #endif |
| 113 } | 107 } |
| 114 | 108 |
| 115 | 109 |
| 116 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() { | 110 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() { |
| 117 } | 111 } |
| 118 | 112 |
| 119 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() { | 113 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() { |
| 120 } | 114 } |
| 121 | 115 |
| 122 bool CloudPrintPrivateGetClientIdFunction::RunAsync() { | 116 bool CloudPrintPrivateGetClientIdFunction::RunAsync() { |
| 123 SetResult(new base::StringValue( | 117 SetResult(new base::StringValue( |
| 124 CloudPrintTestsDelegate::instance() ? | 118 CloudPrintTestsDelegate::instance() ? |
| 125 CloudPrintTestsDelegate::instance()->GetClientId() : | 119 CloudPrintTestsDelegate::instance()->GetClientId() : |
| 126 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); | 120 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); |
| 127 SendResponse(true); | 121 SendResponse(true); |
| 128 return true; | 122 return true; |
| 129 } | 123 } |
| 130 | 124 |
| 131 } // namespace extensions | 125 } // namespace extensions |
| OLD | NEW |