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..4d500a133d3668f24f08f3f52bcdf329a0f888ad |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints.cc |
| @@ -0,0 +1,53 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// 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/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(); |
| + info->width = display.GetSizeInPixel().width(); |
| + info->height = display.GetSizeInPixel().height(); |
| + info->pixel_ratio = display.device_scale_factor(); |
| +} |
| + |
| +} // namespace |
| + |
| +ClientHints::ClientHints() : |
| + weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| +} |
| + |
| +ClientHints::~ClientHints() { |
| +} |
| + |
| +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))); |
|
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
|
| +} |
| + |
| +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.
|
| + return screen_hints_; |
| +} |
| + |
| +void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) { |
| + if (info->height > 0 && info->width > 0 && info->pixel_ratio > 0.0) { |
| + screen_hints_ = base::StringPrintf( |
| + "dh=%d, dw=%d, dpr=%0.3g", |
| + info->height, info->width, info->pixel_ratio); |
| + } |
| +} |
| + |