Chromium Code Reviews| 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..7b9e23f057081b7ac2b9e24f9174605f0ad96473 |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints.cc |
| @@ -0,0 +1,61 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
bengr
2013/09/11 16:32:36
2013, remove (c)
|
| +// 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/strings/stringprintf.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "ui/gfx/screen.h" |
| + |
| +namespace { |
| + |
| +void FetchScreenInfoOnUIThread(ClientHints::ScreenInfo* info) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + 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
|
| + info->pixel_ratio = display.device_scale_factor(); |
| +} |
| + |
| +} // namespace |
| + |
| +ClientHints::ClientHints() |
| + : weak_ptr_factory_(this) { |
|
mmenke
2013/09/09 16:55:30
nit: 4 space indent (Or put this on the previous
|
| +} |
| + |
| +ClientHints::~ClientHints() { |
| +} |
| + |
| +void ClientHints::Init() { |
| + RetrieveScreenInfo(); |
| +} |
| + |
| +bool ClientHints::RetrieveScreenInfo() { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| + ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo(); |
| + return content::BrowserThread::PostTaskAndReply( |
| + content::BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&FetchScreenInfoOnUIThread, info), |
| + base::Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(), |
| + base::Owned(info))); |
| +} |
| + |
| +const std::string& ClientHints::GetScreenInfoHints() { |
| + 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.
|
| +} |
| + |
| +void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) { |
|
bengr
2013/09/11 16:32:36
It doesn't look like info is being modified. If yo
|
| + if (info->pixel_ratio > 0.0) { |
| + std::string pixel_ratio = base::StringPrintf("%.2f", info->pixel_ratio); |
| + // 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"
|
| + std::locale locale; |
| + for (std::string::iterator it = pixel_ratio.begin(); |
| + it != pixel_ratio.end(); |
| + 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
|
| + if (!std::isdigit(*it, locale)) |
| + *it = '.'; |
| + screen_hints_ = std::string("dpr=") + pixel_ratio; |
| + } |
| +} |
| + |