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

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

Issue 10968031: Added ConnectorSettings class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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_backend.h" 5 #include "chrome/service/cloud_print/cloud_print_proxy_backend.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/service/cloud_print/cloud_print_auth.h" 15 #include "chrome/service/cloud_print/cloud_print_auth.h"
16 #include "chrome/service/cloud_print/cloud_print_connector.h" 16 #include "chrome/service/cloud_print/cloud_print_connector.h"
17 #include "chrome/service/cloud_print/cloud_print_consts.h" 17 #include "chrome/service/cloud_print/cloud_print_consts.h"
18 #include "chrome/service/cloud_print/cloud_print_helpers.h" 18 #include "chrome/service/cloud_print/cloud_print_helpers.h"
19 #include "chrome/service/cloud_print/cloud_print_token_store.h" 19 #include "chrome/service/cloud_print/cloud_print_token_store.h"
20 #include "chrome/service/cloud_print/connector_settings.h"
20 #include "chrome/service/gaia/service_gaia_authenticator.h" 21 #include "chrome/service/gaia/service_gaia_authenticator.h"
21 #include "chrome/service/net/service_url_request_context.h" 22 #include "chrome/service/net/service_url_request_context.h"
22 #include "chrome/service/service_process.h" 23 #include "chrome/service/service_process.h"
23 #include "google_apis/gaia/gaia_oauth_client.h" 24 #include "google_apis/gaia/gaia_oauth_client.h"
24 #include "google_apis/gaia/gaia_urls.h" 25 #include "google_apis/gaia/gaia_urls.h"
25 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
26 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
27 #include "jingle/notifier/base/notifier_options.h" 28 #include "jingle/notifier/base/notifier_options.h"
28 #include "jingle/notifier/listener/push_client.h" 29 #include "jingle/notifier/listener/push_client.h"
29 #include "jingle/notifier/listener/push_client_observer.h" 30 #include "jingle/notifier/listener/push_client_observer.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 32
32 // The real guts of CloudPrintProxyBackend, to keep the public client API clean. 33 // The real guts of CloudPrintProxyBackend, to keep the public client API clean.
33 class CloudPrintProxyBackend::Core 34 class CloudPrintProxyBackend::Core
34 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>, 35 : public base::RefCountedThreadSafe<CloudPrintProxyBackend::Core>,
35 public CloudPrintAuth::Client, 36 public CloudPrintAuth::Client,
36 public CloudPrintConnector::Client, 37 public CloudPrintConnector::Client,
37 public notifier::PushClientObserver { 38 public notifier::PushClientObserver {
38 public: 39 public:
39 // It is OK for print_server_url to be empty. In this case system should 40 // It is OK for print_server_url to be empty. In this case system should
40 // use system default (local) print server. 41 // use system default (local) print server.
41 Core(CloudPrintProxyBackend* backend, 42 Core(CloudPrintProxyBackend* backend,
42 const std::string& proxy_id, 43 const ConnectorSettings& settings,
43 const GURL& cloud_print_server_url,
44 const DictionaryValue* print_system_settings,
45 const gaia::OAuthClientInfo& oauth_client_info, 44 const gaia::OAuthClientInfo& oauth_client_info,
46 bool enable_job_poll); 45 bool enable_job_poll);
47 46
48 // Note: 47 // Note:
49 // 48 //
50 // The Do* methods are the various entry points from CloudPrintProxyBackend 49 // The Do* methods are the various entry points from CloudPrintProxyBackend
51 // It calls us on a dedicated thread to actually perform synchronous 50 // It calls us on a dedicated thread to actually perform synchronous
52 // (and potentially blocking) operations. 51 // (and potentially blocking) operations.
53 // 52 //
54 // Called on the CloudPrintProxyBackend core_thread_ to perform 53 // Called on the CloudPrintProxyBackend core_thread_ to perform
55 // initialization. When we are passed in an LSID we authenticate using that 54 // initialization. When we are passed in an LSID we authenticate using that
56 // and retrieve new auth tokens. 55 // and retrieve new auth tokens.
57 void DoInitializeWithLsid(const std::string& lsid, 56 void DoInitializeWithLsid(const std::string& lsid,
58 const std::string& proxy_id,
59 const std::string& last_robot_refresh_token, 57 const std::string& last_robot_refresh_token,
60 const std::string& last_robot_email, 58 const std::string& last_robot_email,
61 const std::string& last_user_email); 59 const std::string& last_user_email);
62 60
63 void DoInitializeWithToken(const std::string& cloud_print_token, 61 void DoInitializeWithToken(const std::string& cloud_print_token);
64 const std::string& proxy_id);
65 void DoInitializeWithRobotToken(const std::string& robot_oauth_refresh_token, 62 void DoInitializeWithRobotToken(const std::string& robot_oauth_refresh_token,
66 const std::string& robot_email, 63 const std::string& robot_email);
67 const std::string& proxy_id);
68 void DoInitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code, 64 void DoInitializeWithRobotAuthCode(const std::string& robot_oauth_auth_code,
69 const std::string& robot_email, 65 const std::string& robot_email);
70 const std::string& proxy_id);
71 66
72 // Called on the CloudPrintProxyBackend core_thread_ to perform 67 // Called on the CloudPrintProxyBackend core_thread_ to perform
73 // shutdown. 68 // shutdown.
74 void DoShutdown(); 69 void DoShutdown();
75 void DoRegisterSelectedPrinters( 70 void DoRegisterSelectedPrinters(
76 const printing::PrinterList& printer_list); 71 const printing::PrinterList& printer_list);
77 void DoUnregisterPrinters(); 72 void DoUnregisterPrinters();
78 73
79 // CloudPrintAuth::Client implementation. 74 // CloudPrintAuth::Client implementation.
80 virtual void OnAuthenticationComplete( 75 virtual void OnAuthenticationComplete(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 123
129 // Our parent CloudPrintProxyBackend 124 // Our parent CloudPrintProxyBackend
130 CloudPrintProxyBackend* backend_; 125 CloudPrintProxyBackend* backend_;
131 126
132 // Cloud Print authenticator. 127 // Cloud Print authenticator.
133 scoped_refptr<CloudPrintAuth> auth_; 128 scoped_refptr<CloudPrintAuth> auth_;
134 129
135 // Cloud Print connector. 130 // Cloud Print connector.
136 scoped_refptr<CloudPrintConnector> connector_; 131 scoped_refptr<CloudPrintConnector> connector_;
137 132
138 // Server URL.
139 GURL cloud_print_server_url_;
140 // Proxy Id.
141 std::string proxy_id_;
142 // Print system settings.
143 scoped_ptr<DictionaryValue> print_system_settings_;
144 // OAuth client info. 133 // OAuth client info.
145 gaia::OAuthClientInfo oauth_client_info_; 134 gaia::OAuthClientInfo oauth_client_info_;
146 // Notification (xmpp) handler. 135 // Notification (xmpp) handler.
147 scoped_ptr<notifier::PushClient> push_client_; 136 scoped_ptr<notifier::PushClient> push_client_;
148 // Indicates whether XMPP notifications are currently enabled. 137 // Indicates whether XMPP notifications are currently enabled.
149 bool notifications_enabled_; 138 bool notifications_enabled_;
150 // The time when notifications were enabled. Valid only when 139 // The time when notifications were enabled. Valid only when
151 // notifications_enabled_ is true. 140 // notifications_enabled_ is true.
152 base::TimeTicks notifications_enabled_since_; 141 base::TimeTicks notifications_enabled_since_;
153 // Indicates whether a task to poll for jobs has been scheduled. 142 // Indicates whether a task to poll for jobs has been scheduled.
154 bool job_poll_scheduled_; 143 bool job_poll_scheduled_;
155 // Indicates whether we should poll for jobs when we lose XMPP connection. 144 // Indicates whether we should poll for jobs when we lose XMPP connection.
156 bool enable_job_poll_; 145 bool enable_job_poll_;
146 // Connector settings.
147 ConnectorSettings settings_;
157 scoped_ptr<CloudPrintTokenStore> token_store_; 148 scoped_ptr<CloudPrintTokenStore> token_store_;
158 149
159 DISALLOW_COPY_AND_ASSIGN(Core); 150 DISALLOW_COPY_AND_ASSIGN(Core);
160 }; 151 };
161 152
162 CloudPrintProxyBackend::CloudPrintProxyBackend( 153 CloudPrintProxyBackend::CloudPrintProxyBackend(
163 CloudPrintProxyFrontend* frontend, 154 CloudPrintProxyFrontend* frontend,
164 const std::string& proxy_id, 155 const ConnectorSettings& settings,
165 const GURL& cloud_print_server_url,
166 const DictionaryValue* print_system_settings,
167 const gaia::OAuthClientInfo& oauth_client_info, 156 const gaia::OAuthClientInfo& oauth_client_info,
168 bool enable_job_poll) 157 bool enable_job_poll)
169 : core_thread_("Chrome_CloudPrintProxyCoreThread"), 158 : core_thread_("Chrome_CloudPrintProxyCoreThread"),
170 frontend_loop_(MessageLoop::current()), 159 frontend_loop_(MessageLoop::current()),
171 frontend_(frontend) { 160 frontend_(frontend) {
172 DCHECK(frontend_); 161 DCHECK(frontend_);
173 core_ = new Core(this, 162 core_ = new Core(this, settings, oauth_client_info, enable_job_poll);
174 proxy_id,
175 cloud_print_server_url,
176 print_system_settings,
177 oauth_client_info,
178 enable_job_poll);
179 } 163 }
180 164
181 CloudPrintProxyBackend::~CloudPrintProxyBackend() { 165 CloudPrintProxyBackend::~CloudPrintProxyBackend() {
182 DCHECK(!core_); 166 DCHECK(!core_);
183 } 167 }
184 168
185 bool CloudPrintProxyBackend::InitializeWithLsid( 169 bool CloudPrintProxyBackend::InitializeWithLsid(
186 const std::string& lsid, 170 const std::string& lsid,
187 const std::string& proxy_id,
188 const std::string& last_robot_refresh_token, 171 const std::string& last_robot_refresh_token,
189 const std::string& last_robot_email, 172 const std::string& last_robot_email,
190 const std::string& last_user_email) { 173 const std::string& last_user_email) {
191 if (!core_thread_.Start()) 174 if (!core_thread_.Start())
192 return false; 175 return false;
193 core_thread_.message_loop()->PostTask( 176 core_thread_.message_loop()->PostTask(
194 FROM_HERE, 177 FROM_HERE,
195 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithLsid, 178 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithLsid,
196 core_.get(), lsid, proxy_id, last_robot_refresh_token, 179 core_.get(), lsid, last_robot_refresh_token, last_robot_email,
197 last_robot_email, last_user_email)); 180 last_user_email));
198 return true; 181 return true;
199 } 182 }
200 183
201 bool CloudPrintProxyBackend::InitializeWithToken( 184 bool CloudPrintProxyBackend::InitializeWithToken(
202 const std::string& cloud_print_token, 185 const std::string& cloud_print_token) {
203 const std::string& proxy_id) {
204 if (!core_thread_.Start()) 186 if (!core_thread_.Start())
205 return false; 187 return false;
206 core_thread_.message_loop()->PostTask( 188 core_thread_.message_loop()->PostTask(
207 FROM_HERE, 189 FROM_HERE,
208 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithToken, 190 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithToken,
209 core_.get(), cloud_print_token, proxy_id)); 191 core_.get(), cloud_print_token));
210 return true; 192 return true;
211 } 193 }
212 194
213 bool CloudPrintProxyBackend::InitializeWithRobotToken( 195 bool CloudPrintProxyBackend::InitializeWithRobotToken(
214 const std::string& robot_oauth_refresh_token, 196 const std::string& robot_oauth_refresh_token,
215 const std::string& robot_email, 197 const std::string& robot_email) {
216 const std::string& proxy_id) {
217 if (!core_thread_.Start()) 198 if (!core_thread_.Start())
218 return false; 199 return false;
219 core_thread_.message_loop()->PostTask( 200 core_thread_.message_loop()->PostTask(
220 FROM_HERE, 201 FROM_HERE,
221 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotToken, 202 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotToken,
222 core_.get(), robot_oauth_refresh_token, robot_email, 203 core_.get(), robot_oauth_refresh_token, robot_email));
223 proxy_id));
224 return true; 204 return true;
225 } 205 }
226 206
227 bool CloudPrintProxyBackend::InitializeWithRobotAuthCode( 207 bool CloudPrintProxyBackend::InitializeWithRobotAuthCode(
228 const std::string& robot_oauth_auth_code, 208 const std::string& robot_oauth_auth_code,
229 const std::string& robot_email, 209 const std::string& robot_email) {
230 const std::string& proxy_id) {
231 if (!core_thread_.Start()) 210 if (!core_thread_.Start())
232 return false; 211 return false;
233 core_thread_.message_loop()->PostTask( 212 core_thread_.message_loop()->PostTask(
234 FROM_HERE, 213 FROM_HERE,
235 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode, 214 base::Bind(&CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode,
236 core_.get(), robot_oauth_auth_code, robot_email, proxy_id)); 215 core_.get(), robot_oauth_auth_code, robot_email));
237 return true; 216 return true;
238 } 217 }
239 218
240 void CloudPrintProxyBackend::Shutdown() { 219 void CloudPrintProxyBackend::Shutdown() {
241 core_thread_.message_loop()->PostTask( 220 core_thread_.message_loop()->PostTask(
242 FROM_HERE, 221 FROM_HERE,
243 base::Bind(&CloudPrintProxyBackend::Core::DoShutdown, core_.get())); 222 base::Bind(&CloudPrintProxyBackend::Core::DoShutdown, core_.get()));
244 core_thread_.Stop(); 223 core_thread_.Stop();
245 core_ = NULL; // Releases reference to core_. 224 core_ = NULL; // Releases reference to core_.
246 } 225 }
247 226
248 void CloudPrintProxyBackend::UnregisterPrinters() { 227 void CloudPrintProxyBackend::UnregisterPrinters() {
249 core_thread_.message_loop()->PostTask( 228 core_thread_.message_loop()->PostTask(
250 FROM_HERE, 229 FROM_HERE,
251 base::Bind(&CloudPrintProxyBackend::Core::DoUnregisterPrinters, 230 base::Bind(&CloudPrintProxyBackend::Core::DoUnregisterPrinters,
252 core_.get())); 231 core_.get()));
253 } 232 }
254 233
255 CloudPrintProxyBackend::Core::Core( 234 CloudPrintProxyBackend::Core::Core(
256 CloudPrintProxyBackend* backend, 235 CloudPrintProxyBackend* backend,
257 const std::string& proxy_id, 236 const ConnectorSettings& settings,
258 const GURL& cloud_print_server_url,
259 const DictionaryValue* print_system_settings,
260 const gaia::OAuthClientInfo& oauth_client_info, 237 const gaia::OAuthClientInfo& oauth_client_info,
261 bool enable_job_poll) 238 bool enable_job_poll)
262 : backend_(backend), 239 : backend_(backend),
263 cloud_print_server_url_(cloud_print_server_url),
264 proxy_id_(proxy_id),
265 oauth_client_info_(oauth_client_info), 240 oauth_client_info_(oauth_client_info),
266 notifications_enabled_(false), 241 notifications_enabled_(false),
267 job_poll_scheduled_(false), 242 job_poll_scheduled_(false),
268 enable_job_poll_(enable_job_poll) { 243 enable_job_poll_(enable_job_poll) {
269 if (print_system_settings) { 244 settings_.CopyFrom(settings);
270 // It is possible to have no print settings specified.
271 print_system_settings_.reset(print_system_settings->DeepCopy());
272 }
273 } 245 }
274 246
275 void CloudPrintProxyBackend::Core::CreateAuthAndConnector() { 247 void CloudPrintProxyBackend::Core::CreateAuthAndConnector() {
276 if (!auth_.get()) { 248 if (!auth_.get()) {
277 auth_ = new CloudPrintAuth(this, 249 auth_ = new CloudPrintAuth(this, settings_.server_url(), oauth_client_info_,
278 cloud_print_server_url_, 250 settings_.proxy_id());
279 oauth_client_info_,
280 proxy_id_);
281 } 251 }
282 252
283 if (!connector_.get()) { 253 if (!connector_.get()) {
284 connector_ = new CloudPrintConnector(this, 254 connector_ = new CloudPrintConnector(this, settings_);
285 proxy_id_,
286 cloud_print_server_url_,
287 print_system_settings_.get());
288 } 255 }
289 } 256 }
290 257
291 void CloudPrintProxyBackend::Core::DestroyAuthAndConnector() { 258 void CloudPrintProxyBackend::Core::DestroyAuthAndConnector() {
292 auth_ = NULL; 259 auth_ = NULL;
293 connector_ = NULL; 260 connector_ = NULL;
294 } 261 }
295 262
296 void CloudPrintProxyBackend::Core::DoInitializeWithLsid( 263 void CloudPrintProxyBackend::Core::DoInitializeWithLsid(
297 const std::string& lsid, 264 const std::string& lsid,
298 const std::string& proxy_id,
299 const std::string& last_robot_refresh_token, 265 const std::string& last_robot_refresh_token,
300 const std::string& last_robot_email, 266 const std::string& last_robot_email,
301 const std::string& last_user_email) { 267 const std::string& last_user_email) {
302 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 268 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
303 CreateAuthAndConnector(); 269 CreateAuthAndConnector();
304 // Note: The GAIA login is synchronous but that should be OK because we are in 270 // Note: The GAIA login is synchronous but that should be OK because we are in
305 // the CloudPrintProxyCoreThread and we cannot really do anything else until 271 // the CloudPrintProxyCoreThread and we cannot really do anything else until
306 // the GAIA signin is successful. 272 // the GAIA signin is successful.
307 auth_->AuthenticateWithLsid(lsid, last_robot_refresh_token, 273 auth_->AuthenticateWithLsid(lsid, last_robot_refresh_token,
308 last_robot_email, last_user_email); 274 last_robot_email, last_user_email);
309 } 275 }
310 276
311 void CloudPrintProxyBackend::Core::DoInitializeWithToken( 277 void CloudPrintProxyBackend::Core::DoInitializeWithToken(
312 const std::string& cloud_print_token, 278 const std::string& cloud_print_token) {
313 const std::string& proxy_id) {
314 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 279 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
315 CreateAuthAndConnector(); 280 CreateAuthAndConnector();
316 auth_->AuthenticateWithToken(cloud_print_token); 281 auth_->AuthenticateWithToken(cloud_print_token);
317 } 282 }
318 283
319 void CloudPrintProxyBackend::Core::DoInitializeWithRobotToken( 284 void CloudPrintProxyBackend::Core::DoInitializeWithRobotToken(
320 const std::string& robot_oauth_refresh_token, 285 const std::string& robot_oauth_refresh_token,
321 const std::string& robot_email, 286 const std::string& robot_email) {
322 const std::string& proxy_id) {
323 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 287 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
324 CreateAuthAndConnector(); 288 CreateAuthAndConnector();
325 auth_->AuthenticateWithRobotToken(robot_oauth_refresh_token, robot_email); 289 auth_->AuthenticateWithRobotToken(robot_oauth_refresh_token, robot_email);
326 } 290 }
327 291
328 void CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode( 292 void CloudPrintProxyBackend::Core::DoInitializeWithRobotAuthCode(
329 const std::string& robot_oauth_auth_code, 293 const std::string& robot_oauth_auth_code,
330 const std::string& robot_email, 294 const std::string& robot_email) {
331 const std::string& proxy_id) {
332 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 295 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
333 CreateAuthAndConnector(); 296 CreateAuthAndConnector();
334 auth_->AuthenticateWithRobotAuthCode(robot_oauth_auth_code, robot_email); 297 auth_->AuthenticateWithRobotAuthCode(robot_oauth_auth_code, robot_email);
335 } 298 }
336 299
337 void CloudPrintProxyBackend::Core::OnAuthenticationComplete( 300 void CloudPrintProxyBackend::Core::OnAuthenticationComplete(
338 const std::string& access_token, 301 const std::string& access_token,
339 const std::string& robot_oauth_refresh_token, 302 const std::string& robot_oauth_refresh_token,
340 const std::string& robot_email, 303 const std::string& robot_email,
341 const std::string& user_email) { 304 const std::string& user_email) {
342 CloudPrintTokenStore* token_store = GetTokenStore(); 305 CloudPrintTokenStore* token_store = GetTokenStore();
343 bool first_time = token_store->token().empty(); 306 bool first_time = token_store->token().empty();
344 token_store->SetToken(access_token); 307 token_store->SetToken(access_token);
345 // Let the frontend know that we have authenticated. 308 // Let the frontend know that we have authenticated.
346 backend_->frontend_loop_->PostTask( 309 backend_->frontend_loop_->PostTask(
347 FROM_HERE, 310 FROM_HERE,
348 base::Bind(&Core::NotifyAuthenticated, this, robot_oauth_refresh_token, 311 base::Bind(&Core::NotifyAuthenticated, this, robot_oauth_refresh_token,
349 robot_email, user_email)); 312 robot_email, user_email));
350 if (first_time) { 313 if (first_time) {
351 InitNotifications(robot_email, access_token); 314 InitNotifications(robot_email, access_token);
352 } else { 315 } else {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 notifier::Subscription subscription; 360 notifier::Subscription subscription;
398 subscription.channel = kCloudPrintPushNotificationsSource; 361 subscription.channel = kCloudPrintPushNotificationsSource;
399 subscription.from = kCloudPrintPushNotificationsSource; 362 subscription.from = kCloudPrintPushNotificationsSource;
400 push_client_->UpdateSubscriptions( 363 push_client_->UpdateSubscriptions(
401 notifier::SubscriptionList(1, subscription)); 364 notifier::SubscriptionList(1, subscription));
402 push_client_->UpdateCredentials(robot_email, access_token); 365 push_client_->UpdateCredentials(robot_email, access_token);
403 } 366 }
404 367
405 void CloudPrintProxyBackend::Core::DoShutdown() { 368 void CloudPrintProxyBackend::Core::DoShutdown() {
406 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 369 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
407 VLOG(1) << "CP_CONNECTOR: Shutdown connector, id: " << proxy_id_; 370 VLOG(1) << "CP_CONNECTOR: Shutdown connector, id: " << settings_.proxy_id();
408 371
409 if (connector_->IsRunning()) 372 if (connector_->IsRunning())
410 connector_->Stop(); 373 connector_->Stop();
411 374
412 // Important to delete the PushClient on this thread. 375 // Important to delete the PushClient on this thread.
413 if (push_client_.get()) { 376 if (push_client_.get()) {
414 push_client_->RemoveObserver(this); 377 push_client_->RemoveObserver(this);
415 } 378 }
416 push_client_.reset(); 379 push_client_.reset();
417 notifications_enabled_ = false; 380 notifications_enabled_ = false;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 const std::string& auth_token, 461 const std::string& auth_token,
499 const std::list<std::string>& printer_ids) { 462 const std::list<std::string>& printer_ids) {
500 DCHECK(MessageLoop::current() == backend_->frontend_loop_); 463 DCHECK(MessageLoop::current() == backend_->frontend_loop_);
501 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids); 464 backend_->frontend_->OnUnregisterPrinters(auth_token, printer_ids);
502 } 465 }
503 466
504 void CloudPrintProxyBackend::Core::OnNotificationsEnabled() { 467 void CloudPrintProxyBackend::Core::OnNotificationsEnabled() {
505 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 468 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
506 notifications_enabled_ = true; 469 notifications_enabled_ = true;
507 notifications_enabled_since_ = base::TimeTicks::Now(); 470 notifications_enabled_since_ = base::TimeTicks::Now();
508 VLOG(1) << "Notifications for connector " << proxy_id_ 471 VLOG(1) << "Notifications for connector " << settings_.proxy_id()
509 << " were enabled at " 472 << " were enabled at "
510 << notifications_enabled_since_.ToInternalValue(); 473 << notifications_enabled_since_.ToInternalValue();
511 // Notifications just got re-enabled. In this case we want to schedule 474 // Notifications just got re-enabled. In this case we want to schedule
512 // a poll once for jobs we might have missed when we were dark. 475 // a poll once for jobs we might have missed when we were dark.
513 // Note that ScheduleJobPoll will not schedule again if a job poll task is 476 // Note that ScheduleJobPoll will not schedule again if a job poll task is
514 // already scheduled. 477 // already scheduled.
515 ScheduleJobPoll(); 478 ScheduleJobPoll();
516 } 479 }
517 480
518 void CloudPrintProxyBackend::Core::OnNotificationsDisabled( 481 void CloudPrintProxyBackend::Core::OnNotificationsDisabled(
519 notifier::NotificationsDisabledReason reason) { 482 notifier::NotificationsDisabledReason reason) {
520 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 483 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
521 notifications_enabled_ = false; 484 notifications_enabled_ = false;
522 LOG(ERROR) << "Notifications for connector " << proxy_id_ << " disabled."; 485 LOG(ERROR) << "Notifications for connector " << settings_.proxy_id()
486 << " disabled.";
523 notifications_enabled_since_ = base::TimeTicks(); 487 notifications_enabled_since_ = base::TimeTicks();
524 // We just lost notifications. This this case we want to schedule a 488 // We just lost notifications. This this case we want to schedule a
525 // job poll if enable_job_poll_ is true. 489 // job poll if enable_job_poll_ is true.
526 if (enable_job_poll_) 490 if (enable_job_poll_)
527 ScheduleJobPoll(); 491 ScheduleJobPoll();
528 } 492 }
529 493
530 494
531 void CloudPrintProxyBackend::Core::OnIncomingNotification( 495 void CloudPrintProxyBackend::Core::OnIncomingNotification(
532 const notifier::Notification& notification) { 496 const notifier::Notification& notification) {
533 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); 497 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop());
534 VLOG(1) << "CP_CONNECTOR: Incoming notification."; 498 VLOG(1) << "CP_CONNECTOR: Incoming notification.";
535 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, 499 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource,
536 notification.channel.c_str())) 500 notification.channel.c_str()))
537 HandlePrinterNotification(notification.data); 501 HandlePrinterNotification(notification.data);
538 } 502 }
503
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698