Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/net/client_hints.cc

Issue 11970002: Added Client-Hints. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Changed ClientHints to use WeakPtr and addressed comments Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/bind.h"
8 #include "base/stringprintf.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "ui/gfx/screen.h"
11
12 using base::Bind;
13 using content::BrowserThread;
Ryan Sleevi 2013/02/26 02:21:04 These are generally discouraged except when they m
bengr 2013/02/26 18:19:53 Done.
14
15 namespace {
16 typedef base::Callback<void(int, int, float)> ClientHintsCallback;
Ryan Sleevi 2013/02/26 02:21:04 nit: Unused
bengr 2013/02/26 18:19:53 Done.
17
18 void FetchScreenInfoOnUIThread(ClientHints::ScreenInfo* info) {
19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
20 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
21 info->width = display.GetSizeInPixel().width();
22 info->height = display.GetSizeInPixel().height();
23 info->pixel_ratio = display.device_scale_factor();
24 }
25 } // namespace
26
27 ClientHints::ClientHints() : screen_hints_(""), weak_ptr_factory_(this) {
28 }
29
30 ClientHints::~ClientHints() {
31 }
32
33 bool ClientHints::RetrieveScreenInfo() {
34 ClientHints::ScreenInfo* info = new ClientHints::ScreenInfo();
35 return BrowserThread::PostTaskAndReply(
36 BrowserThread::UI,
37 FROM_HERE,
38 Bind(&FetchScreenInfoOnUIThread, info),
39 Bind(&ClientHints::UpdateScreenInfo, weak_ptr_factory_.GetWeakPtr(),
40 base::Owned(info)));
41 }
42
43 std::string ClientHints::GetScreenInfoHints() {
44 return screen_hints_;
45 }
46
47 void ClientHints::UpdateScreenInfo(ClientHints::ScreenInfo* info) {
48 screen_hints_ = base::StringPrintf(
49 "dh=%d, dw=%d, dpr=%0.3g", info->height, info->width, info->pixel_ratio);
50 }
51
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698