OLD | NEW |
---|---|
(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() : screen_hints_(""), weak_ptr_factory_(this) { | |
Ryan Sleevi
2013/02/26 18:26:16
You will need to rewrite this (to suppress an MSVC
bengr
2013/02/26 18:41:16
Done.
| |
25 } | |
26 | |
27 ClientHints::~ClientHints() { | |
28 } | |
29 | |
30 bool ClientHints::RetrieveScreenInfo() { | |
Ryan Sleevi
2013/02/26 18:26:16
DCHECK(content::BrowserThread::CurrentlyOn(content
bengr
2013/02/26 18:41:16
Done.
| |
31 ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo(); | |
32 return content::BrowserThread::PostTaskAndReply( | |
33 content::BrowserThread::UI, | |
34 FROM_HERE, | |
35 base::Bind(&FetchScreenInfoOnUIThread, info), | |
36 base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(), | |
37 base::Owned(info))); | |
Ryan Sleevi
2013/02/26 18:26:16
nit: indent to (, following function-call indentin
bengr
2013/02/26 18:41:16
Done.
| |
38 } | |
39 | |
40 std::string ClientHints::GetScreenInfoHints() { | |
41 return screen_hints_; | |
42 } | |
43 | |
44 void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) { | |
45 if (info->height > 0 && info->width > 0 && info->pixel_ratio > 0.0) | |
Ryan Sleevi
2013/02/26 18:26:16
nit: braces here, for a multi-line body (even if i
bengr
2013/02/26 18:41:16
Done.
| |
46 screen_hints_ = base::StringPrintf( | |
47 "dh=%d, dw=%d, dpr=%0.3g", | |
48 info->height, info->width, info->pixel_ratio); | |
49 } | |
50 | |
OLD | NEW |