OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" | 5 #include "chrome/browser/chromeos/system/ash_system_tray_delegate.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/system/audio/audio_observer.h" | 9 #include "ash/system/audio/audio_observer.h" |
10 #include "ash/system/bluetooth/bluetooth_observer.h" | 10 #include "ash/system/bluetooth/bluetooth_observer.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "chrome/browser/chromeos/login/message_bubble.h" | 46 #include "chrome/browser/chromeos/login/message_bubble.h" |
47 #include "chrome/browser/chromeos/login/user.h" | 47 #include "chrome/browser/chromeos/login/user.h" |
48 #include "chrome/browser/chromeos/login/user_manager.h" | 48 #include "chrome/browser/chromeos/login/user_manager.h" |
49 #include "chrome/browser/chromeos/mobile_config.h" | 49 #include "chrome/browser/chromeos/mobile_config.h" |
50 #include "chrome/browser/chromeos/status/data_promo_notification.h" | 50 #include "chrome/browser/chromeos/status/data_promo_notification.h" |
51 #include "chrome/browser/chromeos/status/network_menu.h" | 51 #include "chrome/browser/chromeos/status/network_menu.h" |
52 #include "chrome/browser/chromeos/status/network_menu_icon.h" | 52 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
53 #include "chrome/browser/chromeos/system/timezone_settings.h" | 53 #include "chrome/browser/chromeos/system/timezone_settings.h" |
54 #include "chrome/browser/chromeos/system_key_event_listener.h" | 54 #include "chrome/browser/chromeos/system_key_event_listener.h" |
55 #include "chrome/browser/google_apis/gdata_util.h" | 55 #include "chrome/browser/google_apis/gdata_util.h" |
56 #include "chrome/browser/google_apis/operation_registry.h" | |
57 #include "chrome/browser/lifetime/application_lifetime.h" | 56 #include "chrome/browser/lifetime/application_lifetime.h" |
58 #include "chrome/browser/prefs/pref_service.h" | 57 #include "chrome/browser/prefs/pref_service.h" |
59 #include "chrome/browser/profiles/profile_manager.h" | 58 #include "chrome/browser/profiles/profile_manager.h" |
60 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" | 59 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
61 #include "chrome/browser/ui/browser.h" | 60 #include "chrome/browser/ui/browser.h" |
62 #include "chrome/browser/ui/browser_finder.h" | 61 #include "chrome/browser/ui/browser_finder.h" |
63 #include "chrome/browser/ui/chrome_pages.h" | 62 #include "chrome/browser/ui/chrome_pages.h" |
64 #include "chrome/browser/ui/singleton_tabs.h" | 63 #include "chrome/browser/ui/singleton_tabs.h" |
65 #include "chrome/browser/upgrade_detector.h" | 64 #include "chrome/browser/upgrade_detector.h" |
66 #include "chrome/common/chrome_notification_types.h" | 65 #include "chrome/common/chrome_notification_types.h" |
67 #include "chrome/common/pref_names.h" | 66 #include "chrome/common/pref_names.h" |
68 #include "chrome/common/url_constants.h" | 67 #include "chrome/common/url_constants.h" |
69 #include "chromeos/dbus/dbus_thread_manager.h" | 68 #include "chromeos/dbus/dbus_thread_manager.h" |
70 #include "chromeos/dbus/power_manager_client.h" | 69 #include "chromeos/dbus/power_manager_client.h" |
71 #include "chromeos/dbus/session_manager_client.h" | 70 #include "chromeos/dbus/session_manager_client.h" |
72 #include "content/public/browser/browser_thread.h" | 71 #include "content/public/browser/browser_thread.h" |
73 #include "content/public/browser/notification_observer.h" | 72 #include "content/public/browser/notification_observer.h" |
74 #include "content/public/browser/notification_service.h" | 73 #include "content/public/browser/notification_service.h" |
75 #include "content/public/browser/user_metrics.h" | 74 #include "content/public/browser/user_metrics.h" |
76 #include "grit/generated_resources.h" | 75 #include "grit/generated_resources.h" |
77 #include "ui/base/l10n/l10n_util.h" | 76 #include "ui/base/l10n/l10n_util.h" |
78 | 77 |
79 using gdata::DriveSystemService; | 78 using gdata::DriveSystemService; |
80 using gdata::DriveSystemServiceFactory; | 79 using gdata::DriveSystemServiceFactory; |
81 using gdata::OperationRegistry; | |
82 | 80 |
83 namespace chromeos { | 81 namespace chromeos { |
84 | 82 |
85 namespace { | 83 namespace { |
86 | 84 |
87 // Time delay for rechecking gdata operation when we suspect that there will | 85 // Time delay for rechecking gdata operation when we suspect that there will |
88 // be no upcoming activity notifications that need to be pushed to UI. | 86 // be no upcoming activity notifications that need to be pushed to UI. |
89 const int kGDataOperationRecheckDelayMs = 5000; | 87 const int kGDataOperationRecheckDelayMs = 5000; |
90 | 88 |
91 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, | 89 ash::NetworkIconInfo CreateNetworkIconInfo(const Network* network, |
92 NetworkMenu* network_menu) { | 90 NetworkMenu* network_menu) { |
93 ash::NetworkIconInfo info; | 91 ash::NetworkIconInfo info; |
94 info.name = UTF8ToUTF16(network->name()); | 92 info.name = UTF8ToUTF16(network->name()); |
95 info.image = NetworkMenuIcon::GetImage(network, NetworkMenuIcon::COLOR_DARK); | 93 info.image = NetworkMenuIcon::GetImage(network, NetworkMenuIcon::COLOR_DARK); |
96 info.service_path = network->service_path(); | 94 info.service_path = network->service_path(); |
97 info.highlight = network->connected() || network->connecting(); | 95 info.highlight = network->connected() || network->connecting(); |
98 return info; | 96 return info; |
99 } | 97 } |
100 | 98 |
101 void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime, | 99 void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime, |
102 const input_method::InputMethodUtil& util, | 100 const input_method::InputMethodUtil& util, |
103 ash::IMEInfo* info) { | 101 ash::IMEInfo* info) { |
104 info->id = ime.id(); | 102 info->id = ime.id(); |
105 info->name = util.GetInputMethodLongName(ime); | 103 info->name = util.GetInputMethodLongName(ime); |
106 info->short_name = util.GetInputMethodShortName(ime); | 104 info->short_name = util.GetInputMethodShortName(ime); |
107 info->third_party = ime.third_party(); | 105 info->third_party = ime.third_party(); |
108 } | 106 } |
109 | 107 |
110 ash::DriveOperationStatusList GetDriveStatusList( | 108 ash::DriveOperationStatusList GetDriveStatusList( |
111 const std::vector<OperationRegistry::ProgressStatus>& list) { | 109 const gdata::OperationProgressStatusList& list) { |
112 ash::DriveOperationStatusList results; | 110 ash::DriveOperationStatusList results; |
113 for (OperationRegistry::ProgressStatusList::const_iterator it = | 111 for (gdata::OperationProgressStatusList::const_iterator it = list.begin(); |
114 list.begin(); | |
115 it != list.end(); ++it) { | 112 it != list.end(); ++it) { |
116 ash::DriveOperationStatus status; | 113 ash::DriveOperationStatus status; |
117 status.file_path = it->file_path; | 114 status.file_path = it->file_path; |
118 status.progress = it->progress_total == 0 ? 0.0 : | 115 status.progress = it->progress_total == 0 ? 0.0 : |
119 static_cast<double>(it->progress_current) / | 116 static_cast<double>(it->progress_current) / |
120 static_cast<double>(it->progress_total); | 117 static_cast<double>(it->progress_total); |
121 status.type = static_cast<ash::DriveOperationStatus::OperationType>( | 118 status.type = static_cast<ash::DriveOperationStatus::OperationType>( |
122 it->operation_type); | 119 it->operation_type); |
123 status.state = static_cast<ash::DriveOperationStatus::OperationState>( | 120 status.state = static_cast<ash::DriveOperationStatus::OperationState>( |
124 it->transfer_state); | 121 it->transfer_state); |
(...skipping 20 matching lines...) Expand all Loading... |
145 | 142 |
146 class SystemTrayDelegate : public ash::SystemTrayDelegate, | 143 class SystemTrayDelegate : public ash::SystemTrayDelegate, |
147 public AudioHandler::VolumeObserver, | 144 public AudioHandler::VolumeObserver, |
148 public PowerManagerClient::Observer, | 145 public PowerManagerClient::Observer, |
149 public SessionManagerClient::Observer, | 146 public SessionManagerClient::Observer, |
150 public NetworkMenuIcon::Delegate, | 147 public NetworkMenuIcon::Delegate, |
151 public NetworkMenu::Delegate, | 148 public NetworkMenu::Delegate, |
152 public NetworkLibrary::NetworkManagerObserver, | 149 public NetworkLibrary::NetworkManagerObserver, |
153 public NetworkLibrary::NetworkObserver, | 150 public NetworkLibrary::NetworkObserver, |
154 public NetworkLibrary::CellularDataPlanObserver, | 151 public NetworkLibrary::CellularDataPlanObserver, |
155 public gdata::OperationRegistry::Observer, | 152 public gdata::DriveServiceObserver, |
156 public content::NotificationObserver, | 153 public content::NotificationObserver, |
157 public input_method::InputMethodManager::Observer, | 154 public input_method::InputMethodManager::Observer, |
158 public system::TimezoneSettings::Observer, | 155 public system::TimezoneSettings::Observer, |
159 public BluetoothAdapter::Observer, | 156 public BluetoothAdapter::Observer, |
160 public SystemKeyEventListener::CapsLockObserver, | 157 public SystemKeyEventListener::CapsLockObserver, |
161 public ash::NetworkTrayDelegate { | 158 public ash::NetworkTrayDelegate { |
162 public: | 159 public: |
163 explicit SystemTrayDelegate(ash::SystemTray* tray) | 160 explicit SystemTrayDelegate(ash::SystemTray* tray) |
164 : tray_(tray), | 161 : tray_(tray), |
165 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( | 162 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 } | 232 } |
236 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); | 233 input_method::InputMethodManager::GetInstance()->RemoveObserver(this); |
237 system::TimezoneSettings::GetInstance()->RemoveObserver(this); | 234 system::TimezoneSettings::GetInstance()->RemoveObserver(this); |
238 if (SystemKeyEventListener::GetInstance()) | 235 if (SystemKeyEventListener::GetInstance()) |
239 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); | 236 SystemKeyEventListener::GetInstance()->RemoveCapsLockObserver(this); |
240 bluetooth_adapter_->RemoveObserver(this); | 237 bluetooth_adapter_->RemoveObserver(this); |
241 | 238 |
242 // Stop observing gdata operations. | 239 // Stop observing gdata operations. |
243 DriveSystemService* system_service = FindDriveSystemService(); | 240 DriveSystemService* system_service = FindDriveSystemService(); |
244 if (system_service) { | 241 if (system_service) { |
245 system_service->drive_service()->operation_registry()-> | 242 system_service->drive_service()->RemoveObserver(this); |
246 RemoveObserver(this); | |
247 } | 243 } |
248 } | 244 } |
249 | 245 |
250 // Overridden from ash::SystemTrayDelegate: | 246 // Overridden from ash::SystemTrayDelegate: |
251 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { | 247 virtual bool GetTrayVisibilityOnStartup() OVERRIDE { |
252 // In case of OOBE / sign in screen tray will be shown later. | 248 // In case of OOBE / sign in screen tray will be shown later. |
253 return UserManager::Get()->IsUserLoggedIn(); | 249 return UserManager::Get()->IsUserLoggedIn(); |
254 } | 250 } |
255 | 251 |
256 virtual const string16 GetUserDisplayName() const OVERRIDE { | 252 virtual const string16 GetUserDisplayName() const OVERRIDE { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { | 438 virtual void ActivateIMEProperty(const std::string& key) OVERRIDE { |
443 input_method::InputMethodManager::GetInstance()-> | 439 input_method::InputMethodManager::GetInstance()-> |
444 ActivateInputMethodProperty(key); | 440 ActivateInputMethodProperty(key); |
445 } | 441 } |
446 | 442 |
447 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { | 443 virtual void CancelDriveOperation(const FilePath& file_path) OVERRIDE { |
448 DriveSystemService* system_service = FindDriveSystemService(); | 444 DriveSystemService* system_service = FindDriveSystemService(); |
449 if (!system_service) | 445 if (!system_service) |
450 return; | 446 return; |
451 | 447 |
452 system_service->drive_service()->operation_registry()->CancelForFilePath( | 448 system_service->drive_service()->CancelForFilePath(file_path); |
453 file_path); | |
454 } | 449 } |
455 | 450 |
456 virtual void GetDriveOperationStatusList( | 451 virtual void GetDriveOperationStatusList( |
457 ash::DriveOperationStatusList* list) OVERRIDE { | 452 ash::DriveOperationStatusList* list) OVERRIDE { |
458 DriveSystemService* system_service = FindDriveSystemService(); | 453 DriveSystemService* system_service = FindDriveSystemService(); |
459 if (!system_service) | 454 if (!system_service) |
460 return; | 455 return; |
461 | 456 |
462 *list = GetDriveStatusList( | 457 *list = GetDriveStatusList( |
463 system_service->drive_service()->operation_registry()-> | 458 system_service->drive_service()->GetProgressStatusList()); |
464 GetProgressStatusList()); | |
465 } | 459 } |
466 | 460 |
467 | 461 |
468 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, | 462 virtual void GetMostRelevantNetworkIcon(ash::NetworkIconInfo* info, |
469 bool dark) OVERRIDE { | 463 bool dark) OVERRIDE { |
470 NetworkMenuIcon* icon = | 464 NetworkMenuIcon* icon = |
471 dark ? network_icon_dark_.get() : network_icon_.get(); | 465 dark ? network_icon_dark_.get() : network_icon_.get(); |
472 info->image = icon->GetIconAndText(&info->description); | 466 info->image = icon->GetIconAndText(&info->description); |
473 info->tray_icon_visible = icon->ShouldShowIconInTray(); | 467 info->tray_icon_visible = icon->ShouldShowIconInTray(); |
474 } | 468 } |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 UpdateClockType(profile->GetPrefs()); | 712 UpdateClockType(profile->GetPrefs()); |
719 search_key_mapped_to_ = | 713 search_key_mapped_to_ = |
720 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); | 714 profile->GetPrefs()->GetInteger(prefs::kLanguageXkbRemapSearchKeyTo); |
721 } | 715 } |
722 | 716 |
723 void ObserveGDataUpdates() { | 717 void ObserveGDataUpdates() { |
724 DriveSystemService* system_service = FindDriveSystemService(); | 718 DriveSystemService* system_service = FindDriveSystemService(); |
725 if (!system_service) | 719 if (!system_service) |
726 return; | 720 return; |
727 | 721 |
728 system_service->drive_service()->operation_registry()->AddObserver(this); | 722 system_service->drive_service()->AddObserver(this); |
729 } | 723 } |
730 | 724 |
731 void UpdateClockType(PrefService* service) { | 725 void UpdateClockType(PrefService* service) { |
732 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? | 726 clock_type_ = service->GetBoolean(prefs::kUse24HourClock) ? |
733 base::k24HourClock : base::k12HourClock; | 727 base::k24HourClock : base::k12HourClock; |
734 ash::ClockObserver* observer = tray_->clock_observer(); | 728 ash::ClockObserver* observer = tray_->clock_observer(); |
735 if (observer) | 729 if (observer) |
736 observer->OnDateFormatChanged(); | 730 observer->OnDateFormatChanged(); |
737 } | 731 } |
738 | 732 |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1089 virtual void InputMethodChanged( | 1083 virtual void InputMethodChanged( |
1090 input_method::InputMethodManager* manager, bool show_message) OVERRIDE { | 1084 input_method::InputMethodManager* manager, bool show_message) OVERRIDE { |
1091 NotifyRefreshIME(show_message); | 1085 NotifyRefreshIME(show_message); |
1092 } | 1086 } |
1093 | 1087 |
1094 virtual void InputMethodPropertyChanged( | 1088 virtual void InputMethodPropertyChanged( |
1095 input_method::InputMethodManager* manager) OVERRIDE { | 1089 input_method::InputMethodManager* manager) OVERRIDE { |
1096 NotifyRefreshIME(false); | 1090 NotifyRefreshIME(false); |
1097 } | 1091 } |
1098 | 1092 |
1099 // gdata::OperationRegistry::Observer overrides. | 1093 // gdata::DriveServiceObserver overrides. |
1100 virtual void OnProgressUpdate( | 1094 virtual void OnProgressUpdate( |
1101 const OperationRegistry::ProgressStatusList& list) { | 1095 const gdata::OperationProgressStatusList& list) OVERRIDE { |
1102 std::vector<ash::DriveOperationStatus> ui_list = GetDriveStatusList(list); | 1096 std::vector<ash::DriveOperationStatus> ui_list = GetDriveStatusList(list); |
1103 NotifyRefreshDrive(ui_list); | 1097 NotifyRefreshDrive(ui_list); |
1104 | 1098 |
1105 // If we have something to report right now (i.e. completion status only), | 1099 // If we have something to report right now (i.e. completion status only), |
1106 // we need to delayed re-check the status in few seconds to ensure we | 1100 // we need to delayed re-check the status in few seconds to ensure we |
1107 // raise events that will let us properly clear the uber tray state. | 1101 // raise events that will let us properly clear the uber tray state. |
1108 if (list.size() > 0) { | 1102 if (list.size() > 0) { |
1109 bool has_in_progress_items = false; | 1103 bool has_in_progress_items = false; |
1110 for (OperationRegistry::ProgressStatusList::const_iterator it = | 1104 for (gdata::OperationProgressStatusList::const_iterator it = list.begin(); |
1111 list.begin(); | |
1112 it != list.end(); ++it) { | 1105 it != list.end(); ++it) { |
1113 if (it->transfer_state == | 1106 if (it->transfer_state == gdata::OPERATION_STARTED || |
1114 OperationRegistry::OPERATION_STARTED || | 1107 it->transfer_state == gdata::OPERATION_IN_PROGRESS || |
1115 it->transfer_state == | 1108 it->transfer_state == gdata::OPERATION_SUSPENDED) { |
1116 OperationRegistry::OPERATION_IN_PROGRESS || | |
1117 it->transfer_state == | |
1118 OperationRegistry::OPERATION_SUSPENDED) { | |
1119 has_in_progress_items = true; | 1109 has_in_progress_items = true; |
1120 break; | 1110 break; |
1121 } | 1111 } |
1122 } | 1112 } |
1123 | 1113 |
1124 if (!has_in_progress_items) { | 1114 if (!has_in_progress_items) { |
1125 content::BrowserThread::PostDelayedTask( | 1115 content::BrowserThread::PostDelayedTask( |
1126 content::BrowserThread::UI, | 1116 content::BrowserThread::UI, |
1127 FROM_HERE, | 1117 FROM_HERE, |
1128 base::Bind(&SystemTrayDelegate::RecheckGDataOperations, | 1118 base::Bind(&SystemTrayDelegate::RecheckGDataOperations, |
1129 ui_weak_ptr_factory_->GetWeakPtr()), | 1119 ui_weak_ptr_factory_->GetWeakPtr()), |
1130 base::TimeDelta::FromMilliseconds(kGDataOperationRecheckDelayMs)); | 1120 base::TimeDelta::FromMilliseconds(kGDataOperationRecheckDelayMs)); |
1131 } | 1121 } |
1132 } | 1122 } |
1133 | 1123 |
1134 } | 1124 } |
1135 | 1125 |
1136 // Pulls the list of ongoing drive operations and initiates status update. | 1126 // Pulls the list of ongoing drive operations and initiates status update. |
1137 // This method is needed to ensure delayed cleanup of the latest reported | 1127 // This method is needed to ensure delayed cleanup of the latest reported |
1138 // status in UI in cases when there are no new changes coming (i.e. when the | 1128 // status in UI in cases when there are no new changes coming (i.e. when the |
1139 // last set of transfer operations completed). | 1129 // last set of transfer operations completed). |
1140 void RecheckGDataOperations() { | 1130 void RecheckGDataOperations() { |
1141 DriveSystemService* system_service = FindDriveSystemService(); | 1131 DriveSystemService* system_service = FindDriveSystemService(); |
1142 if (!system_service) | 1132 if (!system_service) |
1143 return; | 1133 return; |
1144 | 1134 |
1145 OnProgressUpdate(system_service->drive_service()->operation_registry()-> | 1135 OnProgressUpdate(system_service->drive_service()->GetProgressStatusList()); |
1146 GetProgressStatusList()); | |
1147 } | 1136 } |
1148 | 1137 |
1149 DriveSystemService* FindDriveSystemService() { | 1138 DriveSystemService* FindDriveSystemService() { |
1150 Profile* profile = ProfileManager::GetDefaultProfile(); | 1139 Profile* profile = ProfileManager::GetDefaultProfile(); |
1151 if (!gdata::util::IsGDataAvailable(profile)) | 1140 if (!gdata::util::IsGDataAvailable(profile)) |
1152 return NULL; | 1141 return NULL; |
1153 return DriveSystemServiceFactory::FindForProfile(profile); | 1142 return DriveSystemServiceFactory::FindForProfile(profile); |
1154 } | 1143 } |
1155 | 1144 |
1156 // Overridden from system::TimezoneSettings::Observer. | 1145 // Overridden from system::TimezoneSettings::Observer. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1264 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); | 1253 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegate); |
1265 }; | 1254 }; |
1266 | 1255 |
1267 } // namespace | 1256 } // namespace |
1268 | 1257 |
1269 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { | 1258 ash::SystemTrayDelegate* CreateSystemTrayDelegate(ash::SystemTray* tray) { |
1270 return new chromeos::SystemTrayDelegate(tray); | 1259 return new chromeos::SystemTrayDelegate(tray); |
1271 } | 1260 } |
1272 | 1261 |
1273 } // namespace chromeos | 1262 } // namespace chromeos |
OLD | NEW |