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.
5 #include "chrome/browser/chromeos/login/helper.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chromeos/network/network_handler.h"
10 #include "chromeos/network/network_state.h"
11 #include "chromeos/network/network_state_handler.h"
12 #include "chromeos/network/shill_property_util.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "third_party/cros_system_api/dbus/service_constants.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/screen.h"
23 gfx::Rect
CalculateScreenBounds(const gfx::Size
& size
) {
24 gfx::Rect
bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds());
25 if (!size
.IsEmpty()) {
26 int horizontal_diff
= bounds
.width() - size
.width();
27 int vertical_diff
= bounds
.height() - size
.height();
28 bounds
.Inset(horizontal_diff
/ 2, vertical_diff
/ 2);
33 int GetCurrentUserImageSize() {
34 // The biggest size that the profile picture is displayed at is currently
35 // 220px, used for the big preview on OOBE and Change Picture options page.
36 static const int kBaseUserImageSize
= 220;
37 float scale_factor
= gfx::Display::GetForcedDeviceScaleFactor();
38 if (scale_factor
> 1.0f
)
39 return static_cast<int>(scale_factor
* kBaseUserImageSize
);
40 return kBaseUserImageSize
* gfx::ImageSkia::GetMaxSupportedScale();
45 NetworkStateHelper::NetworkStateHelper() {}
46 NetworkStateHelper::~NetworkStateHelper() {}
48 base::string16
NetworkStateHelper::GetCurrentNetworkName() const {
49 NetworkStateHandler
* nsh
= NetworkHandler::Get()->network_state_handler();
50 const NetworkState
* network
=
51 nsh
->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
53 if (network
->Matches(NetworkTypePattern::Ethernet()))
54 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET
);
55 return base::UTF8ToUTF16(network
->name());
58 network
= nsh
->ConnectingNetworkByType(NetworkTypePattern::NonVirtual());
60 if (network
->Matches(NetworkTypePattern::Ethernet()))
61 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET
);
62 return base::UTF8ToUTF16(network
->name());
64 return base::string16();
67 bool NetworkStateHelper::IsConnected() const {
68 chromeos::NetworkStateHandler
* nsh
=
69 chromeos::NetworkHandler::Get()->network_state_handler();
70 return nsh
->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) !=
74 bool NetworkStateHelper::IsConnecting() const {
75 chromeos::NetworkStateHandler
* nsh
=
76 chromeos::NetworkHandler::Get()->network_state_handler();
77 return nsh
->ConnectingNetworkByType(
78 chromeos::NetworkTypePattern::Default()) != NULL
;
83 } // namespace chromeos