Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/net/client_hints.h" | |
| 6 | |
| 7 #include "base/stringprintf.h" | |
| 8 #include "content/public/browser/browser_thread.h" | |
| 9 #include "ui/gfx/screen.h" | |
| 10 | |
| 11 using content::BrowserThread; | |
| 12 | |
| 13 ClientHints::ClientHints() : screen_hints_("") { | |
| 14 } | |
| 15 | |
| 16 ClientHints::~ClientHints() { | |
| 17 } | |
| 18 | |
| 19 bool ClientHints::RetrieveScreenInfo() { | |
| 20 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 21 return BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 22 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
| |
| 23 } | |
| 24 | |
| 25 std::string ClientHints::GetScreenInfoHints() { | |
| 26 return screen_hints_; | |
| 27 } | |
| 28 | |
| 29 void ClientHints::FetchScreenInfoOnUIThread() { | |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 31 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
| 32 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 33 base::Bind(&ClientHints::UpdateScreenInfo, this, | |
| 34 display.GetSizeInPixel().width(), | |
| 35 display.GetSizeInPixel().height(), | |
| 36 display.device_scale_factor())); | |
| 37 } | |
| 38 | |
| 39 void ClientHints::UpdateScreenInfo(int width, int height, | |
| 40 float device_pixel_ratio) { | |
| 41 screen_hints_ = base::StringPrintf("dh=%d, dw=%d, dpr=%0.3g", | |
| 42 height, width, device_pixel_ratio); | |
| 43 } | |
| 44 | |
| OLD | NEW |