| 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/printing/cloud_print/privet_url_fetcher.h" | 5 #include "chrome/browser/printing/cloud_print/privet_url_fetcher.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/debug/dump_without_crashing.h" | 14 #include "base/debug/dump_without_crashing.h" |
| 15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/printing/cloud_print/privet_constants.h" | 23 #include "chrome/browser/printing/cloud_print/privet_constants.h" |
| 24 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 25 #include "net/base/load_flags.h" | 26 #include "net/base/load_flags.h" |
| 26 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
| 27 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 29 | 30 |
| 30 namespace cloud_print { | 31 namespace cloud_print { |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 byte_range_start_ = start; | 144 byte_range_start_ = start; |
| 144 byte_range_end_ = end; | 145 byte_range_end_ = end; |
| 145 has_byte_range_ = true; | 146 has_byte_range_ = true; |
| 146 } | 147 } |
| 147 | 148 |
| 148 void PrivetURLFetcher::Try() { | 149 void PrivetURLFetcher::Try() { |
| 149 tries_++; | 150 tries_++; |
| 150 if (tries_ <= max_retries_) { | 151 if (tries_ <= max_retries_) { |
| 151 DVLOG(1) << "Attempt: " << tries_; | 152 DVLOG(1) << "Attempt: " << tries_; |
| 152 url_fetcher_ = net::URLFetcher::Create(url_, request_type_, this); | 153 url_fetcher_ = net::URLFetcher::Create(url_, request_type_, this); |
| 154 data_use_measurement::DataUseUserData::AttachToFetcher( |
| 155 url_fetcher_.get(), data_use_measurement::DataUseUserData::CLOUD_PRINT); |
| 156 |
| 153 // Privet requests are relevant to hosts on local network only. | 157 // Privet requests are relevant to hosts on local network only. |
| 154 url_fetcher_->SetLoadFlags( | 158 url_fetcher_->SetLoadFlags( |
| 155 url_fetcher_->GetLoadFlags() | net::LOAD_BYPASS_PROXY | | 159 url_fetcher_->GetLoadFlags() | net::LOAD_BYPASS_PROXY | |
| 156 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES); | 160 net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SEND_COOKIES); |
| 157 url_fetcher_->SetRequestContext(context_getter_.get()); | 161 url_fetcher_->SetRequestContext(context_getter_.get()); |
| 158 | 162 |
| 159 std::string token = GetPrivetAccessToken(); | 163 std::string token = GetPrivetAccessToken(); |
| 160 | 164 |
| 161 if (token.empty()) | 165 if (token.empty()) |
| 162 token = kXPrivetEmptyToken; | 166 token = kXPrivetEmptyToken; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 385 } |
| 382 | 386 |
| 383 bool PrivetURLFetcher::PrivetErrorTransient(const std::string& error) { | 387 bool PrivetURLFetcher::PrivetErrorTransient(const std::string& error) { |
| 384 return (error == kPrivetErrorDeviceBusy) || | 388 return (error == kPrivetErrorDeviceBusy) || |
| 385 (error == kPrivetV3ErrorDeviceBusy) || | 389 (error == kPrivetV3ErrorDeviceBusy) || |
| 386 (error == kPrivetErrorPendingUserAction) || | 390 (error == kPrivetErrorPendingUserAction) || |
| 387 (error == kPrivetErrorPrinterBusy); | 391 (error == kPrivetErrorPrinterBusy); |
| 388 } | 392 } |
| 389 | 393 |
| 390 } // namespace cloud_print | 394 } // namespace cloud_print |
| OLD | NEW |