OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
bengr
2013/09/11 16:32:36
2013, remove (c)
| |
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/strings/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(); | |
Nicholas Shanks
2013/09/11 10:22:46
Should this not be using the display that (the maj
bengr
2013/09/11 16:32:36
This should really be the dpi of the device where
| |
17 info->pixel_ratio = display.device_scale_factor(); | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 ClientHints::ClientHints() | |
23 : weak_ptr_factory_(this) { | |
mmenke
2013/09/09 16:55:30
nit: 4 space indent (Or put this on the previous
| |
24 } | |
25 | |
26 ClientHints::~ClientHints() { | |
27 } | |
28 | |
29 void ClientHints::Init() { | |
30 RetrieveScreenInfo(); | |
31 } | |
32 | |
33 bool ClientHints::RetrieveScreenInfo() { | |
34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | |
35 ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo(); | |
36 return content::BrowserThread::PostTaskAndReply( | |
37 content::BrowserThread::UI, | |
38 FROM_HERE, | |
39 base::Bind(&FetchScreenInfoOnUIThread, info), | |
40 base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(), | |
41 base::Owned(info))); | |
42 } | |
43 | |
44 const std::string& ClientHints::GetScreenInfoHints() { | |
45 return screen_hints_; | |
Rik
2013/09/07 20:24:58
The screen_hints aren't updated if the devicePixel
bengr
2013/09/11 16:32:36
I think they should be.
| |
46 } | |
47 | |
48 void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) { | |
bengr
2013/09/11 16:32:36
It doesn't look like info is being modified. If yo
| |
49 if (info->pixel_ratio > 0.0) { | |
50 std::string pixel_ratio = base::StringPrintf("%.2f", info->pixel_ratio); | |
51 // Make sure CH value doesn't change according to the machine's locale | |
bengr
2013/09/11 16:32:36
nit: "sure the Client Hints value"
| |
52 std::locale locale; | |
53 for (std::string::iterator it = pixel_ratio.begin(); | |
54 it != pixel_ratio.end(); | |
55 it++) | |
mmenke
2013/09/09 16:55:30
nit: These should be aligned with the "std" of th
mmenke
2013/09/09 16:55:30
Iterators should use pre-increments, for efficienc
| |
56 if (!std::isdigit(*it, locale)) | |
57 *it = '.'; | |
58 screen_hints_ = std::string("dpr=") + pixel_ratio; | |
59 } | |
60 } | |
61 | |
OLD | NEW |