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

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: 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 void ClientHints::Init() {
32 RetrieveScreenInfo();
33 }
34
35 bool ClientHints::RetrieveScreenInfo() {
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
37 ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo();
38 return content::BrowserThread::PostTaskAndReply(
39 content::BrowserThread::UI,
40 FROM_HERE,
41 base::Bind(&FetchScreenInfoOnUIThread, info),
42 base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(),
43 base::Owned(info)));
44 }
45
46 const std::string& ClientHints::GetScreenInfoHints() {
47 return screen_hints_;
48 }
49
50 void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) {
51 if (info->height > 0 && info->width > 0 && info->pixel_ratio > 0.0) {
52 screen_hints_ = base::StringPrintf(
53 "dh=%d, dw=%d, dpr=%0.3g",
54 info->height, info->width, info->pixel_ratio);
55 }
56 }
57
OLDNEW
« 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