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..553d93d44e7c3b181ba5b4fba8f39c2057443329 |
| --- /dev/null |
| +++ b/chrome/browser/net/client_hints.cc |
| @@ -0,0 +1,44 @@ |
| +// 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/stringprintf.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "ui/gfx/screen.h" |
| + |
| +using content::BrowserThread; |
| + |
| +ClientHints::ClientHints() : screen_hints_("") { |
| +} |
| + |
| +ClientHints::~ClientHints() { |
| +} |
| + |
| +bool ClientHints::RetrieveScreenInfo() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + return BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&ClientHints::FetchScreenInfoOnUIThread, this)); |
|
Ryan Sleevi
2013/02/08 22:12:53
For example:
namespace {
typedef base::Callback<v
bengr
2013/02/26 01:57:20
I couldn't get your suggestion to compile. I wound
|
| +} |
| + |
| +std::string ClientHints::GetScreenInfoHints() { |
| + return screen_hints_; |
| +} |
| + |
| +void ClientHints::FetchScreenInfoOnUIThread() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ClientHints::UpdateScreenInfo, this, |
| + display.GetSizeInPixel().width(), |
| + display.GetSizeInPixel().height(), |
| + display.device_scale_factor())); |
| +} |
| + |
| +void ClientHints::UpdateScreenInfo(int width, int height, |
| + float device_pixel_ratio) { |
| + screen_hints_ = base::StringPrintf("dh=%d, dw=%d, dpr=%0.3g", |
| + height, width, device_pixel_ratio); |
| +} |
| + |