OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 392 |
393 job_poll_scheduled_ = false; | 393 job_poll_scheduled_ = false; |
394 // If we don't have notifications and job polling is enabled, poll again | 394 // If we don't have notifications and job polling is enabled, poll again |
395 // after a while. | 395 // after a while. |
396 if (!notifications_enabled_ && enable_job_poll_) | 396 if (!notifications_enabled_ && enable_job_poll_) |
397 ScheduleJobPoll(); | 397 ScheduleJobPoll(); |
398 } | 398 } |
399 | 399 |
400 void CloudPrintProxyBackend::Core::ScheduleJobPoll() { | 400 void CloudPrintProxyBackend::Core::ScheduleJobPoll() { |
401 if (!job_poll_scheduled_) { | 401 if (!job_poll_scheduled_) { |
402 int interval_in_seconds = base::RandInt(kMinJobPollIntervalSecs, | 402 base::TimeDelta interval = base::TimeDelta::FromSeconds( |
403 kMaxJobPollIntervalSecs); | 403 base::RandInt(kMinJobPollIntervalSecs, kMaxJobPollIntervalSecs)); |
404 MessageLoop::current()->PostDelayedTask( | 404 MessageLoop::current()->PostDelayedTask( |
405 FROM_HERE, | 405 FROM_HERE, |
406 base::Bind(&CloudPrintProxyBackend::Core::PollForJobs, this), | 406 base::Bind(&CloudPrintProxyBackend::Core::PollForJobs, this), |
407 interval_in_seconds * 1000); | 407 interval); |
408 job_poll_scheduled_ = true; | 408 job_poll_scheduled_ = true; |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 CloudPrintTokenStore* CloudPrintProxyBackend::Core::GetTokenStore() { | 412 CloudPrintTokenStore* CloudPrintProxyBackend::Core::GetTokenStore() { |
413 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 413 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
414 if (!token_store_.get()) | 414 if (!token_store_.get()) |
415 token_store_.reset(new CloudPrintTokenStore); | 415 token_store_.reset(new CloudPrintTokenStore); |
416 return token_store_.get(); | 416 return token_store_.get(); |
417 } | 417 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 void CloudPrintProxyBackend::Core::OnIncomingNotification( | 464 void CloudPrintProxyBackend::Core::OnIncomingNotification( |
465 const notifier::Notification& notification) { | 465 const notifier::Notification& notification) { |
466 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); | 466 DCHECK(MessageLoop::current() == backend_->core_thread_.message_loop()); |
467 VLOG(1) << "CP_CONNECTOR: Incoming notification."; | 467 VLOG(1) << "CP_CONNECTOR: Incoming notification."; |
468 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, | 468 if (0 == base::strcasecmp(kCloudPrintPushNotificationsSource, |
469 notification.channel.c_str())) | 469 notification.channel.c_str())) |
470 HandlePrinterNotification(notification.data); | 470 HandlePrinterNotification(notification.data); |
471 } | 471 } |
472 | 472 |
473 void CloudPrintProxyBackend::Core::OnOutgoingNotification() {} | 473 void CloudPrintProxyBackend::Core::OnOutgoingNotification() {} |
OLD | NEW |