Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 { | |
| 16 | |
| 17 void UpdatePrecacheMetricsAndStateOnUIThread(const GURL& url, | |
| 18 const GURL& referrer, | |
| 19 base::TimeDelta latency, | |
| 20 const base::Time& fetch_time, | |
| 21 int64_t size, | |
| 22 bool was_cached, | |
| 23 bool is_user_traffic, | |
| 24 void* profile_id) { | |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 26 | |
| 27 if (!g_browser_process->profile_manager()->IsValidProfile(profile_id)) | |
| 28 return; | |
| 29 Profile* profile = reinterpret_cast<Profile*>(profile_id); | |
| 30 | |
| 31 precache::PrecacheManager* precache_manager = | |
| 32 precache::PrecacheManagerFactory::GetForBrowserContext(profile); | |
| 33 // |precache_manager| could be NULL if the profile is off the record. | |
| 34 if (!precache_manager || !precache_manager->IsPrecachingAllowed()) | |
| 35 return; | |
| 36 | |
| 37 precache_manager->UpdatePrecacheMetricsAndState( | |
| 38 url, referrer, latency, fetch_time, size, was_cached, is_user_traffic); | |
| 39 } | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 namespace precache { | |
| 44 | |
| 45 // TODO(rajendrant): Add unittests for this function. | |
| 46 void UpdatePrecacheMetricsAndState(const net::URLRequest* request, | |
|
bengr
2016/07/06 17:04:27
#include url_request.h
Raj
2016/07/06 18:28:23
Done.
| |
| 47 void* profile_id) { | |
|
bengr
2016/07/06 17:04:27
You should probably DCHECK_CURRENTLY_ON(content::B
Raj
2016/07/06 18:28:23
Done.
| |
| 48 // For better accuracy, we use the actual bytes read instead of the length | |
| 49 // specified with the Content-Length header, which may be inaccurate, | |
| 50 // or missing, as is the case with chunked encoding. | |
| 51 int64_t received_content_length = request->received_response_content_length(); | |
| 52 base::TimeDelta latency = base::TimeTicks::Now() - request->creation_time(); | |
|
bengr
2016/07/06 17:04:27
#include time.h
Raj
2016/07/06 18:28:22
Done.
| |
| 53 | |
| 54 // Record precache metrics when a fetch is completed successfully, if | |
| 55 // precaching is allowed. | |
| 56 content::BrowserThread::PostTask( | |
| 57 content::BrowserThread::UI, FROM_HERE, | |
| 58 base::Bind( | |
| 59 &UpdatePrecacheMetricsAndStateOnUIThread, request->url(), | |
| 60 GURL(request->referrer()), latency, base::Time::Now(), | |
|
bengr
2016/07/06 17:04:27
#include gurl.h
Raj
2016/07/06 18:28:22
Done.
| |
| 61 received_content_length, request->was_cached(), | |
| 62 data_use_measurement::DataUseMeasurement::IsUserTraffic(request), | |
| 63 profile_id)); | |
| 64 } | |
| 65 | |
| 66 } // namespace precache | |
| OLD | NEW |