Index: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
diff --git a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
index 39dedd72a6c594cf47d4bfc1f7607cefb57bfdbd..a7e87ab9b844f57c2ba0a4ecaec812b9de376925 100644 |
--- a/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
+++ b/third_party/WebKit/Source/core/loader/FrameFetchContext.cpp |
@@ -606,6 +606,20 @@ void FrameFetchContext::ModifyRequestForCSP(ResourceRequest& resource_request) { |
GetFrame()->Loader().ModifyRequestForCSP(resource_request, GetDocument()); |
} |
+float FrameFetchContext::ClientHintsDeviceRam(int physical_memory_mb) { |
panicker
2017/05/24 17:27:20
let's add a comment that this math with change and
fmeawad
2017/05/24 18:24:57
Done.
|
+ // The reported device-ram is rounded down to next power of 2 in GB. Ex. |
+ // 3072MB will return 2, and 768MB will return 0.5. |
+ DCHECK_GT(physical_memory_mb, 0); |
+ int power = -1; |
Yoav Weiss
2017/05/24 07:48:02
I find the MSB counting here a bit confusing. Mayb
fmeawad
2017/05/24 18:24:57
The loop does an extra iteration, to compensate, w
|
+ // Extract the MSB location. |
+ while (physical_memory_mb != 0) { |
+ physical_memory_mb = physical_memory_mb >> 1; |
Yoav Weiss
2017/05/24 07:48:02
Nit: "physical_memory_mb >>= 1;" might be a bit cl
fmeawad
2017/05/24 18:24:56
Done.
|
+ power++; |
+ } |
+ // Restore to the power of 2, and convert to GB. |
+ return ((1 << power) / 1024.0); |
Yoav Weiss
2017/05/24 07:48:02
Implicit conversion from int to float... Can you m
fmeawad
2017/05/24 18:24:56
Done.
|
+} |
+ |
void FrameFetchContext::AddClientHintsIfNecessary( |
const ClientHintsPreferences& hints_preferences, |
const FetchParameters::ResourceWidth& resource_width, |
@@ -613,6 +627,9 @@ void FrameFetchContext::AddClientHintsIfNecessary( |
if (!RuntimeEnabledFeatures::clientHintsEnabled() || !GetDocument()) |
return; |
+ bool should_send_device_ram = |
+ GetDocument()->GetClientHintsPreferences().ShouldSendDeviceRam() || |
+ hints_preferences.ShouldSendDeviceRam(); |
bool should_send_dpr = |
GetDocument()->GetClientHintsPreferences().ShouldSendDPR() || |
hints_preferences.ShouldSendDPR(); |
@@ -623,6 +640,13 @@ void FrameFetchContext::AddClientHintsIfNecessary( |
GetDocument()->GetClientHintsPreferences().ShouldSendViewportWidth() || |
hints_preferences.ShouldSendViewportWidth(); |
+ if (should_send_device_ram) { |
+ int physical_memory = Platform::Current()->AmountOfPhysicalMemoryMB(); |
+ request.AddHTTPHeaderField( |
+ "device-ram", |
+ AtomicString(String::Number(ClientHintsDeviceRam(physical_memory)))); |
+ } |
+ |
if (should_send_dpr) { |
request.AddHTTPHeaderField( |
"DPR", AtomicString(String::Number(GetDocument()->DevicePixelRatio()))); |