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

Side by Side 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: Addressed comments 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/net/client_hints.h"
6
7 #include "base/bind.h"
8 #include "base/stringprintf.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "ui/gfx/screen.h"
11
12 namespace {
13
14 void FetchScreenInfoOnUIThread(ClientHints::ScreenInfo* info) {
15 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
16 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
17 info->width = display.GetSizeInPixel().width();
18 info->height = display.GetSizeInPixel().height();
19 info->pixel_ratio = display.device_scale_factor();
20 }
21
22 } // namespace
23
24 ClientHints::ClientHints() :
25 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
26 }
27
28 ClientHints::~ClientHints() {
29 }
30
31 bool ClientHints::RetrieveScreenInfo() {
32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
33 ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo();
34 return content::BrowserThread::PostTaskAndReply(
35 content::BrowserThread::UI,
36 FROM_HERE,
37 base::Bind(&FetchScreenInfoOnUIThread, info),
38 base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(),
39 base::Owned(info)));
mmenke 2013/02/27 21:06:05 What if the user changes screen resolution?
bengr 2013/03/06 00:34:19 I presume that screen resolution changes are much
Ryan Sleevi 2013/03/06 00:38:19 Why isn't an orientation change considered a resol
40 }
41
42 std::string ClientHints::GetScreenInfoHints() {
mmenke 2013/02/27 21:06:05 optional: Could just make this return a const str
bengr 2013/03/06 00:34:19 Done.
43 return screen_hints_;
44 }
45
46 void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) {
47 if (info->height > 0 && info->width > 0 && info->pixel_ratio > 0.0) {
48 screen_hints_ = base::StringPrintf(
49 "dh=%d, dw=%d, dpr=%0.3g",
50 info->height, info->width, info->pixel_ratio);
51 }
52 }
53
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698