| 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..c9916b64dcab0a74e7452b27fa265346174b0c08
|
| --- /dev/null
|
| +++ b/chrome/browser/net/client_hints.cc
|
| @@ -0,0 +1,57 @@
|
| +// 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() {
|
| +}
|
| +
|
| +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_;
|
| +}
|
| +
|
| +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);
|
| + }
|
| +}
|
| +
|
|
|