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

Side by Side Diff: chrome/service/cloud_print/cloud_print_proxy.cc

Issue 10968031: Added ConnectorSettings class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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/service/cloud_print/cloud_print_proxy.h" 5 #include "chrome/service/cloud_print/cloud_print_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken, 94 service_prefs_->GetString(prefs::kCloudPrintRobotRefreshToken,
95 &robot_refresh_token); 95 &robot_refresh_token);
96 std::string robot_email; 96 std::string robot_email;
97 service_prefs_->GetString(prefs::kCloudPrintRobotEmail, 97 service_prefs_->GetString(prefs::kCloudPrintRobotEmail,
98 &robot_email); 98 &robot_email);
99 service_prefs_->GetString(prefs::kCloudPrintEmail, &user_email_); 99 service_prefs_->GetString(prefs::kCloudPrintEmail, &user_email_);
100 100
101 // If we have been passed in an LSID, we want to use this to authenticate. 101 // If we have been passed in an LSID, we want to use this to authenticate.
102 // Else we will try and retrieve the last used auth tokens from prefs. 102 // Else we will try and retrieve the last used auth tokens from prefs.
103 if (!lsid.empty()) { 103 if (!lsid.empty()) {
104 backend_->InitializeWithLsid(lsid, 104 backend_->InitializeWithLsid(lsid, robot_refresh_token, robot_email,
105 proxy_id_,
106 robot_refresh_token,
107 robot_email,
108 user_email_); 105 user_email_);
109 } else { 106 } else {
110 // See if we have persisted robot credentials. 107 // See if we have persisted robot credentials.
111 if (!robot_refresh_token.empty()) { 108 if (!robot_refresh_token.empty()) {
112 DCHECK(!robot_email.empty()); 109 DCHECK(!robot_email.empty());
113 backend_->InitializeWithRobotToken(robot_refresh_token, 110 backend_->InitializeWithRobotToken(robot_refresh_token, robot_email);
114 robot_email,
115 proxy_id_);
116 } else { 111 } else {
117 // Finally see if we have persisted user credentials (legacy case). 112 // Finally see if we have persisted user credentials (legacy case).
118 std::string cloud_print_token; 113 std::string cloud_print_token;
119 service_prefs_->GetString(prefs::kCloudPrintAuthToken, 114 service_prefs_->GetString(prefs::kCloudPrintAuthToken,
120 &cloud_print_token); 115 &cloud_print_token);
121 DCHECK(!cloud_print_token.empty()); 116 DCHECK(!cloud_print_token.empty());
122 backend_->InitializeWithToken(cloud_print_token, proxy_id_); 117 backend_->InitializeWithToken(cloud_print_token);
123 } 118 }
124 } 119 }
125 if (client_) { 120 if (client_) {
126 client_->OnCloudPrintProxyEnabled(true); 121 client_->OnCloudPrintProxyEnabled(true);
127 } 122 }
128 } 123 }
129 124
130 void CloudPrintProxy::EnableForUserWithRobot( 125 void CloudPrintProxy::EnableForUserWithRobot(
131 const std::string& robot_auth_code, 126 const std::string& robot_auth_code,
132 const std::string& robot_email, 127 const std::string& robot_email,
133 const std::string& user_email) { 128 const std::string& user_email) {
134 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
135 if (!CreateBackend()) 130 if (!CreateBackend())
136 return; 131 return;
137 DCHECK(backend_.get()); 132 DCHECK(backend_.get());
138 user_email_ = user_email; 133 user_email_ = user_email;
139 backend_->InitializeWithRobotAuthCode(robot_auth_code, 134 backend_->InitializeWithRobotAuthCode(robot_auth_code, robot_email);
140 robot_email,
141 proxy_id_);
142 if (client_) { 135 if (client_) {
143 client_->OnCloudPrintProxyEnabled(true); 136 client_->OnCloudPrintProxyEnabled(true);
144 } 137 }
145 } 138 }
146 139
147 bool CloudPrintProxy::CreateBackend() { 140 bool CloudPrintProxy::CreateBackend() {
148 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
149 if (backend_.get()) 142 if (backend_.get())
150 return false; 143 return false;
151 144
152 service_prefs_->GetString(prefs::kCloudPrintProxyId, &proxy_id_); 145 settings_.InitFrom(service_prefs_);
153 if (proxy_id_.empty()) {
154 proxy_id_ = cloud_print::PrintSystem::GenerateProxyId();
155 service_prefs_->SetString(prefs::kCloudPrintProxyId, proxy_id_);
156 service_prefs_->WritePrefs();
157 }
158
159 // Getting print system specific settings from the preferences.
160 const DictionaryValue* print_system_settings = NULL;
161 service_prefs_->GetDictionary(prefs::kCloudPrintPrintSystemSettings,
162 &print_system_settings);
163
164 // Check if there is an override for the cloud print server URL.
165 std::string cloud_print_server_url_str;
166 service_prefs_->GetString(prefs::kCloudPrintServiceURL,
167 &cloud_print_server_url_str);
168 if (cloud_print_server_url_str.empty()) {
169 cloud_print_server_url_str = kDefaultCloudPrintServerUrl;
170 }
171 146
172 // By default we don't poll for jobs when we lose XMPP connection. But this 147 // By default we don't poll for jobs when we lose XMPP connection. But this
173 // behavior can be overridden by a preference. 148 // behavior can be overridden by a preference.
174 bool enable_job_poll = false; 149 bool enable_job_poll = false;
175 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, 150 service_prefs_->GetBoolean(prefs::kCloudPrintEnableJobPoll, &enable_job_poll);
176 &enable_job_poll);
177 151
178 // TODO(sanjeevr): Allow overriding OAuthClientInfo in prefs.
179 gaia::OAuthClientInfo oauth_client_info; 152 gaia::OAuthClientInfo oauth_client_info;
180 oauth_client_info.client_id = 153 oauth_client_info.client_id =
181 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT); 154 google_apis::GetOAuth2ClientID(google_apis::CLIENT_CLOUD_PRINT);
182 oauth_client_info.client_secret = 155 oauth_client_info.client_secret =
183 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT); 156 google_apis::GetOAuth2ClientSecret(google_apis::CLIENT_CLOUD_PRINT);
157 backend_.reset(new CloudPrintProxyBackend(this, settings_, oauth_client_info,
158 enable_job_poll));
184 159
185 cloud_print_server_url_ = GURL(cloud_print_server_url_str.c_str());
186 DCHECK(cloud_print_server_url_.is_valid());
187 backend_.reset(new CloudPrintProxyBackend(this, proxy_id_,
188 cloud_print_server_url_,
189 print_system_settings,
190 oauth_client_info,
191 enable_job_poll));
192 return true; 160 return true;
193 } 161 }
194 162
195 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() { 163 void CloudPrintProxy::UnregisterPrintersAndDisableForUser() {
196 DCHECK(CalledOnValidThread()); 164 DCHECK(CalledOnValidThread());
197 if (backend_.get()) { 165 if (backend_.get()) {
198 // Try getting auth and printers info from the backend. 166 // Try getting auth and printers info from the backend.
199 // We'll get notified in this case. 167 // We'll get notified in this case.
200 backend_->UnregisterPrinters(); 168 backend_->UnregisterPrinters();
201 } else { 169 } else {
(...skipping 10 matching lines...) Expand all
212 client_->OnCloudPrintProxyDisabled(true); 180 client_->OnCloudPrintProxyDisabled(true);
213 } 181 }
214 ShutdownBackend(); 182 ShutdownBackend();
215 } 183 }
216 184
217 void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) { 185 void CloudPrintProxy::GetProxyInfo(cloud_print::CloudPrintProxyInfo* info) {
218 info->enabled = enabled_; 186 info->enabled = enabled_;
219 info->email.clear(); 187 info->email.clear();
220 if (enabled_) 188 if (enabled_)
221 info->email = user_email(); 189 info->email = user_email();
222 info->proxy_id = proxy_id_; 190 info->proxy_id = settings_.proxy_id();
223 // If the Cloud Print service is not enabled, we may need to read the old 191 // If the Cloud Print service is not enabled, we may need to read the old
224 // value of proxy_id from prefs. 192 // value of proxy_id from prefs.
225 if (info->proxy_id.empty()) 193 if (info->proxy_id.empty())
226 service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id); 194 service_prefs_->GetString(prefs::kCloudPrintProxyId, &info->proxy_id);
227 } 195 }
228 196
229 void CloudPrintProxy::CheckCloudPrintProxyPolicy() { 197 void CloudPrintProxy::CheckCloudPrintProxyPolicy() {
230 g_service_process->io_thread()->message_loop_proxy()->PostTask( 198 g_service_process->io_thread()->message_loop_proxy()->PostTask(
231 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser)); 199 FROM_HERE, base::Bind(&CheckCloudPrintProxyPolicyInBrowser));
232 } 200 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 ShutdownBackend(); 242 ShutdownBackend();
275 if (client_) { 243 if (client_) {
276 client_->OnCloudPrintProxyDisabled(false); 244 client_->OnCloudPrintProxyDisabled(false);
277 } 245 }
278 } 246 }
279 247
280 void CloudPrintProxy::OnUnregisterPrinters( 248 void CloudPrintProxy::OnUnregisterPrinters(
281 const std::string& auth_token, 249 const std::string& auth_token,
282 const std::list<std::string>& printer_ids) { 250 const std::list<std::string>& printer_ids) {
283 ShutdownBackend(); 251 ShutdownBackend();
284 wipeout_.reset(new CloudPrintWipeout(this, cloud_print_server_url_)); 252 wipeout_.reset(new CloudPrintWipeout(this, settings_.server_url()));
285 wipeout_->UnregisterPrinters(auth_token, printer_ids); 253 wipeout_->UnregisterPrinters(auth_token, printer_ids);
286 } 254 }
287 255
288 void CloudPrintProxy::OnUnregisterPrintersComplete() { 256 void CloudPrintProxy::OnUnregisterPrintersComplete() {
289 wipeout_.reset(); 257 wipeout_.reset();
290 // Finish disabling cloud print for this user. 258 // Finish disabling cloud print for this user.
291 DisableForUser(); 259 DisableForUser();
292 } 260 }
293 261
294 void CloudPrintProxy::ShutdownBackend() { 262 void CloudPrintProxy::ShutdownBackend() {
295 DCHECK(CalledOnValidThread()); 263 DCHECK(CalledOnValidThread());
296 if (backend_.get()) 264 if (backend_.get())
297 backend_->Shutdown(); 265 backend_->Shutdown();
298 backend_.reset(); 266 backend_.reset();
299 } 267 }
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/cloud_print_proxy.h ('k') | chrome/service/cloud_print/cloud_print_proxy_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698