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

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

Issue 2006143011: Remove first check random delay on older devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove obsolete TODO Created 4 years, 5 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_manager.h ('k') | no next file » | 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_manager.h" 5 #include "components/quirks/quirks_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/rand_util.h"
15 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
16 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
17 #include "components/prefs/pref_registry_simple.h" 16 #include "components/prefs/pref_registry_simple.h"
18 #include "components/prefs/scoped_user_pref_update.h" 17 #include "components/prefs/scoped_user_pref_update.h"
19 #include "components/quirks/pref_names.h" 18 #include "components/quirks/pref_names.h"
20 #include "components/quirks/quirks_client.h" 19 #include "components/quirks/quirks_client.h"
21 #include "components/quirks/switches.h" 20 #include "components/quirks/switches.h"
22 #include "net/url_request/url_fetcher.h" 21 #include "net/url_request/url_fetcher.h"
23 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
24 #include "url/gurl.h" 23 #include "url/gurl.h"
(...skipping 16 matching lines...) Expand all
41 // TODO(glevin): If file exists, do we want to implement a hash to verify that 40 // TODO(glevin): If file exists, do we want to implement a hash to verify that
42 // the file hasn't been corrupted or tampered with? 41 // the file hasn't been corrupted or tampered with?
43 return exists; 42 return exists;
44 } 43 }
45 44
46 base::FilePath CheckForIccFile(base::FilePath built_in_path, 45 base::FilePath CheckForIccFile(base::FilePath built_in_path,
47 base::FilePath download_path, 46 base::FilePath download_path,
48 bool quirks_enabled) { 47 bool quirks_enabled) {
49 // First, look for icc file in old read-only location. If there, we don't use 48 // First, look for icc file in old read-only location. If there, we don't use
50 // the Quirks server. 49 // the Quirks server.
51 // TODO(glevin): Awaiting final decision on how to handle old read-only files.
52 if (CheckAndLogFile(built_in_path)) 50 if (CheckAndLogFile(built_in_path))
53 return built_in_path; 51 return built_in_path;
54 52
55 // If experimental Quirks flag isn't set, no other icc file is available. 53 // If experimental Quirks flag isn't set, no other icc file is available.
56 if (!quirks_enabled) { 54 if (!quirks_enabled) {
57 VLOG(1) << "Quirks Client disabled, no built-in icc file available."; 55 VLOG(1) << "Quirks Client disabled, no built-in icc file available.";
58 return base::FilePath(); 56 return base::FilePath();
59 } 57 }
60 58
61 // Check if QuirksClient has already downloaded icc file from server. 59 // Check if QuirksClient has already downloaded icc file from server.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 on_request_finished.Run(path, false); 182 on_request_finished.Run(path, false);
185 // TODO(glevin): If Quirks files are ever modified on the server, we'll need 183 // TODO(glevin): If Quirks files are ever modified on the server, we'll need
186 // to modify this logic to check for updates. See crbug.com/595024. 184 // to modify this logic to check for updates. See crbug.com/595024.
187 return; 185 return;
188 } 186 }
189 187
190 double last_check = 0.0; 188 double last_check = 0.0;
191 local_state_->GetDictionary(prefs::kQuirksClientLastServerCheck) 189 local_state_->GetDictionary(prefs::kQuirksClientLastServerCheck)
192 ->GetDouble(IdToHexString(product_id), &last_check); 190 ->GetDouble(IdToHexString(product_id), &last_check);
193 191
194 // If never checked server before, need to check for new device.
195 if (last_check == 0.0) {
196 delegate_->GetDaysSinceOobe(base::Bind(
197 &QuirksManager::OnDaysSinceOobeReceived, weak_ptr_factory_.GetWeakPtr(),
198 product_id, on_request_finished));
199 return;
200 }
201
202 const base::TimeDelta time_since = 192 const base::TimeDelta time_since =
203 base::Time::Now() - base::Time::FromDoubleT(last_check); 193 base::Time::Now() - base::Time::FromDoubleT(last_check);
204 194
205 // Don't need server check if we've checked within last 30 days. 195 // Don't need server check if we've checked within last 30 days.
206 if (time_since < base::TimeDelta::FromDays(kDaysBetweenServerChecks)) { 196 if (time_since < base::TimeDelta::FromDays(kDaysBetweenServerChecks)) {
207 VLOG(2) << time_since.InDays() 197 VLOG(2) << time_since.InDays()
208 << " days since last Quirks Server check for display " 198 << " days since last Quirks Server check for display "
209 << IdToHexString(product_id); 199 << IdToHexString(product_id);
210 on_request_finished.Run(base::FilePath(), false); 200 on_request_finished.Run(base::FilePath(), false);
211 return; 201 return;
212 } 202 }
213 203
214 CreateClient(product_id, on_request_finished); 204 // Create and start a client to download file.
215 }
216
217 void QuirksManager::OnDaysSinceOobeReceived(
218 int64_t product_id,
219 const RequestFinishedCallback& on_request_finished,
220 int days_since_oobe) {
221 DCHECK(thread_checker_.CalledOnValidThread());
222 // On newer devices, we want to check server immediately (after OOBE/login).
223 if (days_since_oobe <= kDaysBetweenServerChecks) {
224 CreateClient(product_id, on_request_finished);
225 return;
226 }
227
228 // Otherwise, for the first check on an older device, we want to stagger
229 // it over 30 days, so artificially set last check accordingly.
230 // TODO(glevin): I believe that it makes sense to remove this random delay
231 // in the next Chrome release.
232 const int rand_days = base::RandInt(0, kDaysBetweenServerChecks);
233 const base::Time fake_last_check =
234 base::Time::Now() - base::TimeDelta::FromDays(rand_days);
235 SetLastServerCheck(product_id, fake_last_check);
236 VLOG(2) << "Delaying first Quirks Server check by "
237 << kDaysBetweenServerChecks - rand_days << " days.";
238
239 on_request_finished.Run(base::FilePath(), false);
240 }
241
242 void QuirksManager::CreateClient(
243 int64_t product_id,
244 const RequestFinishedCallback& on_request_finished) {
245 DCHECK(thread_checker_.CalledOnValidThread());
246 QuirksClient* client = 205 QuirksClient* client =
247 new QuirksClient(product_id, on_request_finished, this); 206 new QuirksClient(product_id, on_request_finished, this);
248 clients_.insert(base::WrapUnique(client)); 207 clients_.insert(base::WrapUnique(client));
249 if (!waiting_for_login_) 208 if (!waiting_for_login_)
250 client->StartDownload(); 209 client->StartDownload();
251 else 210 else
252 VLOG(2) << "Quirks Client created; waiting for login to begin download."; 211 VLOG(2) << "Quirks Client created; waiting for login to begin download.";
253 } 212 }
254 213
255 bool QuirksManager::QuirksEnabled() { 214 bool QuirksManager::QuirksEnabled() {
(...skipping 10 matching lines...) Expand all
266 } 225 }
267 226
268 void QuirksManager::SetLastServerCheck(int64_t product_id, 227 void QuirksManager::SetLastServerCheck(int64_t product_id,
269 const base::Time& last_check) { 228 const base::Time& last_check) {
270 DCHECK(thread_checker_.CalledOnValidThread()); 229 DCHECK(thread_checker_.CalledOnValidThread());
271 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck); 230 DictionaryPrefUpdate dict(local_state_, prefs::kQuirksClientLastServerCheck);
272 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT()); 231 dict->SetDouble(IdToHexString(product_id), last_check.ToDoubleT());
273 } 232 }
274 233
275 } // namespace quirks 234 } // namespace quirks
OLDNEW
« no previous file with comments | « components/quirks/quirks_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698