system_tray_delegate_chromeos.cc revision a02191e04bc25c4935f804f2c080ae28663d096d
1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <algorithm>
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <set>
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector>
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/ash_switches.h"
13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/desktop_background/desktop_background_controller.h"
14a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/ime/input_method_menu_item.h"
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/ime/input_method_menu_manager.h"
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/metrics/user_metrics_recorder.h"
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/session_state_delegate.h"
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/session_state_observer.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/shell_delegate.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell_window_ids.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/bluetooth/bluetooth_observer.h"
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/session/logout_button_observer.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/date/clock_observer.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/drive/drive_observer.h"
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/ime/ime_observer.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray_accessibility.h"
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "ash/system/user/login_status.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/update_observer.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/user/user_observer.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/volume_control_delegate.h"
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "ash/wm/lock_state_controller.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind_helpers.h"
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h"
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h"
415e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/stringprintf.h"
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/sys_info.h"
44eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/browser_process.h"
467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
47868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/accessibility/magnification_manager.h"
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/bluetooth/bluetooth_pairing_dialog.h"
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/charger_replace/charger_replacement_dialog.h"
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/choose_mobile_network_dialog.h"
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/drive/drive_integration_service.h"
53868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/drive/job_list.h"
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/chromeos/enrollment_dialog_view.h"
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/events/system_key_event_listener.h"
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/input_method/input_method_util.h"
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h"
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/login/help_app_launcher.h"
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/login/login_display_host.h"
60c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/login/login_display_host_impl.h"
61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/login/login_wizard.h"
62c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/login/startup_utils.h"
638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/chromeos/login/supervised_user_manager.h"
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/login/user.h"
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/chromeos/login/user_adding_screen.h"
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/chromeos/login/user_manager.h"
67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/chromeos/net/network_portal_detector.h"
6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/options/network_config_view.h"
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h"
72bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "chrome/browser/chromeos/settings/cros_settings.h"
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/browser/chromeos/sim_dialog_delegate.h"
747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/drive/drive_service_interface.h"
75ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "chrome/browser/feedback/tracing_manager.h"
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/google/google_util.h"
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/lifetime/application_lifetime.h"
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
80a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chrome/browser/ui/ash/stub_user_accounts_delegate.h"
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/ash/volume_controller_chromeos.h"
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
84a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "chrome/browser/ui/browser_list.h"
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/chrome_pages.h"
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/host_desktop.h"
870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/singleton_tabs.h"
89eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "chrome/browser/ui/tabs/tab_strip_model.h"
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/webui/chromeos/charger_replacement_handler.h"
913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/upgrade_detector.h"
93effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "chrome/common/chrome_switches.h"
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/pref_names.h"
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/url_constants.h"
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/dbus_thread_manager.h"
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chromeos/dbus/session_manager_client.h"
98c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/ime/extension_ime_util.h"
99a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "chromeos/ime/ime_keyboard.h"
100c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/ime/input_method_manager.h"
101c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/login/login_state.h"
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "components/policy/core/common/cloud/cloud_policy_store.h"
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h"
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/user_metrics.h"
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "content/public/browser/web_contents.h"
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_adapter.h"
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_adapter_factory.h"
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "device/bluetooth/bluetooth_device.h"
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "grit/ash_strings.h"
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/generated_resources.h"
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "grit/locale_settings.h"
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/base/escape.h"
11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "third_party/cros_system_api/dbus/service_constants.h"
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
116bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch#include "ui/base/l10n/time_format.h"
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using drive::DriveIntegrationService;
11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using drive::DriveIntegrationServiceFactory;
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos {
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The minimum session length limit that can be set.
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kSessionLengthLimitMinMs = 30 * 1000;  // 30 seconds.
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The maximum session length limit that can be set.
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000;  // 24 hours.
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
131eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kDisplaySettingsSubPageName[] = "display";
132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochconst char kDisplayOverscanSettingsSubPageName[] = "displayOverscan";
133eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The URL for the Google Drive settings page.
135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const char kDriveSettingsPageURL[] = "https://drive.google.com";
136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const input_method::InputMethodUtil& util,
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    ash::IMEInfo* info) {
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->id = ime.id();
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->name = util.GetInputMethodLongName(ime);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->medium_name = util.GetInputMethodMediumName(ime);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  info->short_name = util.GetInputMethodShortName(ime);
144c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  info->third_party = extension_ime_util::IsExtensionIME(ime.id());
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeWindow GetNativeWindowByStatus(ash::user::LoginStatus login_status,
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          bool session_started) {
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  int container_id =
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (!session_started || login_status == ash::user::LOGGED_IN_NONE ||
151c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch       login_status == ash::user::LOGGED_IN_LOCKED)
152c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          ? ash::kShellWindowId_LockSystemModalContainer
153c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch          : ash::kShellWindowId_SystemModalContainer;
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  return ash::Shell::GetContainer(ash::Shell::GetPrimaryRootWindow(),
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                  container_id);
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Converts drive::JobInfo to ash::DriveOperationStatus.
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// If the job is not of type that ash tray is interested, returns false.
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool ConvertToDriveOperationStatus(const drive::JobInfo& info,
161c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                   ash::DriveOperationStatus* status) {
162c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (info.job_type == drive::TYPE_DOWNLOAD_FILE) {
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->type = ash::DriveOperationStatus::OPERATION_DOWNLOAD;
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  } else if (info.job_type == drive::TYPE_UPLOAD_NEW_FILE ||
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             info.job_type == drive::TYPE_UPLOAD_EXISTING_FILE) {
166c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->type = ash::DriveOperationStatus::OPERATION_UPLOAD;
167c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  } else {
168c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
169c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
170c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
171c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (info.state == drive::STATE_NONE)
172c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->state = ash::DriveOperationStatus::OPERATION_NOT_STARTED;
173c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  else
174c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    status->state = ash::DriveOperationStatus::OPERATION_IN_PROGRESS;
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  status->id = info.job_id;
177c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  status->file_path = info.file_path;
178c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  status->progress = info.num_total_bytes == 0 ? 0.0 :
179c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      static_cast<double>(info.num_completed_bytes) /
180c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          static_cast<double>(info.num_total_bytes);
181c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
183c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Converts drive::JobInfo that has finished in |error| state
185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// to ash::DriveOperationStatus.
186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// If the job is not of type that ash tray is interested, returns false.
187c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)bool ConvertToFinishedDriveOperationStatus(const drive::JobInfo& info,
188c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                           drive::FileError error,
189c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                                           ash::DriveOperationStatus* status) {
190c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (!ConvertToDriveOperationStatus(info, status))
191c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    return false;
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  status->state = (error == drive::FILE_ERROR_OK)
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                      ? ash::DriveOperationStatus::OPERATION_COMPLETED
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                      : ash::DriveOperationStatus::OPERATION_FAILED;
195c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return true;
196c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
197c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
198c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Converts a list of drive::JobInfo to a list of ash::DriveOperationStatusList.
199c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)ash::DriveOperationStatusList ConvertToDriveStatusList(
200c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    const std::vector<drive::JobInfo>& list) {
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ash::DriveOperationStatusList results;
202c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (size_t i = 0; i < list.size(); ++i) {
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ash::DriveOperationStatus status;
204c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (ConvertToDriveOperationStatus(list[i], &status))
205c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      results.push_back(status);
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return results;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void BluetoothPowerFailure() {
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sad): Show an error bubble?
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void BluetoothSetDiscoveringError() {
2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  LOG(ERROR) << "BluetoothSetDiscovering failed.";
2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void BluetoothDeviceConnectError(
2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    device::BluetoothDevice::ConnectErrorCode error_code) {
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(sad): Do something?
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
223effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochvoid ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
224effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  chrome::ShowSettingsSubPageForProfile(
225effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      ProfileManager::GetActiveUserProfile(), sub_page);
2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)}
2270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)void ShowNetworkSettingsPage(const std::string& service_path) {
2293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  std::string page = chrome::kInternetOptionsSubPage;
2304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  page += "?servicePath=" + net::EscapeUrlEncodedData(service_path, true);
2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("OpenInternetOptionsDialog"));
232effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(page);
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void OnAcceptMultiprofilesIntro(bool no_show_again) {
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PrefService* prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  prefs->SetBoolean(prefs::kMultiProfileNeverShowIntro, no_show_again);
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UserAddingScreen::Get()->Start();
2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}  // namespace
2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : weak_ptr_factory_(this),
2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_profile_(NULL),
2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      clock_type_(base::GetHourClockType()),
2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      search_key_mapped_to_(input_method::kSearchKey),
2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      screen_locked_(false),
2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      have_session_start_time_(false),
2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      have_session_length_limit_(false),
251a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      should_run_bluetooth_discovery_(false),
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      volume_control_delegate_(new VolumeController()),
2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      device_settings_observer_(CrosSettings::Get()->AddSettingsObserver(
2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          kSystemUse24HourClock,
2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     base::Unretained(this)))) {
2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Register notifications on construction so that events such as
2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // PROFILE_CREATED do not get missed if they happen before Initialize().
2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_.reset(new content::NotificationRegistrar);
2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() == ash::user::LOGGED_IN_NONE) {
26790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    registrar_->Add(this,
2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    chrome::NOTIFICATION_SESSION_STARTED,
2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    content::NotificationService::AllSources());
2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_PROFILE_CREATED,
2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_->Add(this,
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  chrome::NOTIFICATION_PROFILE_DESTROYED,
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  content::NotificationService::AllSources());
277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  CHECK(accessibility_manager);
280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  accessibility_subscription_ = accessibility_manager->RegisterCallback(
281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged,
282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 base::Unretained(this)));
2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Initialize() {
2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->AddObserver(this);
289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuManager::GetInstance()->AddObserver(this);
2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateClockType();
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothAdapterFactory::GetAdapter(
2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::InitializeOnAdapterReady,
2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr()));
295868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(
2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      this);
29858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (LoginState::IsInitialized())
3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    LoginState::Get()->AddObserver(this);
301a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
302a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CrasAudioHandler::IsInitialized())
303a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CrasAudioHandler::Get()->AddAudioObserver(this);
304a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
305a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList::AddObserver(this);
3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Shutdown() {
3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device_settings_observer_.reset();
3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
311c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::InitializeOnAdapterReady(
3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_refptr<device::BluetoothAdapter> adapter) {
3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_ = adapter;
3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(bluetooth_adapter_.get());
3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->AddObserver(this);
3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_.reset(new PrefChangeRegistrar);
3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Init(g_browser_process->local_state());
3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateSessionStartTime();
3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateSessionLengthLimit();
3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Add(
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kSessionStartTime,
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionStartTime,
3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_->Add(
3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kSessionLengthLimit,
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateSessionLengthLimit,
3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* policy_connector =
3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      policy_connector->GetDeviceCloudPolicyManager();
3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (policy_manager)
3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy_manager->core()->store()->AddObserver(this);
3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Unregister PrefChangeRegistrars.
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  local_state_registrar_.reset();
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset();
3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
347a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Unregister content notifications before destroying any components.
3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  registrar_.reset();
3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
350a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Unregister a11y status subscription.
351a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  accessibility_subscription_.reset();
352a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->RemoveObserver(this);
3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->RemoveObserver(this);
355a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuManager::GetInstance()->RemoveObserver(this);
3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->RemoveObserver(this);
3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()
3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->session_state_delegate()
3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ->RemoveSessionStateObserver(this);
3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginState::Get()->RemoveObserver(this);
3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
362a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (CrasAudioHandler::IsInitialized())
363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    CrasAudioHandler::Get()->RemoveAudioObserver(this);
364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList::RemoveObserver(this);
366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StopObservingAppWindowRegistry();
367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Stop observing Drive operations.
3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UnobserveDriveUpdates();
3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* connector =
3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::DeviceCloudPolicyManagerChromeOS* policy_manager =
3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      connector->GetDeviceCloudPolicyManager();
3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (policy_manager)
3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy_manager->core()->store()->RemoveObserver(this);
3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from ash::SystemTrayDelegate:
3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetTrayVisibilityOnStartup() {
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // In case of OOBE / sign in screen tray will be shown later.
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return LoginState::Get()->IsUserLoggedIn();
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::user::LoginStatus SystemTrayDelegateChromeOS::GetUserLoginStatus() const {
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All non-logged in ChromeOS specific LOGGED_IN states map to the same
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Ash specific LOGGED_IN state.
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!LoginState::Get()->IsUserLoggedIn())
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ash::user::LOGGED_IN_NONE;
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (screen_locked_)
3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return ash::user::LOGGED_IN_LOCKED;
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginState::LoggedInUserType user_type =
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      LoginState::Get()->GetLoggedInUserType();
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  switch (user_type) {
3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_NONE:
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return ash::user::LOGGED_IN_NONE;
3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_REGULAR:
4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_USER;
4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_OWNER:
4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_OWNER;
4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_GUEST:
4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_GUEST;
4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_RETAIL_MODE:
4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_RETAIL_MODE;
4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT:
4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_PUBLIC;
4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_LOCALLY_MANAGED:
4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_LOCALLY_MANAGED;
4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case LoginState::LOGGED_IN_USER_KIOSK_APP:
4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return ash::user::LOGGED_IN_KIOSK_APP;
4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NOTREACHED();
4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::user::LOGGED_IN_NONE;
4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
417d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)
4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsOobeCompleted() const {
4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!base::SysInfo::IsRunningOnChromeOS() &&
4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      LoginState::Get()->IsUserLoggedIn())
4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return StartupUtils::IsOobeCompleted();
4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ChangeProfilePicture() {
4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(
4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::UserMetricsAction("OpenChangeProfilePictureDialog"));
428effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(chrome::kChangeProfilePictureSubPage);
4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
430c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const std::string SystemTrayDelegateChromeOS::GetEnterpriseDomain() const {
4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return enterprise_domain_;
4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16 SystemTrayDelegateChromeOS::GetEnterpriseMessage() const {
4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetEnterpriseDomain().empty())
4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetStringFUTF16(IDS_DEVICE_OWNED_BY_NOTICE,
4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    base::UTF8ToUTF16(GetEnterpriseDomain()));
4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const std::string SystemTrayDelegateChromeOS::GetLocallyManagedUserManager()
4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const {
4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_LOCALLY_MANAGED)
4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return std::string();
4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UserManager::Get()->GetSupervisedUserManager()->GetManagerDisplayEmail(
4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chromeos::UserManager::Get()->GetActiveUser()->email());
4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16
4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::GetLocallyManagedUserManagerName() const {
4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_LOCALLY_MANAGED)
4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UserManager::Get()->GetSupervisedUserManager()->GetManagerDisplayName(
4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chromeos::UserManager::Get()->GetActiveUser()->email());
4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
457c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const base::string16 SystemTrayDelegateChromeOS::GetLocallyManagedUserMessage()
4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const {
4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (GetUserLoginStatus() != ash::user::LOGGED_IN_LOCALLY_MANAGED)
4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return base::string16();
4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetStringFUTF16(
4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      IDS_USER_IS_LOCALLY_MANAGED_BY_NOTICE,
4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::UTF8ToUTF16(GetLocallyManagedUserManager()));
4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
466eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
4675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::SystemShouldUpgrade() const {
4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UpgradeDetector::GetInstance()->notify_upgrade();
4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::HourClockType SystemTrayDelegateChromeOS::GetHourClockType() const {
4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return clock_type_;
4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowSettings() {
476effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser("");
4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldShowSettings() {
4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return UserManager::Get()->GetCurrentUserFlow()->ShouldShowSettings();
4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDateSettings() {
4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowDateOptions"));
4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page =
4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::string(chrome::kSearchSubPage) + "#" +
4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME);
4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Everybody can change the time zone (even though it is a device setting).
489effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
4905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowNetworkSettings(
4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& service_path) {
4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!LoginState::Get()->IsUserLoggedIn())
4955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ShowNetworkSettingsPage(service_path);
4975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowBluetoothSettings() {
5005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(sad): Make this work.
5015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDisplaySettings() {
5045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowDisplayOptions"));
505effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(kDisplaySettingsSubPageName);
5065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowChromeSlow() {
5095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowSlow(displayer.browser());
5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
513eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldShowDisplayNotification() {
5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Packaged app is not counted as 'last active', so if a browser opening the
5165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // display settings is in background of a packaged app, it will return true.
5175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(mukai): fix this.
5185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  Browser* active_browser =
5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chrome::FindLastActiveWithHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH);
5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!active_browser)
5215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
522ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::WebContents* active_contents =
5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      active_browser->tab_strip_model()->GetActiveWebContents();
5255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!active_contents)
5265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return true;
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GURL visible_url = active_contents->GetLastCommittedURL();
529effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  GURL display_settings_url =
530effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      chrome::GetSettingsUrl(kDisplaySettingsSubPageName);
531effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  GURL display_overscan_url =
532effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      chrome::GetSettingsUrl(kDisplayOverscanSettingsSubPageName);
533effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  return (visible_url != display_settings_url &&
534effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch          visible_url != display_overscan_url);
5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowDriveSettings() {
5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(tengs): Open the drive-specific settings page once we put it in.
5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // For now just show Google Drive main page.
5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowSingletonTabOverwritingNTP(
5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      displayer.browser(),
5445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      chrome::GetSingletonTabNavigateParams(displayer.browser(),
5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                            GURL(kDriveSettingsPageURL)));
5465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowIMESettings() {
5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("OpenLanguageOptionsDialog"));
550effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(chrome::kLanguageOptionsSubPage);
5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowHelp() {
5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowHelpForProfile(ProfileManager::GetActiveUserProfile(),
5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             chrome::HOST_DESKTOP_TYPE_ASH,
5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             chrome::HELP_SOURCE_MENU);
5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowAccessibilityHelp() {
5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  accessibility::ShowAccessibilityHelp(displayer.browser());
5635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
564b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
5655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowAccessibilitySettings() {
5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowAccessibilitySettings"));
5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page = std::string(chrome::kSearchSubPage) + "#" +
5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         l10n_util::GetStringUTF8(
5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY);
570effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowPublicAccountInfo() {
5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ScopedTabbedBrowserDisplayer displayer(
5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::ShowPolicy(displayer.browser());
5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowLocallyManagedUserInfo() {
5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(antrim): find out what should we show in this case.
5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // http://crbug.com/229762
5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
5835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowEnterpriseInfo() {
5855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::user::LoginStatus status = GetUserLoginStatus();
5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (status == ash::user::LOGGED_IN_NONE ||
5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      status == ash::user::LOGGED_IN_LOCKED) {
5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_refptr<chromeos::HelpAppLauncher> help_app(
5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new chromeos::HelpAppLauncher(GetNativeWindow()));
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    help_app->ShowHelpTopic(chromeos::HelpAppLauncher::HELP_ENTERPRISE);
5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GURL url(google_util::StringAppendGoogleLocaleParam(
5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        chrome::kLearnMoreEnterpriseURL));
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    chrome::ScopedTabbedBrowserDisplayer displayer(
5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ProfileManager::GetActiveUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    chrome::ShowSingletonTab(displayer.browser(), url);
597c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
599c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowUserLogin() {
6015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell* shell = ash::Shell::GetInstance();
6025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!shell->delegate()->IsMultiProfilesEnabled())
6035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Only regular users could add other users to current session.
6065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (UserManager::Get()->GetActiveUser()->GetType() !=
6075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      User::USER_TYPE_REGULAR) {
6085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
6105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (static_cast<int>(UserManager::Get()->GetLoggedInUsers().size()) >=
6125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers())
6135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Launch sign in screen to add another user to current session.
6165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (UserManager::Get()->GetUsersAdmittedForMultiProfile().size()) {
6175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Don't show dialog if any logged in user in multi-profiles session
6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // dismissed it.
6195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool show_intro = true;
6205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const UserList logged_in_users = UserManager::Get()->GetLoggedInUsers();
6215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    for (UserList::const_iterator it = logged_in_users.begin();
6225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         it != logged_in_users.end();
6235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         ++it) {
6245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      show_intro &= !multi_user_util::GetProfileFromUserID(
6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         multi_user_util::GetUserIDFromEmail((*it)->email()))
6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         ->GetPrefs()
6275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         ->GetBoolean(prefs::kMultiProfileNeverShowIntro);
6285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (!show_intro)
6295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        break;
6305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (show_intro) {
6325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Callback<void(bool)> on_accept =
6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          base::Bind(&OnAcceptMultiprofilesIntro);
6345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ShowMultiprofilesIntroDialog(on_accept);
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    } else {
6365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      UserAddingScreen::Get()->Start();
6372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
6395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShowSpringChargerReplacementDialog() {
6425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!ChargerReplacementDialog::ShouldShowDialog())
6435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
644c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ChargerReplacementDialog* dialog =
6465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      new ChargerReplacementDialog(GetNativeWindow());
6475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  dialog->Show();
6485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
650c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsSpringChargerReplacementDialogVisible() {
6525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ChargerReplacementDialog::IsDialogVisible();
6535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
654c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::HasUserConfirmedSafeSpringCharger() {
6565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ChargerReplacementHandler::GetChargerStatusPref() ==
6575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)         ChargerReplacementHandler::CONFIRM_SAFE_CHARGER;
6585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
659c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
6605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShutDown() {
6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown();
6625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SignOut() {
6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::AttemptUserExit();
6665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::RequestLockScreen() {
6695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // TODO(antrim) : additional logging for crbug/173178
6705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LOG(WARNING) << "Requesting screen lock from AshSystemTrayDelegate";
6715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DBusThreadManager::Get()->GetSessionManagerClient()->RequestLockScreen();
6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::RequestRestartForUpdate() {
6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We expect that UpdateEngine is in "Reboot for update" state now.
6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  chrome::NotifyAndTerminate(true /* fast path */);
6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetAvailableBluetoothDevices(
6805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::BluetoothDeviceList* list) {
6815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothAdapter::DeviceList devices =
6825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      bluetooth_adapter_->GetDevices();
6835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < devices.size(); ++i) {
6845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device = devices[i];
6855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::BluetoothDeviceInfo info;
6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.address = device->GetAddress();
6875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.display_name = device->GetName();
6885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.connected = device->IsConnected();
6895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.connecting = device->IsConnecting();
6905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.paired = device->IsPaired();
6915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(info);
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
6935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::BluetoothStartDiscovering() {
696e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  if (GetBluetoothDiscovering()) {
697a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LOG(WARNING) << "Already have active Bluetooth device discovery session.";
698a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
699a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
700a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Requesting new Bluetooth device discovery session.";
701a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  should_run_bluetooth_discovery_ = true;
702a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_adapter_->StartDiscoverySession(
703a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession,
704a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                 weak_ptr_factory_.GetWeakPtr()),
705a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      base::Bind(&BluetoothSetDiscoveringError));
7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::BluetoothStopDiscovering() {
709a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  should_run_bluetooth_discovery_ = false;
710e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  if (!GetBluetoothDiscovering()) {
711a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    LOG(WARNING) << "No active Bluetooth device discovery session.";
712a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
713a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
714a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Stopping Bluetooth device discovery session.";
715a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_discovery_session_->Stop(
7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&base::DoNothing), base::Bind(&BluetoothSetDiscoveringError));
7175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ConnectToBluetoothDevice(
7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& address) {
7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address);
7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!device || device->IsConnecting() ||
7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      (device->IsConnected() && device->IsPaired())) {
7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
7265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (device->IsPaired() && !device->IsConnectable())
7275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (device->IsPaired() || !device->IsPairable()) {
7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_KNOWN_DEVICE);
7315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device->Connect(NULL,
7325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    base::Bind(&base::DoNothing),
7335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                    base::Bind(&BluetoothDeviceConnectError));
7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {  // Show paring dialog for the unpaired device.
7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::Shell::GetInstance()->metrics()->RecordUserMetricsAction(
7365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::UMA_STATUS_AREA_BLUETOOTH_CONNECT_UNKNOWN_DEVICE);
7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    BluetoothPairingDialog* dialog =
7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        new BluetoothPairingDialog(GetNativeWindow(), device);
7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // The dialog deletes itself on close.
7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    dialog->Show();
7415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsBluetoothDiscovering() {
7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsDiscovering();
7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetCurrentIME(ash::IMEInfo* info) {
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager* manager =
7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      input_method::InputMethodManager::Get();
7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodDescriptor ime = manager->GetCurrentInputMethod();
7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ExtractIMEInfo(ime, *util, info);
7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  info->selected = true;
7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetAvailableIMEList(ash::IMEInfoList* list) {
7585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager* manager =
7595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      input_method::InputMethodManager::Get();
7605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodUtil* util = manager->GetInputMethodUtil();
7615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_ptr<input_method::InputMethodDescriptors> ime_descriptors(
7625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      manager->GetActiveInputMethods());
7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string current = manager->GetCurrentInputMethod().id();
7645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  for (size_t i = 0; i < ime_descriptors->size(); i++) {
7655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    input_method::InputMethodDescriptor& ime = ime_descriptors->at(i);
7665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEInfo info;
7675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ExtractIMEInfo(ime, *util, &info);
7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    info.selected = ime.id() == current;
7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(info);
7705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetCurrentIMEProperties(
7745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEPropertyInfoList* list) {
775a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ash::ime::InputMethodMenuItemList menu_list =
776a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      ash::ime::InputMethodMenuManager::GetInstance()->
777a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      GetCurrentInputMethodMenuItemList();
778a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (size_t i = 0; i < menu_list.size(); ++i) {
7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::IMEPropertyInfo property;
780a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.key = menu_list[i].key;
781a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.name = base::UTF8ToUTF16(menu_list[i].label);
782a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    property.selected = menu_list[i].is_selection_item_checked;
7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    list->push_back(property);
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
7855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SwitchIME(const std::string& ime_id) {
7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  input_method::InputMethodManager::Get()->ChangeInputMethod(ime_id);
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ActivateIMEProperty(const std::string& key) {
792a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  input_method::InputMethodManager::Get()->ActivateInputMethodMenuItem(key);
7935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::CancelDriveOperation(int32 operation_id) {
7965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
7975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!integration_service)
7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  integration_service->job_list()->CancelJob(operation_id);
8015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::GetDriveOperationStatusList(
8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::DriveOperationStatusList* list) {
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
8065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!integration_service)
8075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *list = ConvertToDriveStatusList(
8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      integration_service->job_list()->GetJobInfoList());
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowNetworkConfigure(
8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& network_id,
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::NativeWindow parent_window) {
8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NetworkConfigView::Show(network_id, parent_window);
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::EnrollNetwork(
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& network_id,
8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    gfx::NativeWindow parent_window) {
8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return enrollment::CreateDialog(network_id, parent_window);
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ManageBluetoothDevices() {
8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RecordAction(base::UserMetricsAction("ShowBluetoothSettingsPage"));
8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string sub_page =
8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::string(chrome::kSearchSubPage) + "#" +
8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SECTION_TITLE_BLUETOOTH);
830effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  ShowSettingsSubPageForActiveUser(sub_page);
8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ToggleBluetooth() {
8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bluetooth_adapter_->SetPowered(!bluetooth_adapter_->IsPowered(),
8355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Bind(&base::DoNothing),
8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                 base::Bind(&BluetoothPowerFailure));
8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowMobileSimDialog() {
8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SimDialogDelegate::ShowDialog(GetNativeWindow(),
8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                SimDialogDelegate::SIM_DIALOG_UNLOCK);
8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
84390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowMobileSetupDialog(
8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& service_path) {
8465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  MobileSetupDialog::Show(service_path);
8475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
848ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ShowOtherNetworkDialog(
8505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& type) {
8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (type == shill::kTypeCellular) {
8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
8535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
8555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NetworkConfigView::ShowForType(type, GetNativeWindow());
8565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetBluetoothAvailable() {
8595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsPresent();
8605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetBluetoothEnabled() {
8635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return bluetooth_adapter_->IsPowered();
8645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
866e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochbool SystemTrayDelegateChromeOS::GetBluetoothDiscovering() {
867e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  return (bluetooth_discovery_session_.get() &&
868e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch      bluetooth_discovery_session_->IsActive());
869e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch}
870e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ChangeProxySettings() {
8725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CHECK(GetUserLoginStatus() == ash::user::LOGGED_IN_NONE);
8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  LoginDisplayHostImpl::default_host()->OpenProxySettings();
8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::VolumeControlDelegate*
8775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::GetVolumeControlDelegate() const {
8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return volume_control_delegate_.get();
8795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SetVolumeControlDelegate(
8825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    scoped_ptr<ash::VolumeControlDelegate> delegate) {
8835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  volume_control_delegate_.swap(delegate);
8845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetSessionStartTime(
8875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeTicks* session_start_time) {
8885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *session_start_time = session_start_time_;
8895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return have_session_start_time_;
8905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetSessionLengthLimit(
8935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::TimeDelta* session_length_limit) {
8945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  *session_length_limit = session_length_limit_;
8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return have_session_length_limit_;
8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int SystemTrayDelegateChromeOS::GetSystemTrayMenuWidth() {
8995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return l10n_util::GetLocalizedContentsWidthInPixels(
9005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
9015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ActiveUserWasChanged() {
9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyUserUpdate();
9055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
907a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsNetworkBehindCaptivePortal(
908a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const std::string& service_path) const {
909a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NetworkPortalDetector::CaptivePortalState state =
910a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      NetworkPortalDetector::Get()->GetCaptivePortalState(service_path);
911a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
912a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
913a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
914a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool SystemTrayDelegateChromeOS::IsSearchKeyMappedToCapsLock() {
915a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return search_key_mapped_to_ == input_method::kCapsLockKey;
916a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
917a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
918a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochash::tray::UserAccountsDelegate*
919a02191e04bc25c4935f804f2c080ae28663d096dBen MurdochSystemTrayDelegateChromeOS::GetUserAccountsDelegate(
920a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    const std::string& user_id) {
921a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  if (!accounts_delegates_.contains(user_id)) {
922a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    // TODO(dzhioev): replace stub with real implementation.
923a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    accounts_delegates_.set(user_id,
924a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                            scoped_ptr<ash::tray::UserAccountsDelegate>(
925a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch                                new StubUserAccountsDelegate(user_id)));
926a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
927a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("secondary_account1@gmail.com");
928a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
929a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("very_long_account_name_for_user@gmail.com");
930a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
931a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("secondary_account2@gmail.com");
932a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch    static_cast<StubUserAccountsDelegate*>(accounts_delegates_.get(user_id))
933a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch        ->AddAccount("very_very_very_long_account_name_for_user@gmail.com");
934a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  }
935a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  return accounts_delegates_.get(user_id);
936a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
937a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
9385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::SystemTray* SystemTrayDelegateChromeOS::GetPrimarySystemTray() {
9395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::Shell::GetInstance()->GetPrimarySystemTray();
9405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
9435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ash::Shell::GetInstance()->system_tray_notifier();
9445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
9455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
947a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Stop observing the Drive integration status and the AppWindowRegistry of
948a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the current |user_profile_|.
9495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UnobserveDriveUpdates();
950a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  StopObservingAppWindowRegistry();
9515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_profile_ = profile;
9535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
954a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Start observing the Drive integration status and the AppWindowRegistry of
955a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // the newly set |user_profile_|.
9565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ObserveDriveUpdates();
957a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  apps::AppWindowRegistry::Get(user_profile_)->AddObserver(this);
9585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PrefService* prefs = profile->GetPrefs();
9605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset(new PrefChangeRegistrar);
9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Init(prefs);
9625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kUse24HourClock,
9645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateClockType,
9655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLanguageRemapSearchKeyTo,
9685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged,
9695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kShowLogoutButtonInTray,
9725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray,
9735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLogoutDialogDurationMs,
9765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration,
9775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLargeCursorEnabled,
9805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kAutoclickEnabled,
9855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kShouldAlwaysShowAccessibilityMenu,
9905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::OnAccessibilityModeChanged,
9915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this),
9925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 ash::A11Y_NOTIFICATION_NONE));
9935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_->Add(
9945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kPerformanceTracingEnabled,
9955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing,
9965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 base::Unretained(this)));
9975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
9985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateClockType();
9995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateShowLogoutButtonInTray();
10005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateLogoutDialogDuration();
10015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdatePerformanceTracing();
10025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  search_key_mapped_to_ =
10035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      profile->GetPrefs()->GetInteger(prefs::kLanguageRemapSearchKeyTo);
10045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
100590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
10065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::UnsetProfile(Profile* profile) {
10075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (profile != user_profile_)
10085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return false;
10095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref_registrar_.reset();
1010a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  user_profile_ = NULL;
10115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return true;
10125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ObserveDriveUpdates() {
10155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
10165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (integration_service)
10175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    integration_service->job_list()->AddObserver(this);
10185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
10205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UnobserveDriveUpdates() {
10215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DriveIntegrationService* integration_service = FindDriveIntegrationService();
10225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (integration_service)
10235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    integration_service->job_list()->RemoveObserver(this);
10245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1025bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch
10265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::GetShouldUse24HourClockForTesting() const {
10275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return ShouldUse24HourClock();
10285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
10305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool SystemTrayDelegateChromeOS::ShouldUse24HourClock() const {
10315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // On login screen and in guest mode owner default is used for
10325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // kUse24HourClock preference.
10335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const ash::user::LoginStatus status = GetUserLoginStatus();
10345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const CrosSettings* const cros_settings = CrosSettings::Get();
10355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool system_use_24_hour_clock = true;
10365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const bool system_value_found = cros_settings->GetBoolean(
10375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      kSystemUse24HourClock, &system_use_24_hour_clock);
10385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if ((status == ash::user::LOGGED_IN_NONE) || !user_pref_registrar_)
10405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return (system_value_found
10415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                ? system_use_24_hour_clock
10425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                : (base::GetHourClockType() == base::k24HourClock));
10435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService::Preference* user_pref =
10455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->FindPreference(prefs::kUse24HourClock);
10465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (status == ash::user::LOGGED_IN_GUEST && user_pref->IsDefaultValue())
10475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return (system_value_found
10485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                ? system_use_24_hour_clock
10495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                : (base::GetHourClockType() == base::k24HourClock));
10505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
10515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool use_24_hour_clock = true;
10525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock);
10535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return use_24_hour_clock;
10545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateClockType() {
10575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const bool use_24_hour_clock = ShouldUse24HourClock();
10585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  clock_type_ = use_24_hour_clock ? base::k24HourClock : base::k12HourClock;
10595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyDateFormatChanged();
10605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This also works for enterprise-managed devices because they never have
10615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // local owner.
10625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (chromeos::UserManager::Get()->IsCurrentUserOwner())
10635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CrosSettings::Get()->SetBoolean(kSystemUse24HourClock, use_24_hour_clock);
10645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateShowLogoutButtonInTray() {
10675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyShowLoginButtonChanged(
10685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->GetBoolean(
10695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          prefs::kShowLogoutButtonInTray));
10705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateLogoutDialogDuration() {
10735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const int duration_ms =
10745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      user_pref_registrar_->prefs()->GetInteger(prefs::kLogoutDialogDurationMs);
10755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyLogoutDialogDurationChanged(
10765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      base::TimeDelta::FromMilliseconds(duration_ms));
10775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
107858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
10795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateSessionStartTime() {
10805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService* local_state = local_state_registrar_->prefs();
10815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (local_state->HasPrefPath(prefs::kSessionStartTime)) {
10825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_start_time_ = true;
10835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_start_time_ = base::TimeTicks::FromInternalValue(
10845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        local_state->GetInt64(prefs::kSessionStartTime));
10855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
10865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_start_time_ = false;
10875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_start_time_ = base::TimeTicks();
10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifySessionStartTimeChanged();
10905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateSessionLengthLimit() {
10935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  const PrefService* local_state = local_state_registrar_->prefs();
10945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (local_state->HasPrefPath(prefs::kSessionLengthLimit)) {
10955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_length_limit_ = true;
10965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_length_limit_ = base::TimeDelta::FromMilliseconds(
10975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        std::min(std::max(local_state->GetInteger(prefs::kSessionLengthLimit),
10985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                          kSessionLengthLimitMinMs),
10995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                 kSessionLengthLimitMaxMs));
11005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else {
11015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    have_session_length_limit_ = false;
11025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    session_length_limit_ = base::TimeDelta();
11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifySessionLengthLimitChanged();
11055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1107a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::StopObservingAppWindowRegistry() {
1108a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!user_profile_)
1109a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1110a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1111a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  apps::AppWindowRegistry* registry =
1112a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      apps::AppWindowRegistry::Factory::GetForBrowserContext(user_profile_,
1113a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                                                             false);
1114a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (registry)
1115a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    registry->RemoveObserver(this);
1116a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1118a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::NotifyIfLastWindowClosed() {
1119a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!user_profile_)
1120a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1121a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1122a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  BrowserList* browser_list =
1123a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
1124a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  for (BrowserList::const_iterator it = browser_list->begin();
1125a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       it != browser_list->end();
1126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)       ++it) {
1127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    if ((*it)->profile()->IsSameProfile(user_profile_)) {
1128a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      // The current user has at least one open browser window.
1129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      return;
1130a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    }
1131a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1132a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1133a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!apps::AppWindowRegistry::Get(user_profile_)->app_windows().empty()) {
1134a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    // The current user has at least one open app window.
1135a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1136a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  }
1137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1138a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyLastWindowClosed();
1139a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1140a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// LoginState::Observer overrides.
11425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::LoggedInStateChanged() {
11435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // It apparently sometimes takes a while after login before the current user
11445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is recognized as the owner. Make sure that the system-wide clock setting
11455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // is updated when the recognition eventually happens
11465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // (http://crbug.com/278601).
11475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
11485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note that it isn't safe to blindly call UpdateClockType() from this
11495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // method, as LoggedInStateChanged() is also called before the logged-in
11505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // user's profile has actually been loaded (http://crbug.com/317745). The
11515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // system tray's time format is updated at login via SetProfile().
11525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (chromeos::UserManager::Get()->IsCurrentUserOwner()) {
11535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    CrosSettings::Get()->SetBoolean(kSystemUse24HourClock,
11545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                    ShouldUse24HourClock());
11555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
11565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from SessionManagerClient::Observer.
11595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ScreenIsLocked() {
11605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  screen_locked_ = true;
11615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
11625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::ScreenIsUnlocked() {
11655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  screen_locked_ = false;
11665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
11675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)gfx::NativeWindow SystemTrayDelegateChromeOS::GetNativeWindow() const {
11705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool session_started = ash::Shell::GetInstance()
11715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             ->session_state_delegate()
11725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                             ->IsActiveUserSessionStarted();
11735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return GetNativeWindowByStatus(GetUserLoginStatus(), session_started);
11745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
11755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// content::NotificationObserver implementation.
11775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::Observe(
11785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    int type,
11795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const content::NotificationSource& source,
11805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const content::NotificationDetails& details) {
11815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  switch (type) {
11825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
11835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      UpgradeDetector* detector =
11845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          content::Source<UpgradeDetector>(source).ptr();
11855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ash::UpdateObserver::UpdateSeverity severity =
11865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          ash::UpdateObserver::UPDATE_NORMAL;
11875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      switch (detector->upgrade_notification_stage()) {
11885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
11895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_SEVERE_RED;
11905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
11935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_HIGH_ORANGE;
11945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
11965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
11975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_LOW_GREEN;
11985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
11995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
12005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
12015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        default:
12025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          severity = ash::UpdateObserver::UPDATE_NORMAL;
12035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          break;
12045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
12055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      GetSystemTrayNotifier()->NotifyUpdateRecommended(severity);
12065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
12095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // This notification is also sent on login screen when user avatar
12105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // is loaded from file.
12115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (GetUserLoginStatus() != ash::user::LOGGED_IN_NONE) {
12125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetSystemTrayNotifier()->NotifyUserUpdate();
12135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
12145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_PROFILE_CREATED: {
12175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      SetProfile(content::Source<Profile>(source).ptr());
12185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      registrar_->Remove(this,
12195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         chrome::NOTIFICATION_PROFILE_CREATED,
12205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                         content::NotificationService::AllSources());
12215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_PROFILE_DESTROYED: {
12245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      if (UnsetProfile(content::Source<Profile>(source).ptr())) {
122590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        registrar_->Remove(this,
12265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                           chrome::NOTIFICATION_PROFILE_DESTROYED,
122790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                           content::NotificationService::AllSources());
12282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      }
12295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
12315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    case chrome::NOTIFICATION_SESSION_STARTED: {
12325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
12335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          GetUserLoginStatus());
12345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      SetProfile(ProfileManager::GetActiveUserProfile());
12355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      break;
12365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
12375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    default:
12385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      NOTREACHED();
12395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
12405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnLanguageRemapSearchKeyToChanged() {
12435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  search_key_mapped_to_ = user_pref_registrar_->prefs()->GetInteger(
12445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kLanguageRemapSearchKeyTo);
12455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAccessibilityModeChanged(
12485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ash::AccessibilityNotificationVisibility notify) {
12495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAccessibilityModeChanged(notify);
12505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdatePerformanceTracing() {
12535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!user_pref_registrar_)
12545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
12555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool value = user_pref_registrar_->prefs()->GetBoolean(
12565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      prefs::kPerformanceTracingEnabled);
12575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyTracingModeChanged(value);
12585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
12605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from InputMethodManager::Observer.
12615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::InputMethodChanged(
12625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    input_method::InputMethodManager* manager,
12635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool show_message) {
1264a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshIME();
1265a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1266a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1267a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from InputMethodMenuManager::Observer.
1268a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::InputMethodMenuItemChanged(
1269a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    ash::ime::InputMethodMenuManager* manager) {
1270a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshIME();
1271a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1272a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1273a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from CrasAudioHandler::AudioObserver.
1274a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnOutputVolumeChanged() {
1275a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioOutputVolumeChanged();
1276a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1277a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1278a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnOutputMuteChanged() {
1279a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioOutputMuteChanged();
1280a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1281a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1282a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnInputGainChanged() {
1283a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1284a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1285a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnInputMuteChanged() {
12865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1288a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAudioNodesChanged() {
1289a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioNodesChanged();
1290a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1291a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1292a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnActiveOutputNodeChanged() {
1293a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioActiveOutputNodeChanged();
1294a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1295a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1296a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnActiveInputNodeChanged() {
1297a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyAudioActiveInputNodeChanged();
12985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
12995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// drive::JobListObserver overrides.
13015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnJobAdded(const drive::JobInfo& job_info) {
13025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  OnJobUpdated(job_info);
13035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnJobDone(const drive::JobInfo& job_info,
13065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                           drive::FileError error) {
13075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::DriveOperationStatus status;
13085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (ConvertToFinishedDriveOperationStatus(job_info, error, &status))
13095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetSystemTrayNotifier()->NotifyDriveJobUpdated(status);
13105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnJobUpdated(const drive::JobInfo& job_info) {
13135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ash::DriveOperationStatus status;
13145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (ConvertToDriveOperationStatus(job_info, &status))
13155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetSystemTrayNotifier()->NotifyDriveJobUpdated(status);
13165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)DriveIntegrationService*
13195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SystemTrayDelegateChromeOS::FindDriveIntegrationService() {
13205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return user_profile_
13215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             ? DriveIntegrationServiceFactory::FindForProfile(user_profile_)
13225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             : NULL;
13235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from BluetoothAdapter::Observer.
13265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::AdapterPresentChanged(
13275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool present) {
13295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::AdapterPoweredChanged(
13335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool powered) {
13355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::AdapterDiscoveringChanged(
13395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    bool discovering) {
13415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
13425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::DeviceAdded(device::BluetoothAdapter* adapter,
13455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                             device::BluetoothDevice* device) {
13465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::DeviceChanged(
13505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device) {
13525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
13555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::DeviceRemoved(
13565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothAdapter* adapter,
13575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    device::BluetoothDevice* device) {
13585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyRefreshBluetooth();
13595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1361a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnStartBluetoothDiscoverySession(
1362a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    scoped_ptr<device::BluetoothDiscoverySession> discovery_session) {
1363a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // If the discovery session was returned after a request to stop discovery
1364a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // (e.g. the user dismissed the Bluetooth detailed view before the call
1365a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // returned), don't claim the discovery session and let it clean up.
1366a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (!should_run_bluetooth_discovery_)
1367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return;
1368a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  VLOG(1) << "Claiming new Bluetooth device discovery session.";
1369a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bluetooth_discovery_session_ = discovery_session.Pass();
1370e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  GetSystemTrayNotifier()->NotifyBluetoothDiscoveringChanged();
13715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1372868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
13735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UpdateEnterpriseDomain() {
13745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  policy::BrowserPolicyConnectorChromeOS* connector =
13755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      g_browser_process->platform_part()->browser_policy_connector_chromeos();
13765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string enterprise_domain = connector->GetEnterpriseDomain();
13775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (enterprise_domain_ != enterprise_domain) {
13785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    enterprise_domain_ = enterprise_domain;
13795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    GetSystemTrayNotifier()->NotifyEnterpriseDomainChanged();
13804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  }
13815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
13835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from CloudPolicyStore::Observer
13845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnStoreLoaded(
13855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    policy::CloudPolicyStore* store) {
13865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
13875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
13895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnStoreError(policy::CloudPolicyStore* store) {
13905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  UpdateEnterpriseDomain();
13915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Overridden from ash::SessionStateObserver
13945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SystemTrayDelegateChromeOS::UserAddedToSession(
13955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    const std::string& user_id) {
13965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GetSystemTrayNotifier()->NotifyUserAddedToSession();
13975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
13985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1399a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from chrome::BrowserListObserver.
1400a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) {
1401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NotifyIfLastWindowClosed();
1402a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1403a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1404a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Overridden from apps::AppWindowRegistry::Observer.
1405a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAppWindowAdded(apps::AppWindow* app_window) {
1406a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1407a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1408a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAppWindowIconChanged(
1409a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    apps::AppWindow* app_window) {}
1410a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1411a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAppWindowRemoved(
1412a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    apps::AppWindow* app_window) {
1413a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  NotifyIfLastWindowClosed();
1414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1416a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void SystemTrayDelegateChromeOS::OnAccessibilityStatusChanged(
1417a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    const AccessibilityStatusEventDetails& details) {
1418a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  if (details.notification_type == ACCESSIBILITY_MANAGER_SHUTDOWN)
1419a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    accessibility_subscription_.reset();
1420a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  else
1421a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    OnAccessibilityModeChanged(details.notify);
1422a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
1423a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
14245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)ash::SystemTrayDelegate* CreateSystemTrayDelegate() {
14255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  return new SystemTrayDelegateChromeOS();
14265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
14275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
14285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace chromeos
1429