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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.h"
9 #include "base/threading/sequenced_worker_pool.h"
10 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
11 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
12 #include "chrome/common/extensions/api/cloud_print_private.h"
13 #include "google_apis/google_api_keys.h"
14 #include "net/base/net_util.h"
16 namespace extensions
{
18 CloudPrintTestsDelegate
* CloudPrintTestsDelegate::instance_
= NULL
;
20 CloudPrintTestsDelegate
* CloudPrintTestsDelegate::instance() {
24 CloudPrintTestsDelegate::CloudPrintTestsDelegate() {
28 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() {
32 CloudPrintPrivateSetupConnectorFunction::
33 CloudPrintPrivateSetupConnectorFunction() {
36 CloudPrintPrivateSetupConnectorFunction::
37 ~CloudPrintPrivateSetupConnectorFunction() {
40 bool CloudPrintPrivateSetupConnectorFunction::RunAsync() {
41 #if defined(ENABLE_PRINT_PREVIEW)
42 using api::cloud_print_private::SetupConnector::Params
;
43 scoped_ptr
<Params
> params(Params::Create(*args_
));
44 if (CloudPrintTestsDelegate::instance()) {
45 CloudPrintTestsDelegate::instance()->SetupConnector(
49 params
->user_settings
);
51 CloudPrintProxyService
* service
=
52 CloudPrintProxyServiceFactory::GetForProfile(GetProfile());
55 scoped_ptr
<base::DictionaryValue
> user_setings(
56 params
->user_settings
.ToValue());
57 service
->EnableForUserWithRobot(params
->credentials
,
69 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() {
72 CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() {
75 bool CloudPrintPrivateGetHostNameFunction::RunAsync() {
76 SetResult(new base::StringValue(
77 CloudPrintTestsDelegate::instance() ?
78 CloudPrintTestsDelegate::instance()->GetHostName() :
84 CloudPrintPrivateGetPrintersFunction::CloudPrintPrivateGetPrintersFunction() {
87 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() {
90 void CloudPrintPrivateGetPrintersFunction::SendResults(
91 const std::vector
<std::string
>& printers
) {
92 results_
= api::cloud_print_private::GetPrinters::Results::Create(printers
);
96 bool CloudPrintPrivateGetPrintersFunction::RunAsync() {
97 #if defined(ENABLE_PRINT_PREVIEW)
98 std::vector
<std::string
> result
;
99 if (CloudPrintTestsDelegate::instance()) {
100 SendResults(CloudPrintTestsDelegate::instance()->GetPrinters());
102 CloudPrintProxyService
* service
=
103 CloudPrintProxyServiceFactory::GetForProfile(GetProfile());
106 service
->GetPrinters(
107 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults
, this));
116 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() {
119 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() {
122 bool CloudPrintPrivateGetClientIdFunction::RunAsync() {
123 SetResult(new base::StringValue(
124 CloudPrintTestsDelegate::instance() ?
125 CloudPrintTestsDelegate::instance()->GetClientId() :
126 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT
)));
131 } // namespace extensions