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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
11 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" | 11 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" |
12 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" | 12 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.
h" |
13 #include "chrome/common/extensions/api/cloud_print_private.h" | 13 #include "chrome/common/extensions/api/cloud_print_private.h" |
14 #include "google_apis/google_api_keys.h" | 14 #include "google_apis/google_api_keys.h" |
15 #include "net/base/network_interfaces.h" | 15 #include "net/base/network_interfaces.h" |
| 16 #include "printing/features/features.h" |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 #if defined(ENABLE_PRINT_PREVIEW) | 22 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
22 const char kErrorIncognito[] = "Cannot access in incognito mode"; | 23 const char kErrorIncognito[] = "Cannot access in incognito mode"; |
23 #endif | 24 #endif |
24 | 25 |
25 CloudPrintTestsDelegate* g_instance = nullptr; | 26 CloudPrintTestsDelegate* g_instance = nullptr; |
26 | 27 |
27 } // namespace | 28 } // namespace |
28 | 29 |
29 CloudPrintTestsDelegate* CloudPrintTestsDelegate::Get() { | 30 CloudPrintTestsDelegate* CloudPrintTestsDelegate::Get() { |
30 return g_instance; | 31 return g_instance; |
31 } | 32 } |
32 | 33 |
33 CloudPrintTestsDelegate::CloudPrintTestsDelegate() { | 34 CloudPrintTestsDelegate::CloudPrintTestsDelegate() { |
34 g_instance = this; | 35 g_instance = this; |
35 } | 36 } |
36 | 37 |
37 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { | 38 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { |
38 g_instance = nullptr; | 39 g_instance = nullptr; |
39 } | 40 } |
40 | 41 |
41 CloudPrintPrivateSetupConnectorFunction:: | 42 CloudPrintPrivateSetupConnectorFunction:: |
42 CloudPrintPrivateSetupConnectorFunction() { | 43 CloudPrintPrivateSetupConnectorFunction() { |
43 } | 44 } |
44 | 45 |
45 CloudPrintPrivateSetupConnectorFunction:: | 46 CloudPrintPrivateSetupConnectorFunction:: |
46 ~CloudPrintPrivateSetupConnectorFunction() { | 47 ~CloudPrintPrivateSetupConnectorFunction() { |
47 } | 48 } |
48 | 49 |
49 bool CloudPrintPrivateSetupConnectorFunction::RunAsync() { | 50 bool CloudPrintPrivateSetupConnectorFunction::RunAsync() { |
50 #if defined(ENABLE_PRINT_PREVIEW) | 51 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
51 using api::cloud_print_private::SetupConnector::Params; | 52 using api::cloud_print_private::SetupConnector::Params; |
52 std::unique_ptr<Params> params(Params::Create(*args_)); | 53 std::unique_ptr<Params> params(Params::Create(*args_)); |
53 if (CloudPrintTestsDelegate::Get()) { | 54 if (CloudPrintTestsDelegate::Get()) { |
54 CloudPrintTestsDelegate::Get()->SetupConnector( | 55 CloudPrintTestsDelegate::Get()->SetupConnector( |
55 params->user_email, params->robot_email, params->credentials, | 56 params->user_email, params->robot_email, params->credentials, |
56 params->user_settings); | 57 params->user_settings); |
57 } else { | 58 } else { |
58 std::unique_ptr<base::DictionaryValue> user_settings( | 59 std::unique_ptr<base::DictionaryValue> user_settings( |
59 params->user_settings.ToValue()); | 60 params->user_settings.ToValue()); |
60 CloudPrintProxyService* service = | 61 CloudPrintProxyService* service = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() { | 95 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() { |
95 } | 96 } |
96 | 97 |
97 void CloudPrintPrivateGetPrintersFunction::SendResults( | 98 void CloudPrintPrivateGetPrintersFunction::SendResults( |
98 const std::vector<std::string>& printers) { | 99 const std::vector<std::string>& printers) { |
99 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers); | 100 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers); |
100 SendResponse(true); | 101 SendResponse(true); |
101 } | 102 } |
102 | 103 |
103 bool CloudPrintPrivateGetPrintersFunction::RunAsync() { | 104 bool CloudPrintPrivateGetPrintersFunction::RunAsync() { |
104 #if defined(ENABLE_PRINT_PREVIEW) | 105 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
105 if (CloudPrintTestsDelegate::Get()) { | 106 if (CloudPrintTestsDelegate::Get()) { |
106 SendResults(CloudPrintTestsDelegate::Get()->GetPrinters()); | 107 SendResults(CloudPrintTestsDelegate::Get()->GetPrinters()); |
107 } else { | 108 } else { |
108 CloudPrintProxyService* service = | 109 CloudPrintProxyService* service = |
109 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); | 110 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); |
110 if (!service) { | 111 if (!service) { |
111 error_ = kErrorIncognito; | 112 error_ = kErrorIncognito; |
112 return false; | 113 return false; |
113 } | 114 } |
114 service->GetPrinters( | 115 service->GetPrinters( |
(...skipping 15 matching lines...) Expand all Loading... |
130 bool CloudPrintPrivateGetClientIdFunction::RunAsync() { | 131 bool CloudPrintPrivateGetClientIdFunction::RunAsync() { |
131 SetResult(base::MakeUnique<base::StringValue>( | 132 SetResult(base::MakeUnique<base::StringValue>( |
132 CloudPrintTestsDelegate::Get() | 133 CloudPrintTestsDelegate::Get() |
133 ? CloudPrintTestsDelegate::Get()->GetClientId() | 134 ? CloudPrintTestsDelegate::Get()->GetClientId() |
134 : google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); | 135 : google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); |
135 SendResponse(true); | 136 SendResponse(true); |
136 return true; | 137 return true; |
137 } | 138 } |
138 | 139 |
139 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |