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

Side by Side Diff: chrome/browser/precache/precache_util.cc

Issue 2061303003: Precache should cancel when there is user traffic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: restructured Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/precache/precache_util.h"
6
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/precache/precache_manager_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "components/data_use_measurement/content/data_use_measurement.h"
12 #include "components/precache/content/precache_manager.h"
13 #include "content/public/browser/browser_thread.h"
14
15 namespace precache {
16
17 void PrecacheUtil::UpdatePrecacheMetricsAndState(const net::URLRequest* request,
bengr 2016/06/20 20:21:14 There should be unit tests for these methods.
Raj 2016/06/30 06:03:08 I am trying to add tests. But looks little complic
bengr 2016/07/08 16:54:22 If the functions this uses have unit tests, then j
Raj 2016/07/08 20:05:49 Done.
18 void* profile_id) {
19 // For better accuracy, we use the actual bytes read instead of the length
20 // specified with the Content-Length header, which may be inaccurate,
21 // or missing, as is the case with chunked encoding.
22 int64_t received_content_length = request->received_response_content_length();
23 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time();
24
25 // Record precache metrics when a fetch is completed successfully, if
26 // precaching is allowed.
27 content::BrowserThread::PostTask(
28 content::BrowserThread::UI, FROM_HERE,
29 base::Bind(
30 &PrecacheUtil::UpdatePrecacheMetricsAndStateOnUIThread,
31 request->url(), GURL(request->referrer()), latency, base::Time::Now(),
32 received_content_length, request->was_cached(),
33 data_use_measurement::DataUseMeasurement::IsUserTraffic(request),
34 profile_id));
35 }
36
37 void PrecacheUtil::UpdatePrecacheMetricsAndStateOnUIThread(
bengr 2016/06/20 20:21:14 Can this method be in an anonymous namespace in th
Raj 2016/06/30 06:03:08 Done.
38 const GURL& url,
39 const GURL& referrer,
40 base::TimeDelta latency,
41 const base::Time& fetch_time,
42 int64_t size,
43 bool was_cached,
44 bool is_user_traffic,
45 void* profile_id) {
46 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
47
48 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id))
49 return;
50 Profile* profile = reinterpret_cast<Profile*>(profile_id);
51
52 PrecacheManager* precache_manager =
53 precache::PrecacheManagerFactory::GetForBrowserContext(profile);
54 // |precache_manager| could be NULL if the profile is off the record.
55 if (!precache_manager || !precache_manager->IsPrecachingAllowed())
56 return;
57
58 precache_manager->UpdatePrecacheMetricsAndState(
59 url, referrer, latency, fetch_time, size, was_cached, is_user_traffic);
60 }
61
62 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698