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

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

Issue 11970002: Added Client-Hints. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Made float literals explicit in tests Created 7 years, 9 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..c9916b64dcab0a74e7452b27fa265346174b0c08
--- /dev/null
+++ b/chrome/browser/net/client_hints.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2012 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/stringprintf.h"
+#include "content/public/browser/browser_thread.h"
+#include "ui/gfx/screen.h"
+
+namespace {
+
+void FetchScreenInfoOnUIThread(ClientHints::ScreenInfo* info) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
+ info->width = display.GetSizeInPixel().width();
+ info->height = display.GetSizeInPixel().height();
+ info->pixel_ratio = display.device_scale_factor();
+}
+
+} // namespace
+
+ClientHints::ClientHints() :
+ weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+}
+
+ClientHints::~ClientHints() {
+}
+
+void ClientHints::Init() {
+ RetrieveScreenInfo();
+}
+
+bool ClientHints::RetrieveScreenInfo() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+ ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo();
+ return content::BrowserThread::PostTaskAndReply(
+ content::BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&FetchScreenInfoOnUIThread, info),
+ base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(info)));
+}
+
+const std::string& ClientHints::GetScreenInfoHints() {
+ return screen_hints_;
+}
+
+void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) {
+ if (info->height > 0 && info->width > 0 && info->pixel_ratio > 0.0) {
+ screen_hints_ = base::StringPrintf(
+ "dh=%d, dw=%d, dpr=%0.3g",
+ info->height, info->width, info->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