Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/helper.h" | 5 #include "chrome/browser/chromeos/login/helper.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | 9 #include "chromeos/network/network_handler.h" |
| 10 #include "chromeos/network/network_state.h" | |
| 11 #include "chromeos/network/network_state_handler.h" | |
| 10 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 11 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
| 12 #include "third_party/cros_system_api/dbus/service_constants.h" | 14 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 16 | 18 |
| 17 namespace chromeos { | 19 namespace chromeos { |
| 18 | 20 |
| 19 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { | 21 gfx::Rect CalculateScreenBounds(const gfx::Size& size) { |
| 20 gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds()); | 22 gfx::Rect bounds(ash::Shell::GetScreen()->GetPrimaryDisplay().bounds()); |
| 21 if (!size.IsEmpty()) { | 23 if (!size.IsEmpty()) { |
| 22 int horizontal_diff = bounds.width() - size.width(); | 24 int horizontal_diff = bounds.width() - size.width(); |
| 23 int vertical_diff = bounds.height() - size.height(); | 25 int vertical_diff = bounds.height() - size.height(); |
| 24 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); | 26 bounds.Inset(horizontal_diff / 2, vertical_diff / 2); |
| 25 } | 27 } |
| 26 return bounds; | 28 return bounds; |
| 27 } | 29 } |
| 28 | 30 |
| 29 string16 GetCurrentNetworkName() { | |
| 30 ConnectivityStateHelper* csh = | |
| 31 ConnectivityStateHelper::Get(); | |
| 32 | |
| 33 if (csh->IsConnectedType(flimflam::kTypeEthernet)) { | |
| 34 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
| 35 } else if (csh->IsConnectedType(flimflam::kTypeWifi)) { | |
| 36 return UTF8ToUTF16(csh->NetworkNameForType(flimflam::kTypeWifi)); | |
| 37 } else if (csh->IsConnectedType(flimflam::kTypeCellular)) { | |
| 38 return UTF8ToUTF16(csh->NetworkNameForType(flimflam::kTypeCellular)); | |
| 39 } else if (csh->IsConnectedType(flimflam::kTypeWimax)) { | |
| 40 return UTF8ToUTF16(csh->NetworkNameForType(flimflam::kTypeWimax)); | |
| 41 } else if (csh->IsConnectingType(flimflam::kTypeEthernet)) { | |
| 42 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
| 43 } else if (csh->IsConnectingType(flimflam::kTypeWifi)) { | |
| 44 return UTF8ToUTF16(csh->NetworkNameForType(flimflam::kTypeWifi)); | |
| 45 } else if (csh->IsConnectingType(flimflam::kTypeCellular)) { | |
| 46 return UTF8ToUTF16(csh->NetworkNameForType(flimflam::kTypeCellular)); | |
| 47 } else if (csh->IsConnectingType(flimflam::kTypeWimax)) { | |
| 48 return UTF8ToUTF16(csh->NetworkNameForType(flimflam::kTypeWimax)); | |
| 49 } else { | |
| 50 return string16(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 int GetCurrentUserImageSize() { | 31 int GetCurrentUserImageSize() { |
| 55 // The biggest size that the profile picture is displayed at is currently | 32 // The biggest size that the profile picture is displayed at is currently |
| 56 // 220px, used for the big preview on OOBE and Change Picture options page. | 33 // 220px, used for the big preview on OOBE and Change Picture options page. |
| 57 static const int kBaseUserImageSize = 220; | 34 static const int kBaseUserImageSize = 220; |
| 58 float scale_factor = gfx::Display::GetForcedDeviceScaleFactor(); | 35 float scale_factor = gfx::Display::GetForcedDeviceScaleFactor(); |
| 59 if (scale_factor > 1.0f) | 36 if (scale_factor > 1.0f) |
| 60 return static_cast<int>(scale_factor * kBaseUserImageSize); | 37 return static_cast<int>(scale_factor * kBaseUserImageSize); |
| 61 return kBaseUserImageSize * | 38 return kBaseUserImageSize * |
| 62 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); | 39 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); |
| 63 } | 40 } |
| 64 | 41 |
| 42 namespace login { | |
| 43 | |
| 44 NetworkStateHelper::NetworkStateHelper() {} | |
| 45 NetworkStateHelper::~NetworkStateHelper() {} | |
| 46 | |
| 47 string16 NetworkStateHelper::GetCurrentNetworkName() const { | |
| 48 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); | |
| 49 const NetworkState* network = NULL; | |
| 50 | |
| 51 if (nsh->ConnectedNetworkByType(flimflam::kTypeEthernet)) { | |
| 52 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
| 53 } else if ((network = nsh->ConnectedNetworkByType(flimflam::kTypeWifi))) { | |
| 54 return UTF8ToUTF16(network->name()); | |
| 55 } else if ((network = nsh->ConnectedNetworkByType(flimflam::kTypeCellular))) { | |
| 56 return UTF8ToUTF16(network->name()); | |
| 57 } else if ((network = nsh->ConnectedNetworkByType(flimflam::kTypeWimax))) { | |
| 58 return UTF8ToUTF16(network->name()); | |
|
stevenjb
2013/08/07 01:43:27
I believe the above 4 could be replaced by a singl
gauravsh
2013/08/07 17:28:19
Done.
| |
| 59 } else if ((network = nsh->ConnectingNetworkByType( | |
| 60 flimflam::kTypeEthernet))) { | |
| 61 return l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); | |
| 62 } else if ((network = nsh->ConnectingNetworkByType(flimflam::kTypeWifi))) { | |
| 63 return UTF8ToUTF16(network->name()); | |
| 64 } else if ((network = nsh->ConnectingNetworkByType( | |
| 65 flimflam::kTypeCellular))) { | |
| 66 return UTF8ToUTF16(network->name()); | |
| 67 } else if ((network = nsh->ConnectingNetworkByType(flimflam::kTypeWimax))) { | |
| 68 return UTF8ToUTF16(network->name()); | |
|
stevenjb
2013/08/07 01:43:27
Ditto for Connecting
gauravsh
2013/08/07 17:28:19
Done.
| |
| 69 } else { | |
| 70 return string16(); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 bool NetworkStateHelper::IsConnected() const { | |
| 75 chromeos::NetworkStateHandler* nsh = | |
| 76 chromeos::NetworkHandler::Get()->network_state_handler(); | |
| 77 return nsh->ConnectedNetworkByType( | |
| 78 chromeos::NetworkStateHandler::kMatchTypeDefault) != NULL; | |
| 79 } | |
| 80 | |
| 81 bool NetworkStateHelper::IsConnecting() const { | |
| 82 chromeos::NetworkStateHandler* nsh = | |
| 83 chromeos::NetworkHandler::Get()->network_state_handler(); | |
| 84 return nsh->ConnectingNetworkByType( | |
| 85 chromeos::NetworkStateHandler::kMatchTypeDefault) != NULL; | |
| 86 } | |
| 87 | |
| 88 } // namespace login | |
| 89 | |
| 65 } // namespace chromeos | 90 } // namespace chromeos |
| OLD | NEW |