| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chromeos/printing/cups_print_job_manager_impl.h" | 5 #include "chrome/browser/chromeos/printing/cups_print_job_manager_impl.h" |
| 6 | 6 |
| 7 #include <cups/cups.h> | 7 #include <cups/cups.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 void CupsPrintJobManagerImpl::ScheduleQuery() { | 349 void CupsPrintJobManagerImpl::ScheduleQuery() { |
| 350 ScheduleQuery(base::TimeDelta::FromMilliseconds(kPollRate)); | 350 ScheduleQuery(base::TimeDelta::FromMilliseconds(kPollRate)); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void CupsPrintJobManagerImpl::ScheduleQuery(const base::TimeDelta& delay) { | 353 void CupsPrintJobManagerImpl::ScheduleQuery(const base::TimeDelta& delay) { |
| 354 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 354 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 355 | 355 |
| 356 if (!in_query_) { | 356 if (!in_query_) { |
| 357 in_query_ = true; | 357 in_query_ = true; |
| 358 | 358 |
| 359 content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::UI) | 359 content::BrowserThread::PostDelayedTask( |
| 360 ->PostDelayedTask(FROM_HERE, | 360 content::BrowserThread::UI, FROM_HERE, |
| 361 base::Bind(&CupsPrintJobManagerImpl::PostQuery, | 361 base::Bind(&CupsPrintJobManagerImpl::PostQuery, |
| 362 weak_ptr_factory_.GetWeakPtr()), | 362 weak_ptr_factory_.GetWeakPtr()), |
| 363 delay); | 363 delay); |
| 364 } | 364 } |
| 365 } | 365 } |
| 366 | 366 |
| 367 void CupsPrintJobManagerImpl::PostQuery() { | 367 void CupsPrintJobManagerImpl::PostQuery() { |
| 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 368 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 369 | 369 |
| 370 // The set of active printers is expected to be small. | 370 // The set of active printers is expected to be small. |
| 371 std::set<std::string> printer_ids; | 371 std::set<std::string> printer_ids; |
| 372 for (const auto& entry : jobs_) { | 372 for (const auto& entry : jobs_) { |
| 373 printer_ids.insert(entry.second->printer().id()); | 373 printer_ids.insert(entry.second->printer().id()); |
| 374 } | 374 } |
| 375 std::vector<std::string> ids{printer_ids.begin(), printer_ids.end()}; | 375 std::vector<std::string> ids{printer_ids.begin(), printer_ids.end()}; |
| 376 | 376 |
| 377 auto result = base::MakeUnique<QueryResult>(); | 377 auto result = base::MakeUnique<QueryResult>(); |
| 378 QueryResult* result_ptr = result.get(); | 378 QueryResult* result_ptr = result.get(); |
| 379 // Runs a query on query_runner_ which will rejoin this sequnece on | 379 // Runs a query on |query_runner_| which will rejoin this sequnece on |
| 380 // completion. | 380 // completion. |
| 381 query_runner_->PostTaskAndReply( | 381 query_runner_->PostTaskAndReply( |
| 382 FROM_HERE, | 382 FROM_HERE, |
| 383 base::Bind(&CupsWrapper::QueryCups, base::Unretained(cups_wrapper_.get()), | 383 base::Bind(&CupsWrapper::QueryCups, base::Unretained(cups_wrapper_.get()), |
| 384 ids, result_ptr), | 384 ids, result_ptr), |
| 385 base::Bind(&CupsPrintJobManagerImpl::UpdateJobs, | 385 base::Bind(&CupsPrintJobManagerImpl::UpdateJobs, |
| 386 weak_ptr_factory_.GetWeakPtr(), base::Passed(&result))); | 386 weak_ptr_factory_.GetWeakPtr(), base::Passed(&result))); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Use job information to update local job states. Previously completed jobs | 389 // Use job information to update local job states. Previously completed jobs |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 break; | 506 break; |
| 507 } | 507 } |
| 508 } | 508 } |
| 509 | 509 |
| 510 // static | 510 // static |
| 511 CupsPrintJobManager* CupsPrintJobManager::CreateInstance(Profile* profile) { | 511 CupsPrintJobManager* CupsPrintJobManager::CreateInstance(Profile* profile) { |
| 512 return new CupsPrintJobManagerImpl(profile); | 512 return new CupsPrintJobManagerImpl(profile); |
| 513 } | 513 } |
| 514 | 514 |
| 515 } // namespace chromeos | 515 } // namespace chromeos |
| OLD | NEW |