1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include "ash/ash_switches.h"
#include "ash/desktop_background/desktop_background_controller.h"
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/session/session_state_delegate.h"
#include "ash/session/session_state_observer.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/shell_window_ids.h"
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/chromeos/session/logout_button_observer.h"
#include "ash/system/date/clock_observer.h"
#include "ash/system/ime/ime_observer.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray_accessibility.h"
#include "ash/system/user/login_status.h"
#include "ash/system/user/update_observer.h"
#include "ash/system/user/user_observer.h"
#include "ash/volume_control_delegate.h"
#include "ash/wm/lock_state_controller.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
#include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
#include "chrome/browser/chromeos/events/system_key_event_listener.h"
#include "chrome/browser/chromeos/input_method/input_method_switch_recorder.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/login/help_app_launcher.h"
#include "chrome/browser/chromeos/login/login_wizard.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/login/user_flow.h"
#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
#include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/set_time_dialog.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
#include "chrome/browser/ui/ash/user_accounts_delegate_chromeos.h"
#include "chrome/browser/ui/ash/volume_controller_chromeos.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/locale_settings.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h"
#include "chromeos/login/login_state.h"
#include "chromeos/network/portal_detector/network_portal_detector.h"
#include "components/google/core/browser/google_util.h"
#include "components/policy/core/common/cloud/cloud_policy_store.h"
#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "components/user_manager/user_type.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "device/bluetooth/bluetooth_adapter.h"
#include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/bluetooth_device.h"
#include "net/base/escape.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/base/ime/chromeos/extension_ime_util.h"
#include "ui/base/ime/chromeos/ime_keyboard.h"
#include "ui/base/ime/chromeos/input_method_manager.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "ui/chromeos/ime/input_method_menu_item.h"
#include "ui/chromeos/ime/input_method_menu_manager.h"
#if defined(ENABLE_SUPERVISED_USERS)
#include "chrome/browser/supervised_user/supervised_user_service.h"
#include "chrome/browser/supervised_user/supervised_user_service_factory.h"
#endif
namespace chromeos {
namespace {
// The minimum session length limit that can be set.
const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds.
// The maximum session length limit that can be set.
const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours.
const char kDisplaySettingsSubPageName[] = "display";
const char kDisplayOverscanSettingsSubPageName[] = "displayOverscan";
void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
const input_method::InputMethodUtil& util,
ash::IMEInfo* info) {
info->id = ime.id();
info->name = util.GetInputMethodLongName(ime);
info->medium_name = util.GetInputMethodMediumName(ime);
info->short_name = util.GetInputMethodShortName(ime);
info->third_party = extension_ime_util::IsExtensionIME(ime.id());
}
gfx::NativeWindow GetNativeWindowByStatus(ash::user::LoginStatus login_status,
bool session_started) {
bool isUserAddingRunning = ash::Shell::GetInstance()
->session_state_delegate()
->IsInSecondaryLoginScreen();
int container_id =
(!session_started || login_status == ash::user::LOGGED_IN_NONE ||
login_status == ash::user::LOGGED_IN_LOCKED || isUserAddingRunning)
? ash::kShellWindowId_LockSystemModalContainer
: ash::kShellWindowId_SystemModalContainer;
return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
container_id);
}
void BluetoothPowerFailure() {
// TODO(sad): Show an error bubble?
}
void BluetoothSetDiscoveringError() {
LOG(ERROR) << "BluetoothSetDiscovering failed.";
}
void BluetoothDeviceConnectError(
device::BluetoothDevice::ConnectErrorCode error_code) {
// TODO(sad): Do something?
}
void ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
chrome::ShowSettingsSubPageForProfile(
ProfileManager::GetActiveUserProfile(), sub_page);
}
void ShowNetworkSettingsPage(const std::string& service_path) {
std::string page = chrome::kInternetOptionsSubPage;
page += "?servicePath=" + net::EscapeUrlEncodedData(service_path, true);
content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog"));
ShowSettingsSubPageForActiveUser(page);
}
void OnAcceptMultiprofilesIntro(bool no_show_again) {
PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again);
UserAddingScreen::Get()->Start();
}
} // namespace
SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
: user_profile_(NULL),
clock_type_(base::GetHourClockType()),
search_key_mapped_to_(input_method::kSearchKey),
screen_locked_(false),
have_session_start_time_(false),
have_session_length_limit_(false),
should_run_bluetooth_discovery_(false),
session_started_(false),
volume_control_delegate_(new VolumeController()),
device_settings_observer_(CrosSettings::Get()->AddSettingsObserver(
kSystemUse24HourClock,
base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
base::Unretained(this)))),
weak_ptr_factory_(this) {
// Register notifications on construction so that events such as
// PROFILE_CREATED do not get missed if they happen before Initialize().
registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(this,
chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
content::NotificationService::AllSources());
registrar_->Add(this,
chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
content::NotificationService::AllSources());
if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) {
registrar_->Add(this,
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
}
registrar_->Add(this,
chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
registrar_->Add(this,
chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
registrar_->Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
CHECK(accessibility_manager);
accessibility_subscription_ = accessibility_manager->RegisterCallback(
base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged,
base::Unretained(this)));
user_manager::UserManager::Get()->AddSessionStateObserver(this);
}
void SystemTrayDelegateChromeOS::Initialize() {
DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
input_method::InputMethodManager::Get()->AddObserver(this);
ui::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
UpdateClockType();
device::BluetoothAdapterFactory::GetAdapter(
base::Bind(&SystemTrayDelegateChromeOS::InitializeOnAdapterReady,
weak_ptr_factory_.GetWeakPtr()));
ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(
this);
if (LoginState::IsInitialized())
LoginState::Get()->AddObserver(this);
if (CrasAudioHandler::IsInitialized())
CrasAudioHandler::Get()->AddAudioObserver(this);
BrowserList::AddObserver(this);
}
void SystemTrayDelegateChromeOS::Shutdown() {
device_settings_observer_.reset();
}
void SystemTrayDelegateChromeOS::InitializeOnAdapterReady(
scoped_refptr<device::BluetoothAdapter> adapter) {
bluetooth_adapter_ = adapter;
CHECK(bluetooth_adapter_.get());
bluetooth_adapter_->AddObserver(this);
local_state_registrar_.reset(new PrefChangeRegistrar);
local_state_registrar_->Init(g_browser_process->local_state());
UpdateSessionStartTime();
UpdateSessionLengthLimit();
local_state_registrar_->Add(
prefs::kSessionStartTime,
base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime,
base::Unretained(this)));
local_state_registrar_->Add(
prefs::kSessionLengthLimit,
base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit,
base::Unretained(this)));
policy::BrowserPolicyConnectorChromeOS* policy_connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
policy_connector->GetDeviceCloudPolicyManager();
if (policy_manager)
policy_manager->core()->store()->AddObserver(this);
UpdateEnterpriseDomain();
}
SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
// Unregister PrefChangeRegistrars.
local_state_registrar_.reset();
user_pref_registrar_.reset();
// Unregister content notifications before destroying any components.
registrar_.reset();
// Unregister a11y status subscription.
accessibility_subscription_.reset();
DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
input_method::InputMethodManager::Get()->RemoveObserver(this);
ui::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
bluetooth_adapter_->RemoveObserver(this);
ash::Shell::GetInstance()
->session_state_delegate()
->RemoveSessionStateObserver(this);
LoginState::Get()->RemoveObserver(this);
if (CrasAudioHandler::IsInitialized())
CrasAudioHandler::Get()->RemoveAudioObserver(this);
BrowserList::RemoveObserver(this);
StopObservingAppWindowRegistry();
StopObservingCustodianInfoChanges();
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
connector->GetDeviceCloudPolicyManager();
if (policy_manager)
policy_manager->core()->store()->RemoveObserver(this);
user_manager::UserManager::Get()->RemoveSessionStateObserver(this);
}
// Overridden from ash::SystemTrayDelegate:
bool SystemTrayDelegateChromeOS::GetTrayVisibilityOnStartup() {
// In case of OOBE / sign in screen tray will be shown later.
return LoginState::Get()->IsUserLoggedIn();
}
ash::user::LoginStatus SystemTrayDelegateChromeOS::GetUserLoginStatus() const {
// All non-logged in ChromeOS specific LOGGED_IN states map to the same
// Ash specific LOGGED_IN state.
if (!LoginState::Get()->IsUserLoggedIn())
return ash::user::LOGGED_IN_NONE;
if (screen_locked_)
return ash::user::LOGGED_IN_LOCKED;
LoginState::LoggedInUserType user_type =
LoginState::Get()->GetLoggedInUserType();
switch (user_type) {
case LoginState::LOGGED_IN_USER_NONE:
return ash::user::LOGGED_IN_NONE;
case LoginState::LOGGED_IN_USER_REGULAR:
return ash::user::LOGGED_IN_USER;
case LoginState::LOGGED_IN_USER_OWNER:
return ash::user::LOGGED_IN_OWNER;
case LoginState::LOGGED_IN_USER_GUEST:
return ash::user::LOGGED_IN_GUEST;
case LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT:
return ash::user::LOGGED_IN_PUBLIC;
case LoginState::LOGGED_IN_USER_SUPERVISED:
return ash::user::LOGGED_IN_SUPERVISED;
case LoginState::LOGGED_IN_USER_KIOSK_APP:
return ash::user::LOGGED_IN_KIOSK_APP;
}
NOTREACHED();
return ash::user::LOGGED_IN_NONE;
}
void SystemTrayDelegateChromeOS::ChangeProfilePicture() {
content::RecordAction(
base::UserMetricsAction("OpenChangeProfilePictureDialog"));
ShowSettingsSubPageForActiveUser(chrome::kChangeProfilePictureSubPage);
}
const std::string SystemTrayDelegateChromeOS::GetEnterpriseDomain() const {
return enterprise_domain_;
}
const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
if (GetEnterpriseDomain().empty())
return base::string16();
return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE,
base::UTF8ToUTF16(GetEnterpriseDomain()));
}
const std::string SystemTrayDelegateChromeOS::GetSupervisedUserManager() const {
if (!IsUserSupervised())
return std::string();
return SupervisedUserServiceFactory::GetForProfile(user_profile_)->
GetCustodianEmailAddress();
}
const base::string16
SystemTrayDelegateChromeOS::GetSupervisedUserManagerName() const {
if (!IsUserSupervised())
return base::string16();
return base::UTF8ToUTF16(SupervisedUserServiceFactory::GetForProfile(
user_profile_)->GetCustodianName());
}
const base::string16 SystemTrayDelegateChromeOS::GetSupervisedUserMessage()
const {
if (!IsUserSupervised())
return base::string16();
if (IsUserChild())
return GetChildUserMessage();
return GetLegacySupervisedUserMessage();
}
bool SystemTrayDelegateChromeOS::IsUserSupervised() const {
user_manager::User* user = user_manager::UserManager::Get()->GetActiveUser();
return user && user->IsSupervised();
}
bool SystemTrayDelegateChromeOS::IsUserChild() const {
return user_manager::UserManager::Get()->IsLoggedInAsChildUser();
}
void SystemTrayDelegateChromeOS::GetSystemUpdateInfo(
ash::UpdateInfo* info) const {
GetUpdateInfo(UpgradeDetector::GetInstance(), info);
}
base::HourClockType SystemTrayDelegateChromeOS::GetHourClockType() const {
return clock_type_;
}
void SystemTrayDelegateChromeOS::ShowSettings() {
ShowSettingsSubPageForActiveUser("");
}
bool SystemTrayDelegateChromeOS::ShouldShowSettings() {
return ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings() &&
!ash::Shell::GetInstance()
->session_state_delegate()
->IsInSecondaryLoginScreen();
}
void SystemTrayDelegateChromeOS::ShowDateSettings() {
content::RecordAction(base::UserMetricsAction("ShowDateOptions"));
std::string sub_page =
std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
// Everybody can change the time zone (even though it is a device setting).
ShowSettingsSubPageForActiveUser(sub_page);
}
void SystemTrayDelegateChromeOS::ShowSetTimeDialog() {
SetTimeDialog::ShowDialog(GetNativeWindow());
}
void SystemTrayDelegateChromeOS::ShowNetworkSettings(
const std::string& service_path) {
bool userAddingRunning = ash::Shell::GetInstance()
->session_state_delegate()
->IsInSecondaryLoginScreen();
if (!LoginState::Get()->IsUserLoggedIn() || userAddingRunning)
return;
ShowNetworkSettingsPage(service_path);
}
void SystemTrayDelegateChromeOS::ShowBluetoothSettings() {
// TODO(sad): Make this work.
}
void SystemTrayDelegateChromeOS::ShowDisplaySettings() {
content::RecordAction(base::UserMetricsAction("ShowDisplayOptions"));
ShowSettingsSubPageForActiveUser(kDisplaySettingsSubPageName);
}
void SystemTrayDelegateChromeOS::ShowChromeSlow() {
chrome::ScopedTabbedBrowserDisplayer displayer(
ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
chrome::ShowSlow(displayer.browser());
}
bool SystemTrayDelegateChromeOS::ShouldShowDisplayNotification() {
// Packaged app is not counted as 'last active', so if a browser opening the
// display settings is in background of a packaged app, it will return true.
// TODO(mukai): fix this.
Browser* active_browser =
chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
if (!active_browser)
return true;
content::WebContents* active_contents =
active_browser->tab_strip_model()->GetActiveWebContents();
if (!active_contents)
return true;
GURL visible_url = active_contents->GetLastCommittedURL();
GURL display_settings_url =
chrome::GetSettingsUrl(kDisplaySettingsSubPageName);
GURL display_overscan_url =
chrome::GetSettingsUrl(kDisplayOverscanSettingsSubPageName);
return (visible_url != display_settings_url &&
visible_url != display_overscan_url);
}
void SystemTrayDelegateChromeOS::ShowIMESettings() {
content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
ShowSettingsSubPageForActiveUser(chrome::kLanguageOptionsSubPage);
}
void SystemTrayDelegateChromeOS::ShowHelp() {
chrome::ShowHelpForProfile(ProfileManager::GetActiveUserProfile(),
chrome::HOST_DESKTOP_TYPE_ASH,
chrome::HELP_SOURCE_MENU);
}
void SystemTrayDelegateChromeOS::ShowAccessibilityHelp() {
chrome::ScopedTabbedBrowserDisplayer displayer(
ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
accessibility::ShowAccessibilityHelp(displayer.browser());
}
void SystemTrayDelegateChromeOS::ShowAccessibilitySettings() {
content::RecordAction(base::UserMetricsAction("ShowAccessibilitySettings"));
std::string sub_page = std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(
IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY);
ShowSettingsSubPageForActiveUser(sub_page);
}
void SystemTrayDelegateChromeOS::ShowPublicAccountInfo() {
chrome::ScopedTabbedBrowserDisplayer displayer(
ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
chrome::ShowPolicy(displayer.browser());
}
void SystemTrayDelegateChromeOS::ShowSupervisedUserInfo() {
// TODO(antrim): find out what should we show in this case.
// http://crbug.com/229762
}
void SystemTrayDelegateChromeOS::ShowEnterpriseInfo() {
ash::user::LoginStatus status = GetUserLoginStatus();
bool userAddingRunning = ash::Shell::GetInstance()
->session_state_delegate()
->IsInSecondaryLoginScreen();
if (status == ash::user::LOGGED_IN_NONE ||
status == ash::user::LOGGED_IN_LOCKED || userAddingRunning) {
scoped_refptr<chromeos::HelpAppLauncher> help_app(
new chromeos::HelpAppLauncher(GetNativeWindow()));
help_app->ShowHelpTopic(chromeos::HelpAppLauncher::HELP_ENTERPRISE);
} else {
chrome::ScopedTabbedBrowserDisplayer displayer(
ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
chrome::ShowSingletonTab(displayer.browser(),
GURL(chrome::kLearnMoreEnterpriseURL));
}
}
void SystemTrayDelegateChromeOS::ShowUserLogin() {
ash::Shell* shell = ash::Shell::GetInstance();
if (!shell->delegate()->IsMultiProfilesEnabled())
return;
// Only regular non-supervised users could add other users to current session.
if (user_manager::UserManager::Get()->GetActiveUser()->GetType() !=
user_manager::USER_TYPE_REGULAR) {
return;
}
if (static_cast<int>(
user_manager::UserManager::Get()->GetLoggedInUsers().size()) >=
shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers())
return;
// Launch sign in screen to add another user to current session.
if (user_manager::UserManager::Get()
->GetUsersAllowedForMultiProfile()
.size()) {
// Don't show dialog if any logged in user in multi-profiles session
// dismissed it.
bool show_intro = true;
const user_manager::UserList logged_in_users =
user_manager::UserManager::Get()->GetLoggedInUsers();
for (user_manager::UserList::const_iterator it = logged_in_users.begin();
it != logged_in_users.end();
++it) {
show_intro &= !multi_user_util::GetProfileFromUserID(
multi_user_util::GetUserIDFromEmail((*it)->email()))
->GetPrefs()
->GetBoolean(prefs::kMultiProfileNeverShowIntro);
if (!show_intro)
break;
}
if (show_intro) {
base::Callback<void(bool)> on_accept =
base::Bind(&OnAcceptMultiprofilesIntro);
ShowMultiprofilesIntroDialog(on_accept);
} else {
UserAddingScreen::Get()->Start();
}
}
}
void SystemTrayDelegateChromeOS::SignOut() {
chrome::AttemptUserExit();
}
void SystemTrayDelegateChromeOS::RequestLockScreen() {
// TODO(antrim) : additional logging for crbug/173178
LOG(WARNING) << "Requesting screen lock from AshSystemTrayDelegate";
DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
}
void SystemTrayDelegateChromeOS::RequestRestartForUpdate() {
// We expect that UpdateEngine is in "Reboot for update" state now.
chrome::NotifyAndTerminate(true /* fast path */);
}
void SystemTrayDelegateChromeOS::GetAvailableBluetoothDevices(
ash::BluetoothDeviceList* list) {
device::BluetoothAdapter::DeviceList devices =
bluetooth_adapter_->GetDevices();
for (size_t i = 0; i < devices.size(); ++i) {
device::BluetoothDevice* device = devices[i];
ash::BluetoothDeviceInfo info;
info.address = device->GetAddress();
info.display_name = device->GetName();
info.connected = device->IsConnected();
info.connecting = device->IsConnecting();
info.paired = device->IsPaired();
list->push_back(info);
}
}
void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() {
if (GetBluetoothDiscovering()) {
LOG(WARNING) << "Already have active Bluetooth device discovery session.";
return;
}
VLOG(1) << "Requesting new Bluetooth device discovery session.";
should_run_bluetooth_discovery_ = true;
bluetooth_adapter_->StartDiscoverySession(
base::Bind(&SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BluetoothSetDiscoveringError));
}
void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() {
should_run_bluetooth_discovery_ = false;
if (!GetBluetoothDiscovering()) {
LOG(WARNING) << "No active Bluetooth device discovery session.";
return;
}
VLOG(1) << "Stopping Bluetooth device discovery session.";
bluetooth_discovery_session_->Stop(
base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError));
}
void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice(
const std::string& address) {
device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address);
if (!device || device->IsConnecting() ||
(device->IsConnected() && device->IsPaired())) {
return;
}
if (device->IsPaired() && !device->IsConnectable())
return;
if (device->IsPaired() || !device->IsPairable()) {
ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE);
device->Connect(NULL,
base::Bind(&base::DoNothing),
base::Bind(&BluetoothDeviceConnectError));
} else { // Show paring dialog for the unpaired device.
ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE);
BluetoothPairingDialog* dialog =
new BluetoothPairingDialog(GetNativeWindow(), device);
// The dialog deletes itself on close.
dialog->Show();
}
}
bool SystemTrayDelegateChromeOS::IsBluetoothDiscovering() {
return bluetooth_adapter_->IsDiscovering();
}
void SystemTrayDelegateChromeOS::GetCurrentIME(ash::IMEInfo* info) {
input_method::InputMethodManager* manager =
input_method::InputMethodManager::Get();
input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
input_method::InputMethodDescriptor ime =
manager->GetActiveIMEState()->GetCurrentInputMethod();
ExtractIMEInfo(ime, *util, info);
info->selected = true;
}
void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList* list) {
input_method::InputMethodManager* manager =
input_method::InputMethodManager::Get();
input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
scoped_ptr<input_method::InputMethodDescriptors> ime_descriptors(
manager->GetActiveIMEState()->GetActiveInputMethods());
std::string current =
manager->GetActiveIMEState()->GetCurrentInputMethod().id();
for (size_t i = 0; i < ime_descriptors->size(); i++) {
input_method::InputMethodDescriptor& ime = ime_descriptors->at(i);
ash::IMEInfo info;
ExtractIMEInfo(ime, *util, &info);
info.selected = ime.id() == current;
list->push_back(info);
}
}
void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
ash::IMEPropertyInfoList* list) {
ui::ime::InputMethodMenuItemList menu_list =
ui::ime::InputMethodMenuManager::GetInstance()->
GetCurrentInputMethodMenuItemList();
for (size_t i = 0; i < menu_list.size(); ++i) {
ash::IMEPropertyInfo property;
property.key = menu_list[i].key;
property.name = base::UTF8ToUTF16(menu_list[i].label);
property.selected = menu_list[i].is_selection_item_checked;
list->push_back(property);
}
}
void SystemTrayDelegateChromeOS::SwitchIME(const std::string& ime_id) {
input_method::InputMethodManager::Get()
->GetActiveIMEState()
->ChangeInputMethod(ime_id, false /* show_message */);
input_method::InputMethodSwitchRecorder::Get()->RecordSwitch(
true /* by_tray_menu */);
}
void SystemTrayDelegateChromeOS::ActivateIMEProperty(const std::string& key) {
input_method::InputMethodManager::Get()->ActivateInputMethodMenuItem(key);
}
void SystemTrayDelegateChromeOS::ManageBluetoothDevices() {
content::RecordAction(base::UserMetricsAction("ShowBluetoothSettingsPage"));
std::string sub_page =
std::string(chrome::kSearchSubPage) + "#" +
l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH);
ShowSettingsSubPageForActiveUser(sub_page);
}
void SystemTrayDelegateChromeOS::ToggleBluetooth() {
bluetooth_adapter_->SetPowered(!bluetooth_adapter_->IsPowered(),
base::Bind(&base::DoNothing),
base::Bind(&BluetoothPowerFailure));
}
void SystemTrayDelegateChromeOS::ShowOtherNetworkDialog(
const std::string& type) {
if (type == shill::kTypeCellular) {
ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
return;
}
NetworkConfigView::ShowForType(type, GetNativeWindow());
}
bool SystemTrayDelegateChromeOS::GetBluetoothAvailable() {
return bluetooth_adapter_->IsPresent();
}
bool SystemTrayDelegateChromeOS::GetBluetoothEnabled() {
return bluetooth_adapter_->IsPowered();
}
bool SystemTrayDelegateChromeOS::GetBluetoothDiscovering() {
return (bluetooth_discovery_session_.get() &&
bluetooth_discovery_session_->IsActive());
}
void SystemTrayDelegateChromeOS::ChangeProxySettings() {
CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE);
LoginDisplayHostImpl::default_host()->OpenProxySettings();
}
ash::VolumeControlDelegate*
SystemTrayDelegateChromeOS::GetVolumeControlDelegate() const {
return volume_control_delegate_.get();
}
void SystemTrayDelegateChromeOS::SetVolumeControlDelegate(
scoped_ptr<ash::VolumeControlDelegate> delegate) {
volume_control_delegate_.swap(delegate);
}
bool SystemTrayDelegateChromeOS::GetSessionStartTime(
base::TimeTicks* session_start_time) {
*session_start_time = session_start_time_;
return have_session_start_time_;
}
bool SystemTrayDelegateChromeOS::GetSessionLengthLimit(
base::TimeDelta* session_length_limit) {
*session_length_limit = session_length_limit_;
return have_session_length_limit_;
}
int SystemTrayDelegateChromeOS::GetSystemTrayMenuWidth() {
return l10n_util::GetLocalizedContentsWidthInPixels(
IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
}
void SystemTrayDelegateChromeOS::ActiveUserWasChanged() {
SetProfile(ProfileManager::GetActiveUserProfile());
GetSystemTrayNotifier()->NotifyUserUpdate();
}
bool SystemTrayDelegateChromeOS::IsSearchKeyMappedToCapsLock() {
return search_key_mapped_to_ == input_method::kCapsLockKey;
}
ash::tray::UserAccountsDelegate*
SystemTrayDelegateChromeOS::GetUserAccountsDelegate(
const std::string& user_id) {
if (!accounts_delegates_.contains(user_id)) {
const user_manager::User* user =
user_manager::UserManager::Get()->FindUser(user_id);
Profile* user_profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
CHECK(user_profile);
accounts_delegates_.set(
user_id,
scoped_ptr<ash::tray::UserAccountsDelegate>(
new UserAccountsDelegateChromeOS(user_profile)));
}
return accounts_delegates_.get(user_id);
}
void SystemTrayDelegateChromeOS::AddCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) {
custodian_info_changed_observers_.AddObserver(observer);
}
void SystemTrayDelegateChromeOS::RemoveCustodianInfoTrayObserver(
ash::CustodianInfoTrayObserver* observer) {
custodian_info_changed_observers_.RemoveObserver(observer);
}
void SystemTrayDelegateChromeOS::UserAddedToSession(
const user_manager::User* active_user) {
}
void SystemTrayDelegateChromeOS::ActiveUserChanged(
const user_manager::User* /* active_user */) {
}
void SystemTrayDelegateChromeOS::UserChangedChildStatus(
user_manager::User* user) {
Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(user);
// Returned user_profile might be NULL on restoring Users on browser start.
// At some point profile is not yet fully initiated.
if (session_started_ &&
user_profile != NULL &&
user_profile_ == user_profile) {
ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
GetUserLoginStatus());
}
}
ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() {
return ash::Shell::GetInstance()->GetPrimarySystemTray();
}
ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
return ash::Shell::GetInstance()->system_tray_notifier();
}
void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
// Stop observing the AppWindowRegistry of the current |user_profile_|.
StopObservingAppWindowRegistry();
// Stop observing custodian info changes of the current |user_profile_|.
StopObservingCustodianInfoChanges();
user_profile_ = profile;
// Start observing the AppWindowRegistry of the newly set |user_profile_|.
extensions::AppWindowRegistry::Get(user_profile_)->AddObserver(this);
// Start observing custodian info changes of the newly set |user_profile_|.
SupervisedUserServiceFactory::GetForProfile(profile)->AddObserver(this);
PrefService* prefs = profile->GetPrefs();
user_pref_registrar_.reset(new PrefChangeRegistrar);
user_pref_registrar_->Init(prefs);
user_pref_registrar_->Add(
prefs::kUse24HourClock,
base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
base::Unretained(this)));
user_pref_registrar_->Add(
prefs::kLanguageRemapSearchKeyTo,
base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged,
base::Unretained(this)));
user_pref_registrar_->Add(
prefs::kShowLogoutButtonInTray,
base::Bind(&SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray,
base::Unretained(this)));
user_pref_registrar_->Add(
prefs::kLogoutDialogDurationMs,
base::Bind(&SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration,
base::Unretained(this)));
user_pref_registrar_->Add(
prefs::kAccessibilityLargeCursorEnabled,
base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
base::Unretained(this),
ui::A11Y_NOTIFICATION_NONE));
user_pref_registrar_->Add(
prefs::kAccessibilityAutoclickEnabled,
base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
base::Unretained(this),
ui::A11Y_NOTIFICATION_NONE));
user_pref_registrar_->Add(
prefs::kShouldAlwaysShowAccessibilityMenu,
base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
base::Unretained(this),
ui::A11Y_NOTIFICATION_NONE));
user_pref_registrar_->Add(
prefs::kPerformanceTracingEnabled,
base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing,
base::Unretained(this)));
UpdateShowLogoutButtonInTray();
UpdateLogoutDialogDuration();
UpdatePerformanceTracing();
OnCustodianInfoChanged();
search_key_mapped_to_ =
profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
}
bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) {
if (profile != user_profile_)
return false;
user_pref_registrar_.reset();
user_profile_ = NULL;
return true;
}
bool SystemTrayDelegateChromeOS::GetShouldUse24HourClockForTesting() const {
return ShouldUse24HourClock();
}
bool SystemTrayDelegateChromeOS::ShouldUse24HourClock() const {
// On login screen and in guest mode owner default is used for
// kUse24HourClock preference.
const ash::user::LoginStatus status = GetUserLoginStatus();
const CrosSettings* const cros_settings = CrosSettings::Get();
bool system_use_24_hour_clock = true;
const bool system_value_found = cros_settings->GetBoolean(
kSystemUse24HourClock, &system_use_24_hour_clock);
if ((status == ash::user::LOGGED_IN_NONE) || !user_pref_registrar_)
return (system_value_found
? system_use_24_hour_clock
: (base::GetHourClockType() == base::k24HourClock));
const PrefService::Preference* user_pref =
user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock);
if (status == ash::user::LOGGED_IN_GUEST && user_pref->IsDefaultValue())
return (system_value_found
? system_use_24_hour_clock
: (base::GetHourClockType() == base::k24HourClock));
user_manager::User* active_user =
user_manager::UserManager::Get()->GetActiveUser();
if (active_user) {
Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(active_user);
if (user_profile) {
user_pref =
user_profile->GetPrefs()->FindPreference(prefs::kUse24HourClock);
}
}
bool use_24_hour_clock = true;
user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock);
return use_24_hour_clock;
}
void SystemTrayDelegateChromeOS::UpdateClockType() {
const bool use_24_hour_clock = ShouldUse24HourClock();
clock_type_ = use_24_hour_clock ? base::k24HourClock : base::k12HourClock;
GetSystemTrayNotifier()->NotifyDateFormatChanged();
// This also works for enterprise-managed devices because they never have
// local owner.
if (user_manager::UserManager::Get()->IsCurrentUserOwner())
CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, use_24_hour_clock);
}
void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() {
GetSystemTrayNotifier()->NotifyShowLoginButtonChanged(
user_pref_registrar_->prefs()->GetBoolean(
prefs::kShowLogoutButtonInTray));
}
void SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration() {
const int duration_ms =
user_pref_registrar_->prefs()->GetInteger(prefs::kLogoutDialogDurationMs);
GetSystemTrayNotifier()->NotifyLogoutDialogDurationChanged(
base::TimeDelta::FromMilliseconds(duration_ms));
}
void SystemTrayDelegateChromeOS::UpdateSessionStartTime() {
const PrefService* local_state = local_state_registrar_->prefs();
if (local_state->HasPrefPath(prefs::kSessionStartTime)) {
have_session_start_time_ = true;
session_start_time_ = base::TimeTicks::FromInternalValue(
local_state->GetInt64(prefs::kSessionStartTime));
} else {
have_session_start_time_ = false;
session_start_time_ = base::TimeTicks();
}
GetSystemTrayNotifier()->NotifySessionStartTimeChanged();
}
void SystemTrayDelegateChromeOS::UpdateSessionLengthLimit() {
const PrefService* local_state = local_state_registrar_->prefs();
if (local_state->HasPrefPath(prefs::kSessionLengthLimit)) {
have_session_length_limit_ = true;
session_length_limit_ = base::TimeDelta::FromMilliseconds(
std::min(std::max(local_state->GetInteger(prefs::kSessionLengthLimit),
kSessionLengthLimitMinMs),
kSessionLengthLimitMaxMs));
} else {
have_session_length_limit_ = false;
session_length_limit_ = base::TimeDelta();
}
GetSystemTrayNotifier()->NotifySessionLengthLimitChanged();
}
void SystemTrayDelegateChromeOS::StopObservingAppWindowRegistry() {
if (!user_profile_)
return;
extensions::AppWindowRegistry* registry =
extensions::AppWindowRegistry::Factory::GetForBrowserContext(
user_profile_, false);
if (registry)
registry->RemoveObserver(this);
}
void SystemTrayDelegateChromeOS::StopObservingCustodianInfoChanges() {
if (!user_profile_)
return;
SupervisedUserService* service = SupervisedUserServiceFactory::GetForProfile(
user_profile_);
if (service)
service->RemoveObserver(this);
}
void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
if (!user_profile_)
return;
BrowserList* browser_list =
BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
for (BrowserList::const_iterator it = browser_list->begin();
it != browser_list->end();
++it) {
if ((*it)->profile()->IsSameProfile(user_profile_)) {
// The current user has at least one open browser window.
return;
}
}
if (!extensions::AppWindowRegistry::Get(
user_profile_)->app_windows().empty()) {
// The current user has at least one open app window.
return;
}
GetSystemTrayNotifier()->NotifyLastWindowClosed();
}
// LoginState::Observer overrides.
void SystemTrayDelegateChromeOS::LoggedInStateChanged() {
// It apparently sometimes takes a while after login before the current user
// is recognized as the owner. Make sure that the system-wide clock setting
// is updated when the recognition eventually happens
// (http://crbug.com/278601).
//
// Note that it isn't safe to blindly call UpdateClockType() from this
// method, as LoggedInStateChanged() is also called before the logged-in
// user's profile has actually been loaded (http://crbug.com/317745). The
// system tray's time format is updated at login via SetProfile().
if (user_manager::UserManager::Get()->IsCurrentUserOwner()) {
CrosSettings::Get()->SetBoolean(kSystemUse24HourClock,
ShouldUse24HourClock());
}
}
// Overridden from SessionManagerClient::Observer.
void SystemTrayDelegateChromeOS::ScreenIsLocked() {
screen_locked_ = true;
ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
}
void SystemTrayDelegateChromeOS::ScreenIsUnlocked() {
screen_locked_ = false;
ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
}
gfx::NativeWindow SystemTrayDelegateChromeOS::GetNativeWindow() const {
bool session_started = ash::Shell::GetInstance()
->session_state_delegate()
->IsActiveUserSessionStarted();
return GetNativeWindowByStatus(GetUserLoginStatus(), session_started);
}
// content::NotificationObserver implementation.
void SystemTrayDelegateChromeOS::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
UpdateClockType();
break;
}
case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
ash::UpdateInfo info;
GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info);
GetSystemTrayNotifier()->NotifyUpdateRecommended(info);
break;
}
case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
// This notification is also sent on login screen when user avatar
// is loaded from file.
if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) {
GetSystemTrayNotifier()->NotifyUserUpdate();
}
break;
}
case chrome::NOTIFICATION_PROFILE_CREATED: {
SetProfile(content::Source<Profile>(source).ptr());
registrar_->Remove(this,
chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
break;
}
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
if (UnsetProfile(content::Source<Profile>(source).ptr())) {
registrar_->Remove(this,
chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
}
break;
}
case chrome::NOTIFICATION_SESSION_STARTED: {
session_started_ = true;
ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
GetUserLoginStatus());
SetProfile(ProfileManager::GetActiveUserProfile());
break;
}
default:
NOTREACHED();
}
}
void SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged() {
search_key_mapped_to_ = user_pref_registrar_->prefs()->GetInteger(
prefs::kLanguageRemapSearchKeyTo);
}
void SystemTrayDelegateChromeOS::OnAccessibilityModeChanged(
ui::AccessibilityNotificationVisibility notify) {
GetSystemTrayNotifier()->NotifyAccessibilityModeChanged(notify);
}
void SystemTrayDelegateChromeOS::UpdatePerformanceTracing() {
if (!user_pref_registrar_)
return;
bool value = user_pref_registrar_->prefs()->GetBoolean(
prefs::kPerformanceTracingEnabled);
GetSystemTrayNotifier()->NotifyTracingModeChanged(value);
}
// Overridden from InputMethodManager::Observer.
void SystemTrayDelegateChromeOS::InputMethodChanged(
input_method::InputMethodManager* manager,
bool show_message) {
GetSystemTrayNotifier()->NotifyRefreshIME();
}
// Overridden from InputMethodMenuManager::Observer.
void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged(
ui::ime::InputMethodMenuManager* manager) {
GetSystemTrayNotifier()->NotifyRefreshIME();
}
// Overridden from CrasAudioHandler::AudioObserver.
void SystemTrayDelegateChromeOS::OnOutputVolumeChanged() {
GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged();
}
void SystemTrayDelegateChromeOS::OnOutputMuteChanged() {
GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged();
}
void SystemTrayDelegateChromeOS::OnInputGainChanged() {
}
void SystemTrayDelegateChromeOS::OnInputMuteChanged() {
}
void SystemTrayDelegateChromeOS::OnAudioNodesChanged() {
GetSystemTrayNotifier()->NotifyAudioNodesChanged();
}
void SystemTrayDelegateChromeOS::OnActiveOutputNodeChanged() {
GetSystemTrayNotifier()->NotifyAudioActiveOutputNodeChanged();
}
void SystemTrayDelegateChromeOS::OnActiveInputNodeChanged() {
GetSystemTrayNotifier()->NotifyAudioActiveInputNodeChanged();
}
// Overridden from BluetoothAdapter::Observer.
void SystemTrayDelegateChromeOS::AdapterPresentChanged(
device::BluetoothAdapter* adapter,
bool present) {
GetSystemTrayNotifier()->NotifyRefreshBluetooth();
}
void SystemTrayDelegateChromeOS::AdapterPoweredChanged(
device::BluetoothAdapter* adapter,
bool powered) {
GetSystemTrayNotifier()->NotifyRefreshBluetooth();
}
void SystemTrayDelegateChromeOS::AdapterDiscoveringChanged(
device::BluetoothAdapter* adapter,
bool discovering) {
GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
}
void SystemTrayDelegateChromeOS::DeviceAdded(device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
GetSystemTrayNotifier()->NotifyRefreshBluetooth();
}
void SystemTrayDelegateChromeOS::DeviceChanged(
device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
GetSystemTrayNotifier()->NotifyRefreshBluetooth();
}
void SystemTrayDelegateChromeOS::DeviceRemoved(
device::BluetoothAdapter* adapter,
device::BluetoothDevice* device) {
GetSystemTrayNotifier()->NotifyRefreshBluetooth();
}
void SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession(
scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
// If the discovery session was returned after a request to stop discovery
// (e.g. the user dismissed the Bluetooth detailed view before the call
// returned), don't claim the discovery session and let it clean up.
if (!should_run_bluetooth_discovery_)
return;
VLOG(1) << "Claiming new Bluetooth device discovery session.";
bluetooth_discovery_session_ = discovery_session.Pass();
GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
}
void SystemTrayDelegateChromeOS::UpdateEnterpriseDomain() {
policy::BrowserPolicyConnectorChromeOS* connector =
g_browser_process->platform_part()->browser_policy_connector_chromeos();
std::string enterprise_domain = connector->GetEnterpriseDomain();
if (enterprise_domain_ != enterprise_domain) {
enterprise_domain_ = enterprise_domain;
GetSystemTrayNotifier()->NotifyEnterpriseDomainChanged();
}
}
// Overridden from CloudPolicyStore::Observer
void SystemTrayDelegateChromeOS::OnStoreLoaded(
policy::CloudPolicyStore* store) {
UpdateEnterpriseDomain();
}
void SystemTrayDelegateChromeOS::OnStoreError(policy::CloudPolicyStore* store) {
UpdateEnterpriseDomain();
}
// Overridden from ash::SessionStateObserver
void SystemTrayDelegateChromeOS::UserAddedToSession(
const std::string& user_id) {
GetSystemTrayNotifier()->NotifyUserAddedToSession();
}
void SystemTrayDelegateChromeOS::ActiveUserChanged(
const std::string& /* user_id */) {
UpdateClockType();
}
// Overridden from chrome::BrowserListObserver.
void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) {
NotifyIfLastWindowClosed();
}
// Overridden from extensions::AppWindowRegistry::Observer.
void SystemTrayDelegateChromeOS::OnAppWindowRemoved(
extensions::AppWindow* app_window) {
NotifyIfLastWindowClosed();
}
// Overridden from SupervisedUserServiceObserver.
void SystemTrayDelegateChromeOS::OnCustodianInfoChanged() {
FOR_EACH_OBSERVER(
ash::CustodianInfoTrayObserver, custodian_info_changed_observers_,
OnCustodianInfoChanged());
}
void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged(
const AccessibilityStatusEventDetails& details) {
if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
accessibility_subscription_.reset();
else
OnAccessibilityModeChanged(details.notify);
}
const base::string16
SystemTrayDelegateChromeOS::GetLegacySupervisedUserMessage() const {
std::string user_manager_name = GetSupervisedUserManager();
return l10n_util::GetStringFUTF16(
IDS_USER_IS_SUPERVISED_BY_NOTICE,
base::UTF8ToUTF16(user_manager_name));
}
const base::string16
SystemTrayDelegateChromeOS::GetChildUserMessage() const {
#if defined(ENABLE_SUPERVISED_USERS)
SupervisedUserService* service =
SupervisedUserServiceFactory::GetForProfile(user_profile_);
base::string16 first_custodian =
base::UTF8ToUTF16(service->GetCustodianEmailAddress());
base::string16 second_custodian =
base::UTF8ToUTF16(service->GetSecondCustodianEmailAddress());
LOG_IF(WARNING, first_custodian.empty()) <<
"Returning incomplete child user message as manager not known yet.";
if (second_custodian.empty()) {
return l10n_util::GetStringFUTF16(
IDS_CHILD_USER_IS_MANAGED_BY_ONE_PARENT_NOTICE, first_custodian);
} else {
return l10n_util::GetStringFUTF16(
IDS_CHILD_USER_IS_MANAGED_BY_TWO_PARENTS_NOTICE,
first_custodian,
second_custodian);
}
#endif
LOG(WARNING) << "SystemTrayDelegateChromeOS::GetChildUserMessage call while "
<< "ENABLE_SUPERVISED_USERS undefined.";
return base::string16();
}
ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
return new SystemTrayDelegateChromeOS();
}
} // namespace chromeos
|