• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/chromeos/login/helper.h"
6 
7 #include "ash/shell.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"
23 
24 namespace chromeos {
25 
CalculateScreenBounds(const gfx::Size & size)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);
32   }
33   return bounds;
34 }
35 
GetCurrentUserImageSize()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();
44 }
45 
46 namespace login {
47 
CanonicalizeUserID(const std::string & user_id)48 std::string CanonicalizeUserID(const std::string& user_id) {
49   if (user_id == UserManager::kGuestUserName)
50     return user_id;
51   return gaia::CanonicalizeEmail(user_id);
52 }
53 
LoginScrollIntoViewEnabled()54 bool LoginScrollIntoViewEnabled() {
55   return !CommandLine::ForCurrentProcess()->HasSwitch(
56       chromeos::switches::kDisableLoginScrollIntoView);
57 }
58 
NetworkStateHelper()59 NetworkStateHelper::NetworkStateHelper() {}
~NetworkStateHelper()60 NetworkStateHelper::~NetworkStateHelper() {}
61 
GetCurrentNetworkName() const62 base::string16 NetworkStateHelper::GetCurrentNetworkName() const {
63   NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler();
64   const NetworkState* network =
65       nsh->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
66   if (network) {
67     if (network->Matches(NetworkTypePattern::Ethernet()))
68       return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
69     return base::UTF8ToUTF16(network->name());
70   }
71 
72   network = nsh->ConnectingNetworkByType(NetworkTypePattern::NonVirtual());
73   if (network) {
74     if (network->Matches(NetworkTypePattern::Ethernet()))
75       return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
76     return base::UTF8ToUTF16(network->name());
77   }
78   return base::string16();
79 }
80 
IsConnected() const81 bool NetworkStateHelper::IsConnected() const {
82   chromeos::NetworkStateHandler* nsh =
83       chromeos::NetworkHandler::Get()->network_state_handler();
84   return nsh->ConnectedNetworkByType(chromeos::NetworkTypePattern::Default()) !=
85          NULL;
86 }
87 
IsConnecting() const88 bool NetworkStateHelper::IsConnecting() const {
89   chromeos::NetworkStateHandler* nsh =
90       chromeos::NetworkHandler::Get()->network_state_handler();
91   return nsh->ConnectingNetworkByType(
92       chromeos::NetworkTypePattern::Default()) != NULL;
93 }
94 
95 }  // namespace login
96 
97 }  // namespace chromeos
98