| 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 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 CloudPrintTestsDelegate::CloudPrintTestsDelegate() { | 26 CloudPrintTestsDelegate::CloudPrintTestsDelegate() { |
| 27 instance_ = this; | 27 instance_ = this; |
| 28 } | 28 } |
| 29 | 29 |
| 30 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { | 30 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { |
| 31 instance_ = NULL; | 31 instance_ = NULL; |
| 32 } | 32 } |
| 33 | 33 |
| 34 CloudPrintSetupConnectorFunction::CloudPrintSetupConnectorFunction() { | 34 CloudPrintPrivateSetupConnectorFunction:: |
| 35 CloudPrintPrivateSetupConnectorFunction() { |
| 35 } | 36 } |
| 36 | 37 |
| 37 CloudPrintSetupConnectorFunction::~CloudPrintSetupConnectorFunction() { | 38 CloudPrintPrivateSetupConnectorFunction:: |
| 39 ~CloudPrintPrivateSetupConnectorFunction() { |
| 38 } | 40 } |
| 39 | 41 |
| 40 | 42 |
| 41 bool CloudPrintSetupConnectorFunction::RunImpl() { | 43 bool CloudPrintPrivateSetupConnectorFunction::RunImpl() { |
| 42 using extensions::api::cloud_print_private::SetupConnector::Params; | 44 using extensions::api::cloud_print_private::SetupConnector::Params; |
| 43 scoped_ptr<Params> params(Params::Create(*args_)); | 45 scoped_ptr<Params> params(Params::Create(*args_)); |
| 44 if (CloudPrintTestsDelegate::instance()) { | 46 if (CloudPrintTestsDelegate::instance()) { |
| 45 CloudPrintTestsDelegate::instance()->SetupConnector( | 47 CloudPrintTestsDelegate::instance()->SetupConnector( |
| 46 params->user_email, | 48 params->user_email, |
| 47 params->robot_email, | 49 params->robot_email, |
| 48 params->credentials, | 50 params->credentials, |
| 49 params->connect_new_printers, | 51 params->connect_new_printers, |
| 50 params->printer_blacklist); | 52 params->printer_blacklist); |
| 51 } else { | 53 } else { |
| 52 CloudPrintProxyServiceFactory::GetForProfile(profile_)-> | 54 CloudPrintProxyServiceFactory::GetForProfile(profile_)-> |
| 53 EnableForUserWithRobot(params->credentials, | 55 EnableForUserWithRobot(params->credentials, |
| 54 params->robot_email, | 56 params->robot_email, |
| 55 params->user_email, | 57 params->user_email, |
| 56 params->connect_new_printers, | 58 params->connect_new_printers, |
| 57 params->printer_blacklist); | 59 params->printer_blacklist); |
| 58 } | 60 } |
| 59 SendResponse(true); | 61 SendResponse(true); |
| 60 return true; | 62 return true; |
| 61 } | 63 } |
| 62 | 64 |
| 63 CloudPrintGetHostNameFunction::CloudPrintGetHostNameFunction() { | 65 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() { |
| 64 } | 66 } |
| 65 | 67 |
| 66 CloudPrintGetHostNameFunction::~CloudPrintGetHostNameFunction() { | 68 CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() { |
| 67 } | 69 } |
| 68 | 70 |
| 69 bool CloudPrintGetHostNameFunction::RunImpl() { | 71 bool CloudPrintPrivateGetHostNameFunction::RunImpl() { |
| 70 SetResult(Value::CreateStringValue( | 72 SetResult(Value::CreateStringValue( |
| 71 CloudPrintTestsDelegate::instance() ? | 73 CloudPrintTestsDelegate::instance() ? |
| 72 CloudPrintTestsDelegate::instance()->GetHostName() : | 74 CloudPrintTestsDelegate::instance()->GetHostName() : |
| 73 net::GetHostName())); | 75 net::GetHostName())); |
| 74 SendResponse(true); | 76 SendResponse(true); |
| 75 return true; | 77 return true; |
| 76 } | 78 } |
| 77 | 79 |
| 78 CloudPrintGetPrintersFunction::CloudPrintGetPrintersFunction() { | 80 CloudPrintPrivateGetPrintersFunction::CloudPrintPrivateGetPrintersFunction() { |
| 79 } | 81 } |
| 80 | 82 |
| 81 CloudPrintGetPrintersFunction::~CloudPrintGetPrintersFunction() { | 83 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() { |
| 82 } | 84 } |
| 83 | 85 |
| 84 void CloudPrintGetPrintersFunction::ReturnResult( | 86 void CloudPrintPrivateGetPrintersFunction::ReturnResult( |
| 85 const base::ListValue* printers) { | 87 const base::ListValue* printers) { |
| 86 SetResult(printers->DeepCopy()); | 88 SetResult(printers->DeepCopy()); |
| 87 SendResponse(true); | 89 SendResponse(true); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void CloudPrintGetPrintersFunction::CollectPrinters() { | 92 void CloudPrintPrivateGetPrintersFunction::CollectPrinters() { |
| 91 scoped_ptr<base::ListValue> result(new base::ListValue()); | 93 scoped_ptr<base::ListValue> result(new base::ListValue()); |
| 92 if (CloudPrintTestsDelegate::instance()) { | 94 if (CloudPrintTestsDelegate::instance()) { |
| 93 std::vector<std::string> printers = | 95 std::vector<std::string> printers = |
| 94 CloudPrintTestsDelegate::instance()->GetPrinters(); | 96 CloudPrintTestsDelegate::instance()->GetPrinters(); |
| 95 for (size_t i = 0; i < printers.size(); ++i) | 97 for (size_t i = 0; i < printers.size(); ++i) |
| 96 result->Append(Value::CreateStringValue(printers[i])); | 98 result->Append(Value::CreateStringValue(printers[i])); |
| 97 } else { | 99 } else { |
| 98 printing::PrinterList printers; | 100 printing::PrinterList printers; |
| 99 scoped_refptr<printing::PrintBackend> backend( | 101 scoped_refptr<printing::PrintBackend> backend( |
| 100 printing::PrintBackend::CreateInstance(NULL)); | 102 printing::PrintBackend::CreateInstance(NULL)); |
| 101 if (backend) | 103 if (backend) |
| 102 backend->EnumeratePrinters(&printers); | 104 backend->EnumeratePrinters(&printers); |
| 103 for (size_t i = 0; i < printers.size(); ++i) | 105 for (size_t i = 0; i < printers.size(); ++i) |
| 104 result->Append(Value::CreateStringValue(printers[i].printer_name)); | 106 result->Append(Value::CreateStringValue(printers[i].printer_name)); |
| 105 } | 107 } |
| 106 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 108 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 107 base::Bind(&CloudPrintGetPrintersFunction::ReturnResult, this, | 109 base::Bind(&CloudPrintPrivateGetPrintersFunction::ReturnResult, this, |
| 108 base::Owned(result.release()))); | 110 base::Owned(result.release()))); |
| 109 } | 111 } |
| 110 | 112 |
| 111 | 113 |
| 112 bool CloudPrintGetPrintersFunction::RunImpl() { | 114 bool CloudPrintPrivateGetPrintersFunction::RunImpl() { |
| 113 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, | 115 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE, |
| 114 base::Bind(&CloudPrintGetPrintersFunction::CollectPrinters, this)); | 116 base::Bind(&CloudPrintPrivateGetPrintersFunction::CollectPrinters, this)); |
| 115 return true; | 117 return true; |
| 116 } | 118 } |
| 117 | 119 |
| 118 } // namespace extensions | 120 } // namespace extensions |
| OLD | NEW |