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

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContext.cpp

Issue 2860093003: Implement device-ram client hints header (Closed)
Patch Set: Created 3 years, 7 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
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 GetFrame()->Loader().ModifyRequestForCSP(resource_request, GetDocument()); 602 GetFrame()->Loader().ModifyRequestForCSP(resource_request, GetDocument());
603 } 603 }
604 604
605 void FrameFetchContext::AddClientHintsIfNecessary( 605 void FrameFetchContext::AddClientHintsIfNecessary(
606 const ClientHintsPreferences& hints_preferences, 606 const ClientHintsPreferences& hints_preferences,
607 const FetchParameters::ResourceWidth& resource_width, 607 const FetchParameters::ResourceWidth& resource_width,
608 ResourceRequest& request) { 608 ResourceRequest& request) {
609 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !GetDocument()) 609 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !GetDocument())
610 return; 610 return;
611 611
612 bool should_send_device_ram =
panicker 2017/05/05 17:19:30 also check if device-ram RunTimeFlagEnabled is en
fmeawad 2017/05/23 20:50:54 I don't think I need/should since ShouldSendDevice
613 GetDocument()->GetClientHintsPreferences().ShouldSendDeviceRam() ||
614 hints_preferences.ShouldSendDeviceRam();
612 bool should_send_dpr = 615 bool should_send_dpr =
613 GetDocument()->GetClientHintsPreferences().ShouldSendDPR() || 616 GetDocument()->GetClientHintsPreferences().ShouldSendDPR() ||
614 hints_preferences.ShouldSendDPR(); 617 hints_preferences.ShouldSendDPR();
615 bool should_send_resource_width = 618 bool should_send_resource_width =
616 GetDocument()->GetClientHintsPreferences().ShouldSendResourceWidth() || 619 GetDocument()->GetClientHintsPreferences().ShouldSendResourceWidth() ||
617 hints_preferences.ShouldSendResourceWidth(); 620 hints_preferences.ShouldSendResourceWidth();
618 bool should_send_viewport_width = 621 bool should_send_viewport_width =
619 GetDocument()->GetClientHintsPreferences().ShouldSendViewportWidth() || 622 GetDocument()->GetClientHintsPreferences().ShouldSendViewportWidth() ||
620 hints_preferences.ShouldSendViewportWidth(); 623 hints_preferences.ShouldSendViewportWidth();
621 624
625 if (should_send_device_ram) {
panicker 2017/05/05 17:19:30 Nit: extract this math into a helper Also makes un
fmeawad 2017/05/23 20:50:54 Done.
626 int physical_memory = Platform::Current()->AmountOfPhysicalMemoryMB();
627 int power = -1;
628 while (physical_memory != 0) {
629 physical_memory = physical_memory >> 1;
630 power++;
631 }
632 request.AddHTTPHeaderField(
633 "device-ram", AtomicString(String::Number((1 << power) / 1024.0)));
634 }
635
622 if (should_send_dpr) { 636 if (should_send_dpr) {
623 request.AddHTTPHeaderField( 637 request.AddHTTPHeaderField(
624 "DPR", AtomicString(String::Number(GetDocument()->DevicePixelRatio()))); 638 "DPR", AtomicString(String::Number(GetDocument()->DevicePixelRatio())));
625 } 639 }
626 640
627 if (should_send_resource_width) { 641 if (should_send_resource_width) {
628 if (resource_width.is_set) { 642 if (resource_width.is_set) {
629 float physical_width = 643 float physical_width =
630 resource_width.width * GetDocument()->DevicePixelRatio(); 644 resource_width.width * GetDocument()->DevicePixelRatio();
631 request.AddHTTPHeaderField( 645 request.AddHTTPHeaderField(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 std::unique_ptr<WebURLLoader> FrameFetchContext::CreateURLLoader() { 789 std::unique_ptr<WebURLLoader> FrameFetchContext::CreateURLLoader() {
776 return Platform::Current()->CreateURLLoader(); 790 return Platform::Current()->CreateURLLoader();
777 } 791 }
778 792
779 DEFINE_TRACE(FrameFetchContext) { 793 DEFINE_TRACE(FrameFetchContext) {
780 visitor->Trace(document_loader_); 794 visitor->Trace(document_loader_);
781 BaseFetchContext::Trace(visitor); 795 BaseFetchContext::Trace(visitor);
782 } 796 }
783 797
784 } // namespace blink 798 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698