Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: components/quirks/quirks_client.cc

Issue 2765703003: Include display names in Quirks URL (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/quirks/quirks_client.h ('k') | components/quirks/quirks_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "components/prefs/scoped_user_pref_update.h" 13 #include "components/prefs/scoped_user_pref_update.h"
14 #include "components/quirks/quirks_manager.h" 14 #include "components/quirks/quirks_manager.h"
15 #include "components/version_info/version_info.h" 15 #include "components/version_info/version_info.h"
16 #include "net/base/escape.h"
16 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
17 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
18 #include "net/url_request/url_fetcher.h" 19 #include "net/url_request/url_fetcher.h"
19 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
20 21
21 namespace quirks { 22 namespace quirks {
22 23
23 namespace { 24 namespace {
24 25
25 const char kQuirksUrlFormat[] = 26 const char kQuirksUrlFormat[] =
26 "https://chromeosquirksserver-pa.googleapis.com/v2/display/%s/clients" 27 "https://chromeosquirksserver-pa.googleapis.com/v2/display/%s/clients"
27 "/chromeos/M%d"; 28 "/chromeos/M%d?";
28 29
29 const int kMaxServerFailures = 10; 30 const int kMaxServerFailures = 10;
30 31
31 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { 32 const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
32 1, // Initial errors before applying backoff 33 1, // Initial errors before applying backoff
33 10000, // 10 seconds. 34 10000, // 10 seconds.
34 2, // Factor by which the waiting time will be multiplied. 35 2, // Factor by which the waiting time will be multiplied.
35 0, // Random fuzzing percentage. 36 0, // Random fuzzing percentage.
36 1000 * 3600 * 6, // Max wait between requests = 6 hours. 37 1000 * 3600 * 6, // Max wait between requests = 6 hours.
37 -1, // Don't discard entry. 38 -1, // Don't discard entry.
38 true, // Use initial delay after first error. 39 true, // Use initial delay after first error.
39 }; 40 };
40 41
41 bool WriteIccFile(const base::FilePath file_path, const std::string& data) { 42 bool WriteIccFile(const base::FilePath file_path, const std::string& data) {
42 int bytes_written = base::WriteFile(file_path, data.data(), data.length()); 43 int bytes_written = base::WriteFile(file_path, data.data(), data.length());
43 if (bytes_written == -1) 44 if (bytes_written == -1)
44 LOG(ERROR) << "Write failed: " << file_path.value() << ", err = " << errno; 45 LOG(ERROR) << "Write failed: " << file_path.value() << ", err = " << errno;
45 else 46 else
46 VLOG(1) << bytes_written << "bytes written to: " << file_path.value(); 47 VLOG(1) << bytes_written << "bytes written to: " << file_path.value();
47 48
48 return (bytes_written != -1); 49 return (bytes_written != -1);
49 } 50 }
50 51
51 } // namespace 52 } // namespace
52 53
53 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
54 // QuirksClient 55 // QuirksClient
55 56
56 QuirksClient::QuirksClient(int64_t product_id, 57 QuirksClient::QuirksClient(int64_t product_id,
58 const std::string& display_name,
57 const RequestFinishedCallback& on_request_finished, 59 const RequestFinishedCallback& on_request_finished,
58 QuirksManager* manager) 60 QuirksManager* manager)
59 : product_id_(product_id), 61 : product_id_(product_id),
62 display_name_(display_name),
60 on_request_finished_(on_request_finished), 63 on_request_finished_(on_request_finished),
61 manager_(manager), 64 manager_(manager),
62 icc_path_(manager->delegate()->GetDisplayProfileDirectory().Append( 65 icc_path_(manager->delegate()->GetDisplayProfileDirectory().Append(
63 IdToFileName(product_id))), 66 IdToFileName(product_id))),
64 backoff_entry_(&kDefaultBackoffPolicy), 67 backoff_entry_(&kDefaultBackoffPolicy),
65 weak_ptr_factory_(this) {} 68 weak_ptr_factory_(this) {}
66 69
67 QuirksClient::~QuirksClient() {} 70 QuirksClient::~QuirksClient() {}
68 71
69 void QuirksClient::StartDownload() { 72 void QuirksClient::StartDownload() {
70 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
71 74
72 // URL of icc file on Quirks Server. 75 // URL of icc file on Quirks Server.
73 int major_version = atoi(version_info::GetVersionNumber().c_str()); 76 int major_version = atoi(version_info::GetVersionNumber().c_str());
74 std::string url = base::StringPrintf( 77 std::string url = base::StringPrintf(
75 kQuirksUrlFormat, IdToHexString(product_id_).c_str(), major_version); 78 kQuirksUrlFormat, IdToHexString(product_id_).c_str(), major_version);
76 79
80 if (!display_name_.empty()) {
81 url +=
82 "display_name=" + net::EscapeQueryParamValue(display_name_, true) + "&";
83 }
84
77 VLOG(2) << "Preparing to download\n " << url << "\nto file " 85 VLOG(2) << "Preparing to download\n " << url << "\nto file "
78 << icc_path_.value(); 86 << icc_path_.value();
79 87
80 url += "?key="; 88 url += "key=" + manager_->delegate()->GetApiKey();
81 url += manager_->delegate()->GetApiKey();
82 89
83 url_fetcher_ = manager_->CreateURLFetcher(GURL(url), this); 90 url_fetcher_ = manager_->CreateURLFetcher(GURL(url), this);
84 url_fetcher_->SetRequestContext(manager_->url_context_getter()); 91 url_fetcher_->SetRequestContext(manager_->url_context_getter());
85 url_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE | 92 url_fetcher_->SetLoadFlags(net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE |
86 net::LOAD_DO_NOT_SAVE_COOKIES | 93 net::LOAD_DO_NOT_SAVE_COOKIES |
87 net::LOAD_DO_NOT_SEND_COOKIES | 94 net::LOAD_DO_NOT_SEND_COOKIES |
88 net::LOAD_DO_NOT_SEND_AUTH_DATA); 95 net::LOAD_DO_NOT_SEND_AUTH_DATA);
89 url_fetcher_->Start(); 96 url_fetcher_->Start();
90 } 97 }
91 98
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 177
171 if (!base::Base64Decode(data64, data)) { 178 if (!base::Base64Decode(data64, data)) {
172 VLOG(1) << "Failed to decode Base64 icc data"; 179 VLOG(1) << "Failed to decode Base64 icc data";
173 return false; 180 return false;
174 } 181 }
175 182
176 return true; 183 return true;
177 } 184 }
178 185
179 } // namespace quirks 186 } // namespace quirks
OLDNEW
« no previous file with comments | « components/quirks/quirks_client.h ('k') | components/quirks/quirks_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698