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..c3186dc35f564caee58685e66b29c3901556b8b3 |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints.cc |
| @@ -0,0 +1,50 @@ |
| +// 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() : 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.
|
| +} |
| + |
| +ClientHints::~ClientHints() { |
| +} |
| + |
| +bool ClientHints::RetrieveScreenInfo() { |
|
Ryan Sleevi
2013/02/26 18:26:16
DCHECK(content::BrowserThread::CurrentlyOn(content
bengr
2013/02/26 18:41:16
Done.
|
| + 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))); |
|
Ryan Sleevi
2013/02/26 18:26:16
nit: indent to (, following function-call indentin
bengr
2013/02/26 18:41:16
Done.
|
| +} |
| + |
| +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) |
|
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.
|
| + screen_hints_ = base::StringPrintf( |
| + "dh=%d, dw=%d, dpr=%0.3g", |
| + info->height, info->width, info->pixel_ratio); |
| +} |
| + |