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

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

Issue 208653010: Use service process to collect printers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #if defined(ENABLE_FULL_PRINTING) 42 #if defined(ENABLE_FULL_PRINTING)
43 using api::cloud_print_private::SetupConnector::Params; 43 using api::cloud_print_private::SetupConnector::Params;
44 scoped_ptr<Params> params(Params::Create(*args_)); 44 scoped_ptr<Params> params(Params::Create(*args_));
45 if (CloudPrintTestsDelegate::instance()) { 45 if (CloudPrintTestsDelegate::instance()) {
46 CloudPrintTestsDelegate::instance()->SetupConnector( 46 CloudPrintTestsDelegate::instance()->SetupConnector(
47 params->user_email, 47 params->user_email,
48 params->robot_email, 48 params->robot_email,
49 params->credentials, 49 params->credentials,
50 params->user_settings); 50 params->user_settings);
51 } else { 51 } else {
52 if (!CloudPrintProxyServiceFactory::GetForProfile(GetProfile())) 52 CloudPrintProxyService* service =
53 CloudPrintProxyServiceFactory::GetForProfile(GetProfile());
54 if (!service)
53 return false; 55 return false;
54 scoped_ptr<base::DictionaryValue> user_setings( 56 scoped_ptr<base::DictionaryValue> user_setings(
55 params->user_settings.ToValue()); 57 params->user_settings.ToValue());
56 CloudPrintProxyServiceFactory::GetForProfile(GetProfile()) 58 service->EnableForUserWithRobot(params->credentials,
57 ->EnableForUserWithRobot(params->credentials, 59 params->robot_email,
58 params->robot_email, 60 params->user_email,
59 params->user_email, 61 *user_setings);
60 *user_setings);
61 } 62 }
62 SendResponse(true); 63 SendResponse(true);
64 return true;
65 #else
66 return false;
63 #endif 67 #endif
64 return true;
65 } 68 }
66 69
67 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() { 70 CloudPrintPrivateGetHostNameFunction::CloudPrintPrivateGetHostNameFunction() {
68 } 71 }
69 72
70 CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() { 73 CloudPrintPrivateGetHostNameFunction::~CloudPrintPrivateGetHostNameFunction() {
71 } 74 }
72 75
73 bool CloudPrintPrivateGetHostNameFunction::RunImpl() { 76 bool CloudPrintPrivateGetHostNameFunction::RunImpl() {
74 SetResult(new base::StringValue( 77 SetResult(new base::StringValue(
75 CloudPrintTestsDelegate::instance() ? 78 CloudPrintTestsDelegate::instance() ?
76 CloudPrintTestsDelegate::instance()->GetHostName() : 79 CloudPrintTestsDelegate::instance()->GetHostName() :
77 net::GetHostName())); 80 net::GetHostName()));
78 SendResponse(true); 81 SendResponse(true);
79 return true; 82 return true;
80 } 83 }
81 84
82 CloudPrintPrivateGetPrintersFunction::CloudPrintPrivateGetPrintersFunction() { 85 CloudPrintPrivateGetPrintersFunction::CloudPrintPrivateGetPrintersFunction() {
83 } 86 }
84 87
85 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() { 88 CloudPrintPrivateGetPrintersFunction::~CloudPrintPrivateGetPrintersFunction() {
86 } 89 }
87 90
88 void CloudPrintPrivateGetPrintersFunction::CollectPrinters() { 91 void CloudPrintPrivateGetPrintersFunction::SendResults(
92 const std::vector<std::string>& printers) {
93 results_ = api::cloud_print_private::GetPrinters::Results::Create(printers);
94 SendResponse(true);
95 }
96
97 bool CloudPrintPrivateGetPrintersFunction::RunImpl() {
89 #if defined(ENABLE_FULL_PRINTING) 98 #if defined(ENABLE_FULL_PRINTING)
90 std::vector<std::string> result; 99 std::vector<std::string> result;
91 if (CloudPrintTestsDelegate::instance()) { 100 if (CloudPrintTestsDelegate::instance()) {
92 result = CloudPrintTestsDelegate::instance()->GetPrinters(); 101 SendResults(CloudPrintTestsDelegate::instance()->GetPrinters());
93 } else { 102 } else {
94 CloudPrintProxyService::GetPrintersAvalibleForRegistration(&result); 103 CloudPrintProxyService* service =
104 CloudPrintProxyServiceFactory::GetForProfile(GetProfile());
105 if (!service)
106 return false;
107 service->GetPrinters(
108 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResults, this));
95 } 109 }
96 results_ = api::cloud_print_private::GetPrinters::Results::Create(result); 110 return true;
97 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 111 #else
98 base::Bind(&CloudPrintPrivateGetPrintersFunction::SendResponse, 112 return false;
99 this, true));
100 #endif 113 #endif
101 } 114 }
102 115
103 116
104 bool CloudPrintPrivateGetPrintersFunction::RunImpl() {
105 content::BrowserThread::GetBlockingPool()->PostTask(FROM_HERE,
106 base::Bind(&CloudPrintPrivateGetPrintersFunction::CollectPrinters, this));
107 return true;
108 }
109
110
111 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() { 117 CloudPrintPrivateGetClientIdFunction::CloudPrintPrivateGetClientIdFunction() {
112 } 118 }
113 119
114 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() { 120 CloudPrintPrivateGetClientIdFunction::~CloudPrintPrivateGetClientIdFunction() {
115 } 121 }
116 122
117 bool CloudPrintPrivateGetClientIdFunction::RunImpl() { 123 bool CloudPrintPrivateGetClientIdFunction::RunImpl() {
118 SetResult(new base::StringValue( 124 SetResult(new base::StringValue(
119 CloudPrintTestsDelegate::instance() ? 125 CloudPrintTestsDelegate::instance() ?
120 CloudPrintTestsDelegate::instance()->GetClientId() : 126 CloudPrintTestsDelegate::instance()->GetClientId() :
121 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT))); 127 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT)));
122 SendResponse(true); 128 SendResponse(true);
123 return true; 129 return true;
124 } 130 }
125 131
126 } // namespace extensions 132 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698