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/command_line.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chromeos/login/users/user_manager.h"
11 #include "chromeos/chromeos_switches.h"
12 #include "chromeos/network/network_handler.h"
13 #include "chromeos/network/network_state.h"
14 #include "chromeos/network/network_state_handler.h"
15 #include "google_apis/gaia/gaia_auth_util.h"
16 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image_skia.h"
22 #include "ui/gfx/screen.h"
26 gfx::Rect CalculateScreenBounds(const gfx::Size& size) {
27 gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds());
28 if (!size.IsEmpty()) {
29 int horizontal_diff = bounds.width() - size.width();
30 int vertical_diff = bounds.height() - size.height();
31 bounds.Inset(horizontal_diff / 2, vertical_diff / 2);
36 int GetCurrentUserImageSize() {
37 // The biggest size that the profile picture is displayed at is currently
38 // 220px, used for the big preview on OOBE and Change Picture options page.
39 static const int kBaseUserImageSize = 220;
40 float scale_factor = gfx::Display::GetForcedDeviceScaleFactor();
41 if (scale_factor > 1.0f)
42 return static_cast<int>(scale_factor * kBaseUserImageSize);
43 return kBaseUserImageSize * gfx::ImageSkia::GetMaxSupportedScale();
48 std::string CanonicalizeUserID(const std::string& user_id) {
49 if (user_id == UserManager::kGuestUserName)
51 return gaia::CanonicalizeEmail(user_id);
54 bool LoginScrollIntoViewEnabled() {
55 return !CommandLine::ForCurrentProcess()->HasSwitch(
56 chromeos::switches::kDisableLoginScrollIntoView);
59 NetworkStateHelper::NetworkStateHelper() {}
60 NetworkStateHelper::~NetworkStateHelper() {}
62 base::string16 NetworkStateHelper::GetCurrentNetworkName() const {
63 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
64 const NetworkState* network =
65 nsh->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
67 if (network->Matches(NetworkTypePattern::Ethernet()))
68 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
69 return base::UTF8ToUTF16(network->name());
72 network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual());
74 if (network->Matches(NetworkTypePattern::Ethernet()))
75 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
76 return base::UTF8ToUTF16(network->name());
78 return base::string16();
81 bool NetworkStateHelper::IsConnected() const {
82 chromeos::NetworkStateHandler* nsh =
83 chromeos::NetworkHandler::Get()->network_state_handler();
84 return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) !=
88 bool NetworkStateHelper::IsConnecting() const {
89 chromeos::NetworkStateHandler* nsh =
90 chromeos::NetworkHandler::Get()->network_state_handler();
91 return nsh->ConnectingNetworkByType(
92 chromeos::NetworkTypePattern::Default()) != NULL;
97 } // namespace chromeos