Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/extensions/api/cloud_print_private/cloud_print_private_api.cc

Issue 1898503002: Cleanup LocalDiscoveryUIHandler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 11 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
12 #include "chrome/common/extensions/api/cloud_print_private.h" 12 #include "chrome/common/extensions/api/cloud_print_private.h"
13 #include "google_apis/google_api_keys.h" 13 #include "google_apis/google_api_keys.h"
14 #include "net/base/network_interfaces.h" 14 #include "net/base/network_interfaces.h"
15 15
16 namespace extensions { 16 namespace extensions {
17 17
18 CloudPrintTestsDelegate* CloudPrintTestsDelegate::instance_ = NULL; 18 namespace {
19 19
20 CloudPrintTestsDelegate* CloudPrintTestsDelegate::instance() { 20 const char kErrorIncognito[] = "Cannot access in incognito mode";
21 return instance_; 21
22 CloudPrintTestsDelegate* g_instance = nullptr;
23
24 } // namespace
25
26 CloudPrintTestsDelegate* CloudPrintTestsDelegate::Get() {
27 return g_instance;
22 } 28 }
23 29
24 CloudPrintTestsDelegate::CloudPrintTestsDelegate() { 30 CloudPrintTestsDelegate::CloudPrintTestsDelegate() {
25 instance_ = this; 31 g_instance = this;
26 } 32 }
27 33
28 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() { 34 CloudPrintTestsDelegate::~CloudPrintTestsDelegate() {
29 instance_ = NULL; 35 g_instance = nullptr;
30 } 36 }
31 37
32 CloudPrintPrivateSetupConnectorFunction:: 38 CloudPrintPrivateSetupConnectorFunction::
33 CloudPrintPrivateSetupConnectorFunction() { 39 CloudPrintPrivateSetupConnectorFunction() {
34 } 40 }
35 41
36 CloudPrintPrivateSetupConnectorFunction:: 42 CloudPrintPrivateSetupConnectorFunction::
37 ~CloudPrintPrivateSetupConnectorFunction() { 43 ~CloudPrintPrivateSetupConnectorFunction() {
38 } 44 }
39 45
40 bool CloudPrintPrivateSetupConnectorFunction::RunAsync() { 46 bool CloudPrintPrivateSetupConnectorFunction::RunAsync() {
41 #if defined(ENABLE_PRINT_PREVIEW) 47 #if defined(ENABLE_PRINT_PREVIEW)
42 using api::cloud_print_private::SetupConnector::Params; 48 using api::cloud_print_private::SetupConnector::Params;
43 std::unique_ptr<Params> params(Params::Create(*args_)); 49 std::unique_ptr<Params> params(Params::Create(*args_));
44 if (CloudPrintTestsDelegate::instance()) { 50 if (CloudPrintTestsDelegate::Get()) {
45 CloudPrintTestsDelegate::instance()->SetupConnector( 51 CloudPrintTestsDelegate::Get()->SetupConnector(
46 params->user_email, 52 params->user_email, params->robot_email, params->credentials,
47 params->robot_email,
48 params->credentials,
49 params->user_settings); 53 params->user_settings);
50 } else { 54 } else {
55 std::unique_ptr<base::DictionaryValue> user_settings(
56 params->user_settings.ToValue());
51 CloudPrintProxyService* service = 57 CloudPrintProxyService* service =
52 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); 58 CloudPrintProxyServiceFactory::GetForProfile(GetProfile());
53 if (!service) 59 if (!service) {
60 error_ = kErrorIncognito;
54 return false; 61 return false;
55 std::unique_ptr<base::DictionaryValue> user_setings( 62 }
56 params->user_settings.ToValue()); 63 service->EnableForUserWithRobot(params->credentials, params->robot_email,
57 service->EnableForUserWithRobot(params->credentials, 64 params->user_email, *user_settings);
58 params->robot_email,
59 params->user_email,
60 *user_setings);
61 } 65 }
62 SendResponse(true); 66 SendResponse(true);
63 return true; 67 return true;
64 #else 68 #else
65 return false; 69 return false;
66 #endif 70 #endif
67 } 71 }
68 72
69 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() { 73 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() {
70 } 74 }
71 75
72 CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() { 76 CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() {
73 } 77 }
74 78
75 bool CloudPrintPrivateGetHostNameFunction::RunAsync() { 79 bool CloudPrintPrivateGetHostNameFunction::RunAsync() {
76 SetResult(new base::StringValue( 80 SetResult(
77 CloudPrintTestsDelegate::instance() ? 81 new base::StringValue(CloudPrintTestsDelegate::Get()
78 CloudPrintTestsDelegate::instance()->GetHostName() : 82 ? CloudPrintTestsDelegate::Get()->GetHostName()
79 net::GetHostName())); 83 : net::GetHostName()));
80 SendResponse(true); 84 SendResponse(true);
81 return true; 85 return true;
82 } 86 }
83 87
84 CloudPrintPrivateGetPrintersFunction::CloudPrintPrivateGetPrintersFunction() { 88 CloudPrintPrivateGetPrintersFunction::CloudPrintPrivateGetPrintersFunction() {
85 } 89 }
86 90
87 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() { 91 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() {
88 } 92 }
89 93
90 void CloudPrintPrivateGetPrintersFunction::SendResults( 94 void CloudPrintPrivateGetPrintersFunction::SendResults(
91 const std::vector<std::string>& printers) { 95 const std::vector<std::string>& printers) {
92 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers); 96 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers);
93 SendResponse(true); 97 SendResponse(true);
94 } 98 }
95 99
96 bool CloudPrintPrivateGetPrintersFunction::RunAsync() { 100 bool CloudPrintPrivateGetPrintersFunction::RunAsync() {
97 #if defined(ENABLE_PRINT_PREVIEW) 101 #if defined(ENABLE_PRINT_PREVIEW)
98 std::vector<std::string> result; 102 if (CloudPrintTestsDelegate::Get()) {
99 if (CloudPrintTestsDelegate::instance()) { 103 SendResults(CloudPrintTestsDelegate::Get()->GetPrinters());
100 SendResults(CloudPrintTestsDelegate::instance()->GetPrinters());
101 } else { 104 } else {
102 CloudPrintProxyService* service = 105 CloudPrintProxyService* service =
103 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()); 106 CloudPrintProxyServiceFactory::GetForProfile(GetProfile());
104 if (!service) 107 if (!service) {
108 error_ = kErrorIncognito;
105 return false; 109 return false;
110 }
106 service->GetPrinters( 111 service->GetPrinters(
107 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this)); 112 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this));
108 } 113 }
109 return true; 114 return true;
110 #else 115 #else
111 return false; 116 return false;
112 #endif 117 #endif
113 } 118 }
114 119
115 120
116 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() { 121 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() {
117 } 122 }
118 123
119 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() { 124 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() {
120 } 125 }
121 126
122 bool CloudPrintPrivateGetClientIdFunction::RunAsync() { 127 bool CloudPrintPrivateGetClientIdFunction::RunAsync() {
123 SetResult(new base::StringValue( 128 SetResult(new base::StringValue(
124 CloudPrintTestsDelegate::instance() ? 129 CloudPrintTestsDelegate::Get()
125 CloudPrintTestsDelegate::instance()->GetClientId() : 130 ? CloudPrintTestsDelegate::Get()->GetClientId()
126 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); 131 : google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT)));
127 SendResponse(true); 132 SendResponse(true);
128 return true; 133 return true;
129 } 134 }
130 135
131 } // namespace extensions 136 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698