| 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_url_fetcher.h" | 5 #include "chrome/browser/local_discovery/privet_url_fetcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/dump_without_crashing.h" |
| 10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 13 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
| 14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/local_discovery/privet_constants.h" | 19 #include "chrome/browser/local_discovery/privet_constants.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 205 |
| 205 url_fetcher_->Start(); | 206 url_fetcher_->Start(); |
| 206 } else { | 207 } else { |
| 207 delegate_->OnError(this, UNKNOWN_ERROR); | 208 delegate_->OnError(this, UNKNOWN_ERROR); |
| 208 } | 209 } |
| 209 } | 210 } |
| 210 | 211 |
| 211 void PrivetURLFetcher::Start() { | 212 void PrivetURLFetcher::Start() { |
| 212 DCHECK_EQ(tries_, 0); // We haven't called |Start()| yet. | 213 DCHECK_EQ(tries_, 0); // We haven't called |Start()| yet. |
| 213 | 214 |
| 215 if (!url_.is_valid()) { |
| 216 // Not yet clear why it's possible. crbug.com/513505 |
| 217 base::debug::DumpWithoutCrashing(); |
| 218 return delegate_->OnError(this, UNKNOWN_ERROR); |
| 219 } |
| 220 |
| 214 if (!send_empty_privet_token_ && !v3_mode_) { | 221 if (!send_empty_privet_token_ && !v3_mode_) { |
| 215 std::string privet_access_token; | 222 std::string privet_access_token; |
| 216 privet_access_token = GetPrivetAccessToken(); | 223 privet_access_token = GetPrivetAccessToken(); |
| 217 if (privet_access_token.empty()) { | 224 if (privet_access_token.empty()) { |
| 218 RequestTokenRefresh(); | 225 RequestTokenRefresh(); |
| 219 return; | 226 return; |
| 220 } | 227 } |
| 221 } | 228 } |
| 222 | 229 |
| 223 Try(); | 230 Try(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 } | 398 } |
| 392 | 399 |
| 393 bool PrivetURLFetcher::PrivetErrorTransient(const std::string& error) { | 400 bool PrivetURLFetcher::PrivetErrorTransient(const std::string& error) { |
| 394 return (error == kPrivetErrorDeviceBusy) || | 401 return (error == kPrivetErrorDeviceBusy) || |
| 395 (error == kPrivetV3ErrorDeviceBusy) || | 402 (error == kPrivetV3ErrorDeviceBusy) || |
| 396 (error == kPrivetErrorPendingUserAction) || | 403 (error == kPrivetErrorPendingUserAction) || |
| 397 (error == kPrivetErrorPrinterBusy); | 404 (error == kPrivetErrorPrinterBusy); |
| 398 } | 405 } |
| 399 | 406 |
| 400 } // namespace local_discovery | 407 } // namespace local_discovery |
| OLD | NEW |