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

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: Changed ClientHints to use WeakPtr and addressed comments Created 7 years, 10 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
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..1a4a3aa735714837ef582e39fcb3670aa640781f
--- /dev/null
+++ b/chrome/browser/net/client_hints.cc
@@ -0,0 +1,51 @@
+// 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"
+
+using base::Bind;
+using content::BrowserThread;
Ryan Sleevi 2013/02/26 02:21:04 These are generally discouraged except when they m
bengr 2013/02/26 18:19:53 Done.
+
+namespace {
+typedef base::Callback<void(int, int, float)> ClientHintsCallback;
Ryan Sleevi 2013/02/26 02:21:04 nit: Unused
bengr 2013/02/26 18:19:53 Done.
+
+void FetchScreenInfoOnUIThread(ClientHints::ScreenInfo* info) {
+ DCHECK(BrowserThread::CurrentlyOn(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() : screen_hints_(""), weak_ptr_factory_(this) {
+}
+
+ClientHints::~ClientHints() {
+}
+
+bool ClientHints::RetrieveScreenInfo() {
+ ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo();
+ return BrowserThread::PostTaskAndReply(
+ BrowserThread::UI,
+ FROM_HERE,
+ Bind(&FetchScreenInfoOnUIThread, info),
+ Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(info)));
+}
+
+std::string ClientHints::GetScreenInfoHints() {
+ return screen_hints_;
+}
+
+void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) {
+ screen_hints_ = base::StringPrintf(
+ "dh=%d, dw=%d, dpr=%0.3g", info->height, info->width, info->pixel_ratio);
+}
+

Powered by Google App Engine
This is Rietveld 408576698