| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/local_discovery/privet_http_impl.h" | 5 #include "chrome/browser/local_discovery/privet_http_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/location.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" |
| 15 #include "chrome/browser/local_discovery/privet_constants.h" | 17 #include "chrome/browser/local_discovery/privet_constants.h" |
| 16 #include "net/base/url_util.h" | 18 #include "net/base/url_util.h" |
| 17 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 18 | 20 |
| 19 #if defined(ENABLE_PRINT_PREVIEW) | 21 #if defined(ENABLE_PRINT_PREVIEW) |
| 20 #include "chrome/browser/local_discovery/pwg_raster_converter.h" | 22 #include "chrome/browser/local_discovery/pwg_raster_converter.h" |
| 21 #include "components/cloud_devices/common/printer_description.h" | 23 #include "components/cloud_devices/common/printer_description.h" |
| 22 #include "printing/pdf_render_settings.h" | 24 #include "printing/pdf_render_settings.h" |
| 23 #include "printing/pwg_raster_settings.h" | 25 #include "printing/pwg_raster_settings.h" |
| 24 #include "ui/gfx/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 SendRequest(kPrivetActionStart); | 141 SendRequest(kPrivetActionStart); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void PrivetRegisterOperationImpl::Cancel() { | 144 void PrivetRegisterOperationImpl::Cancel() { |
| 143 url_fetcher_.reset(); | 145 url_fetcher_.reset(); |
| 144 | 146 |
| 145 if (ongoing_) { | 147 if (ongoing_) { |
| 146 // Owned by the message loop. | 148 // Owned by the message loop. |
| 147 Cancelation* cancelation = new Cancelation(privet_client_, user_); | 149 Cancelation* cancelation = new Cancelation(privet_client_, user_); |
| 148 | 150 |
| 149 base::MessageLoop::current()->PostDelayedTask( | 151 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 150 FROM_HERE, | 152 FROM_HERE, |
| 151 base::Bind(&PrivetRegisterOperationImpl::Cancelation::Cleanup, | 153 base::Bind(&PrivetRegisterOperationImpl::Cancelation::Cleanup, |
| 152 base::Owned(cancelation)), | 154 base::Owned(cancelation)), |
| 153 base::TimeDelta::FromSeconds(kPrivetCancelationTimeoutSeconds)); | 155 base::TimeDelta::FromSeconds(kPrivetCancelationTimeoutSeconds)); |
| 154 | 156 |
| 155 ongoing_ = false; | 157 ongoing_ = false; |
| 156 } | 158 } |
| 157 } | 159 } |
| 158 | 160 |
| 159 void PrivetRegisterOperationImpl::CompleteRegistration() { | 161 void PrivetRegisterOperationImpl::CompleteRegistration() { |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 int timeout = kPrivetLocalPrintDefaultTimeout; | 568 int timeout = kPrivetLocalPrintDefaultTimeout; |
| 567 value->GetInteger(kPrivetKeyTimeout, &timeout); | 569 value->GetInteger(kPrivetKeyTimeout, &timeout); |
| 568 | 570 |
| 569 double random_scaling_factor = | 571 double random_scaling_factor = |
| 570 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition; | 572 1 + base::RandDouble() * kPrivetMaximumTimeRandomAddition; |
| 571 | 573 |
| 572 timeout = static_cast<int>(timeout * random_scaling_factor); | 574 timeout = static_cast<int>(timeout * random_scaling_factor); |
| 573 | 575 |
| 574 timeout = std::max(timeout, kPrivetMinimumTimeout); | 576 timeout = std::max(timeout, kPrivetMinimumTimeout); |
| 575 | 577 |
| 576 base::MessageLoop::current()->PostDelayedTask( | 578 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 577 FROM_HERE, base::Bind(&PrivetLocalPrintOperationImpl::DoCreatejob, | 579 FROM_HERE, base::Bind(&PrivetLocalPrintOperationImpl::DoCreatejob, |
| 578 weak_factory_.GetWeakPtr()), | 580 weak_factory_.GetWeakPtr()), |
| 579 base::TimeDelta::FromSeconds(timeout)); | 581 base::TimeDelta::FromSeconds(timeout)); |
| 580 } else if (use_pdf_ && error == kPrivetErrorInvalidDocumentType) { | 582 } else if (use_pdf_ && error == kPrivetErrorInvalidDocumentType) { |
| 581 use_pdf_ = false; | 583 use_pdf_ = false; |
| 582 StartConvertToPWG(); | 584 StartConvertToPWG(); |
| 583 } else { | 585 } else { |
| 584 delegate_->OnPrivetPrintingError(this, 200); | 586 delegate_->OnPrivetPrintingError(this, 200); |
| 585 } | 587 } |
| 586 | 588 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 PrivetLocalPrintOperation::Delegate* delegate) { | 793 PrivetLocalPrintOperation::Delegate* delegate) { |
| 792 #if defined(ENABLE_PRINT_PREVIEW) | 794 #if defined(ENABLE_PRINT_PREVIEW) |
| 793 return scoped_ptr<PrivetLocalPrintOperation>( | 795 return scoped_ptr<PrivetLocalPrintOperation>( |
| 794 new PrivetLocalPrintOperationImpl(info_client(), delegate)); | 796 new PrivetLocalPrintOperationImpl(info_client(), delegate)); |
| 795 #else | 797 #else |
| 796 return scoped_ptr<PrivetLocalPrintOperation>(); | 798 return scoped_ptr<PrivetLocalPrintOperation>(); |
| 797 #endif // ENABLE_PRINT_PREVIEW | 799 #endif // ENABLE_PRINT_PREVIEW |
| 798 } | 800 } |
| 799 | 801 |
| 800 } // namespace local_discovery | 802 } // namespace local_discovery |
| OLD | NEW |