| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/quirks/quirks_client.h" | 5 #include "components/quirks/quirks_client.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 12 #include "components/prefs/scoped_user_pref_update.h" | 12 #include "components/prefs/scoped_user_pref_update.h" |
| 13 #include "components/quirks/quirks_manager.h" | 13 #include "components/quirks/quirks_manager.h" |
| 14 #include "components/version_info/version_info.h" | 14 #include "components/version_info/version_info.h" |
| 15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 16 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 17 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 19 | 19 |
| 20 namespace quirks { | 20 namespace quirks { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kQuirksUrlFormat[] = | 24 const char kQuirksUrlFormat[] = |
| 25 "https://chromeosquirksserver-pa.googleapis.com/v2/display/%s/clients" | 25 "https://chromeosquirksserver-pa.googleapis.com/v2/display/%s/clients" |
| 26 "/chromeos/M%d"; | 26 "/chromeos/M%d"; |
| 27 | 27 |
| 28 const int kMaxServerFailures = 10; |
| 29 |
| 28 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { | 30 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { |
| 29 1, // Initial errors before applying backoff | 31 1, // Initial errors before applying backoff |
| 30 10000, // 10 seconds. | 32 10000, // 10 seconds. |
| 31 2, // Factor by which the waiting time will be multiplied. | 33 2, // Factor by which the waiting time will be multiplied. |
| 32 0, // Random fuzzing percentage. | 34 0, // Random fuzzing percentage. |
| 33 1000 * 3600 * 6, // Max wait between requests = 6 hours. | 35 1000 * 3600 * 6, // Max wait between requests = 6 hours. |
| 34 -1, // Don't discard entry. | 36 -1, // Don't discard entry. |
| 35 true, // Use initial delay after first error. | 37 true, // Use initial delay after first error. |
| 36 }; | 38 }; |
| 37 | 39 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 << ", response_code=" << response_code | 106 << ", response_code=" << response_code |
| 105 << ", server_error=" << server_error; | 107 << ", server_error=" << server_error; |
| 106 | 108 |
| 107 if (response_code == net::HTTP_NOT_FOUND) { | 109 if (response_code == net::HTTP_NOT_FOUND) { |
| 108 VLOG(1) << IdToFileName(product_id_) << " not found on Quirks server."; | 110 VLOG(1) << IdToFileName(product_id_) << " not found on Quirks server."; |
| 109 Shutdown(false); | 111 Shutdown(false); |
| 110 return; | 112 return; |
| 111 } | 113 } |
| 112 | 114 |
| 113 if (server_error) { | 115 if (server_error) { |
| 116 if (backoff_entry_.failure_count() >= kMaxServerFailures) { |
| 117 // After 10 retires (5+ hours), give up, and try again in a month. |
| 118 VLOG(1) << "Too many retries; Quirks Client shutting down."; |
| 119 Shutdown(false); |
| 120 return; |
| 121 } |
| 114 url_fetcher_.reset(); | 122 url_fetcher_.reset(); |
| 115 Retry(); | 123 Retry(); |
| 116 return; | 124 return; |
| 117 } | 125 } |
| 118 | 126 |
| 119 std::string response; | 127 std::string response; |
| 120 url_fetcher_->GetResponseAsString(&response); | 128 url_fetcher_->GetResponseAsString(&response); |
| 121 VLOG(2) << "Quirks server response:\n" << response; | 129 VLOG(2) << "Quirks server response:\n" << response; |
| 122 | 130 |
| 123 // Parse response data and write to file on file thread. | 131 // Parse response data and write to file on file thread. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 170 |
| 163 if (!base::Base64Decode(data64, data)) { | 171 if (!base::Base64Decode(data64, data)) { |
| 164 VLOG(1) << "Failed to decode Base64 icc data"; | 172 VLOG(1) << "Failed to decode Base64 icc data"; |
| 165 return false; | 173 return false; |
| 166 } | 174 } |
| 167 | 175 |
| 168 return true; | 176 return true; |
| 169 } | 177 } |
| 170 | 178 |
| 171 } // namespace quirks | 179 } // namespace quirks |
| OLD | NEW |