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

Unified Diff: chrome/browser/net/client_hints.cc

Issue 23654014: Updated Client-Hints patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed issues raised in review by mmenke and bengr Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/client_hints.h ('k') | chrome/browser/net/client_hints_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/client_hints.cc
diff --git a/chrome/browser/net/client_hints.cc b/chrome/browser/net/client_hints.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a4c0ac6b9950c0208485d66fb7a76f9e3f4786cb
--- /dev/null
+++ b/chrome/browser/net/client_hints.cc
@@ -0,0 +1,62 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/net/client_hints.h"
+
+#include "base/bind.h"
+#include "base/strings/stringprintf.h"
+#include "content/public/browser/browser_thread.h"
+#include "ui/gfx/screen.h"
+
+namespace {
+
+void FetchScreenInfoOnUIThread(float* device_pixel_ratio) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
+ *device_pixel_ratio = display.device_scale_factor();
+}
+
+} // namespace
+
+ClientHints::ClientHints()
+ : weak_ptr_factory_(this) {
+}
+
+ClientHints::~ClientHints() {
+}
+
+void ClientHints::Init() {
+ RetrieveScreenInfo();
+}
+
+bool ClientHints::RetrieveScreenInfo() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ float* devicePixelRatio = new float;
+ return content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&FetchScreenInfoOnUIThread, devicePixelRatio),
+ base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(devicePixelRatio)));
+}
+
+const std::string& ClientHints::GetString() const {
+ return screen_hints_;
+}
+
+void ClientHints::UpdateScreenInfo(const float* device_pixel_ratio_value) {
+ if (device_pixel_ratio_value && *device_pixel_ratio_value > 0.0) {
+ std::string device_pixel_ratio = base::StringPrintf("%.2f",
+ *device_pixel_ratio_value);
+ // Make sure the Client Hints value doesn't change
+ // according to the machine's locale
+ std::locale locale;
+ for (std::string::iterator it = device_pixel_ratio.begin();
+ it != device_pixel_ratio.end(); ++it)
+ if (!std::isdigit(*it, locale))
+ *it = '.';
+ screen_hints_ = std::string("dpr=") + device_pixel_ratio;
+ }
+}
+
« no previous file with comments | « chrome/browser/net/client_hints.h ('k') | chrome/browser/net/client_hints_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698