| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/loader/fetch/ClientHintsPreferences.h" | 5 #include "platform/loader/fetch/ClientHintsPreferences.h" |
| 6 | 6 |
| 7 #include "platform/RuntimeEnabledFeatures.h" | 7 #include "platform/RuntimeEnabledFeatures.h" |
| 8 #include "platform/network/HTTPParsers.h" | 8 #include "platform/network/HTTPParsers.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 ClientHintsPreferences::ClientHintsPreferences() | 12 ClientHintsPreferences::ClientHintsPreferences() |
| 13 : should_send_dpr_(false), | 13 : should_send_device_ram_(false), |
| 14 should_send_dpr_(false), |
| 14 should_send_resource_width_(false), | 15 should_send_resource_width_(false), |
| 15 should_send_viewport_width_(false) {} | 16 should_send_viewport_width_(false) {} |
| 16 | 17 |
| 17 void ClientHintsPreferences::UpdateFrom( | 18 void ClientHintsPreferences::UpdateFrom( |
| 18 const ClientHintsPreferences& preferences) { | 19 const ClientHintsPreferences& preferences) { |
| 20 should_send_device_ram_ = preferences.should_send_device_ram_; |
| 19 should_send_dpr_ = preferences.should_send_dpr_; | 21 should_send_dpr_ = preferences.should_send_dpr_; |
| 20 should_send_resource_width_ = preferences.should_send_resource_width_; | 22 should_send_resource_width_ = preferences.should_send_resource_width_; |
| 21 should_send_viewport_width_ = preferences.should_send_viewport_width_; | 23 should_send_viewport_width_ = preferences.should_send_viewport_width_; |
| 22 } | 24 } |
| 23 | 25 |
| 24 void ClientHintsPreferences::UpdateFromAcceptClientHintsHeader( | 26 void ClientHintsPreferences::UpdateFromAcceptClientHintsHeader( |
| 25 const String& header_value, | 27 const String& header_value, |
| 26 Context* context) { | 28 Context* context) { |
| 27 if (!RuntimeEnabledFeatures::clientHintsEnabled() || header_value.IsEmpty()) | 29 if (!RuntimeEnabledFeatures::clientHintsEnabled() || header_value.IsEmpty()) |
| 28 return; | 30 return; |
| 29 | 31 |
| 30 CommaDelimitedHeaderSet accept_client_hints_header; | 32 CommaDelimitedHeaderSet accept_client_hints_header; |
| 31 ParseCommaDelimitedHeader(header_value, accept_client_hints_header); | 33 ParseCommaDelimitedHeader(header_value, accept_client_hints_header); |
| 34 if (RuntimeEnabledFeatures::deviceRAMHeaderEnabled() && |
| 35 accept_client_hints_header.Contains("device-ram")) { |
| 36 if (context) |
| 37 context->CountClientHintsDeviceRAM(); |
| 38 should_send_device_ram_ = true; |
| 39 } |
| 40 |
| 32 if (accept_client_hints_header.Contains("dpr")) { | 41 if (accept_client_hints_header.Contains("dpr")) { |
| 33 if (context) | 42 if (context) |
| 34 context->CountClientHintsDPR(); | 43 context->CountClientHintsDPR(); |
| 35 should_send_dpr_ = true; | 44 should_send_dpr_ = true; |
| 36 } | 45 } |
| 37 | 46 |
| 38 if (accept_client_hints_header.Contains("width")) { | 47 if (accept_client_hints_header.Contains("width")) { |
| 39 if (context) | 48 if (context) |
| 40 context->CountClientHintsResourceWidth(); | 49 context->CountClientHintsResourceWidth(); |
| 41 should_send_resource_width_ = true; | 50 should_send_resource_width_ = true; |
| 42 } | 51 } |
| 43 | 52 |
| 44 if (accept_client_hints_header.Contains("viewport-width")) { | 53 if (accept_client_hints_header.Contains("viewport-width")) { |
| 45 if (context) | 54 if (context) |
| 46 context->CountClientHintsViewportWidth(); | 55 context->CountClientHintsViewportWidth(); |
| 47 should_send_viewport_width_ = true; | 56 should_send_viewport_width_ = true; |
| 48 } | 57 } |
| 49 } | 58 } |
| 50 | 59 |
| 51 } // namespace blink | 60 } // namespace blink |
| OLD | NEW |