Commit 9dac0955 authored by yutak's avatar yutak Committed by Commit bot

Revert of ash: Use system tray mojo interface to show system update tray icon...

Revert of ash: Use system tray mojo interface to show system update tray icon (patchset #6 id:100001 of https://codereview.chromium.org/2558043006/ )

Reason for revert:
Broke compile on Google Chrome ChromeOS:

https://build.chromium.org/p/chromium.chrome/builders/Google%20Chrome%20ChromeOS/builds/26896

../../chrome/browser/component_updater/pepper_flash_component_installer.cc:94:3: error: no type named 'SystemTrayClient' in namespace 'chromeos'; did you mean simply 'SystemTrayClient'?
  chromeos::SystemTrayClient* tray = chromeos::SystemTrayClient::Get();
  ^~~~~~~~~~~~~~~~~~~~~~~~~~
  SystemTrayClient
../../chrome/browser/ui/ash/system_tray_client.h:27:7: note: 'SystemTrayClient' declared here
class SystemTrayClient : public ash::mojom::SystemTrayClient,
      ^
../../chrome/browser/component_updater/pepper_flash_component_installer.cc:94:38: error: no member named 'SystemTrayClient' in namespace 'chromeos'; did you mean simply 'SystemTrayClient'?
  chromeos::SystemTrayClient* tray = chromeos::SystemTrayClient::Get();
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
                                     SystemTrayClient
../../chrome/browser/ui/ash/system_tray_client.h:27:7: note: 'SystemTrayClient' declared here
class SystemTrayClient : public ash::mojom::SystemTrayClient,
      ^
2 errors generated.

Original issue's description:
> ash: Use system tray mojo interface to show system update tray icon
>
> Change the flow so that Chrome explicitly asks ash to show the icon
> rather than having ash ask Chrome whether there is an update available.
>
> * Add ShowUpdateIcon to system_tray.mojom
> * Introduce update.mojom
> * Migrate ash to using ash::mojom::UpdateSeverity internally
> * Migrate update methods from SystemTrayDelegate to SystemTrayClient
> * Add a new SystemTrayClientTest and move existing Flash test there
>
> Also add docs for SystemTrayItem (used by TrayUpdate) since tray view
> vs. default view vs. detailed view always confuses me.
>
> BUG=647412
> TEST=chrome browser_tests, ash_unittests
>
> Committed: https://crrev.com/196ee3b66b3700733cecb8472d63d872d99e3783
> Cr-Commit-Position: refs/heads/master@{#438051}

TBR=msw@chromium.org,kerrnel@chromium.org,tsepez@chromium.org,waffles@chromium.org,sky@chromium.org,jamescook@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=647412

Review-Url: https://codereview.chromium.org/2568413002
Cr-Commit-Position: refs/heads/master@{#438064}
parent 82298e59
...@@ -441,6 +441,7 @@ component("ash") { ...@@ -441,6 +441,7 @@ component("ash") {
"common/system/tray_accessibility.h", "common/system/tray_accessibility.h",
"common/system/update/tray_update.cc", "common/system/update/tray_update.cc",
"common/system/update/tray_update.h", "common/system/update/tray_update.h",
"common/system/update/update_observer.h",
"common/system/user/button_from_view.cc", "common/system/user/button_from_view.cc",
"common/system/user/button_from_view.h", "common/system/user/button_from_view.h",
"common/system/user/login_status.cc", "common/system/user/login_status.cc",
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@
#include "ash/common/system/tray/default_system_tray_delegate.h" #include "ash/common/system/tray/default_system_tray_delegate.h"
#include <string> #include <string>
#include <utility>
#include "ash/common/system/networking_config_delegate.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
namespace ash { namespace ash {
...@@ -27,6 +32,13 @@ bool DefaultSystemTrayDelegate::IsUserSupervised() const { ...@@ -27,6 +32,13 @@ bool DefaultSystemTrayDelegate::IsUserSupervised() const {
return GetUserLoginStatus() == LoginStatus::SUPERVISED; return GetUserLoginStatus() == LoginStatus::SUPERVISED;
} }
void DefaultSystemTrayDelegate::GetSystemUpdateInfo(UpdateInfo* info) const {
DCHECK(info);
info->severity = UpdateInfo::UPDATE_NONE;
info->update_required = true;
info->factory_reset_required = false;
}
bool DefaultSystemTrayDelegate::ShouldShowSettings() const { bool DefaultSystemTrayDelegate::ShouldShowSettings() const {
return true; return true;
} }
......
...@@ -20,6 +20,7 @@ class ASH_EXPORT DefaultSystemTrayDelegate : public SystemTrayDelegate { ...@@ -20,6 +20,7 @@ class ASH_EXPORT DefaultSystemTrayDelegate : public SystemTrayDelegate {
LoginStatus GetUserLoginStatus() const override; LoginStatus GetUserLoginStatus() const override;
std::string GetSupervisedUserManager() const override; std::string GetSupervisedUserManager() const override;
bool IsUserSupervised() const override; bool IsUserSupervised() const override;
void GetSystemUpdateInfo(UpdateInfo* info) const override;
bool ShouldShowSettings() const override; bool ShouldShowSettings() const override;
bool ShouldShowNotificationTray() const override; bool ShouldShowNotificationTray() const override;
void ToggleBluetooth() override; void ToggleBluetooth() override;
......
...@@ -822,6 +822,10 @@ TrayTiles* SystemTray::GetTrayTilesForTesting() const { ...@@ -822,6 +822,10 @@ TrayTiles* SystemTray::GetTrayTilesForTesting() const {
return tray_tiles_; return tray_tiles_;
} }
TrayUpdate* SystemTray::GetTrayUpdateForTesting() const {
return tray_update_;
}
void SystemTray::CloseBubble(const ui::KeyEvent& key_event) { void SystemTray::CloseBubble(const ui::KeyEvent& key_event) {
CloseSystemBubble(); CloseSystemBubble();
} }
......
...@@ -47,8 +47,6 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView, ...@@ -47,8 +47,6 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView,
explicit SystemTray(WmShelf* wm_shelf); explicit SystemTray(WmShelf* wm_shelf);
~SystemTray() override; ~SystemTray() override;
TrayUpdate* tray_update() { return tray_update_; }
// Calls TrayBackgroundView::Initialize(), creates the tray items, and // Calls TrayBackgroundView::Initialize(), creates the tray items, and
// adds them to SystemTrayNotifier. // adds them to SystemTrayNotifier.
void InitializeTrayItems(SystemTrayDelegate* delegate, void InitializeTrayItems(SystemTrayDelegate* delegate,
...@@ -170,6 +168,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView, ...@@ -170,6 +168,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView,
TrayNetwork* GetTrayNetworkForTesting() const; TrayNetwork* GetTrayNetworkForTesting() const;
TraySystemInfo* GetTraySystemInfoForTesting() const; TraySystemInfo* GetTraySystemInfoForTesting() const;
TrayTiles* GetTrayTilesForTesting() const; TrayTiles* GetTrayTilesForTesting() const;
TrayUpdate* GetTrayUpdateForTesting() const;
// Activates the system tray bubble. // Activates the system tray bubble.
void ActivateBubble(); void ActivateBubble();
......
...@@ -4,12 +4,8 @@ ...@@ -4,12 +4,8 @@
#include "ash/common/system/tray/system_tray_controller.h" #include "ash/common/system/tray/system_tray_controller.h"
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_notifier.h" #include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/update/tray_update.h"
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h" #include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
namespace ash { namespace ash {
...@@ -132,16 +128,4 @@ void SystemTrayController::SetUse24HourClock(bool use_24_hour) { ...@@ -132,16 +128,4 @@ void SystemTrayController::SetUse24HourClock(bool use_24_hour) {
WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged(); WmShell::Get()->system_tray_notifier()->NotifyDateFormatChanged();
} }
void SystemTrayController::ShowUpdateIcon(mojom::UpdateSeverity severity,
bool factory_reset_required) {
// Show the icon on all displays.
for (WmWindow* root : WmShell::Get()->GetAllRootWindows()) {
ash::SystemTray* tray = root->GetRootWindowController()->GetSystemTray();
// External monitors might not have a tray yet.
if (!tray)
continue;
tray->tray_update()->ShowUpdateIcon(severity, factory_reset_required);
}
}
} // namespace ash } // namespace ash
...@@ -56,13 +56,11 @@ class ASH_EXPORT SystemTrayController ...@@ -56,13 +56,11 @@ class ASH_EXPORT SystemTrayController
// Binds the mojom::SystemTray interface to this object. // Binds the mojom::SystemTray interface to this object.
void BindRequest(mojom::SystemTrayRequest request); void BindRequest(mojom::SystemTrayRequest request);
// mojom::SystemTray overrides. Public for testing. private:
// mojom::SystemTray:
void SetClient(mojom::SystemTrayClientPtr client) override; void SetClient(mojom::SystemTrayClientPtr client) override;
void SetUse24HourClock(bool use_24_hour) override; void SetUse24HourClock(bool use_24_hour) override;
void ShowUpdateIcon(mojom::UpdateSeverity severity,
bool factory_reset_required) override;
private:
// Client interface in chrome browser. Only bound on Chrome OS. // Client interface in chrome browser. Only bound on Chrome OS.
mojom::SystemTrayClientPtr system_tray_client_; mojom::SystemTrayClientPtr system_tray_client_;
......
...@@ -17,6 +17,13 @@ BluetoothDeviceInfo::BluetoothDeviceInfo(const BluetoothDeviceInfo& other) = ...@@ -17,6 +17,13 @@ BluetoothDeviceInfo::BluetoothDeviceInfo(const BluetoothDeviceInfo& other) =
BluetoothDeviceInfo::~BluetoothDeviceInfo() {} BluetoothDeviceInfo::~BluetoothDeviceInfo() {}
UpdateInfo::UpdateInfo()
: severity(UPDATE_NONE),
update_required(false),
factory_reset_required(false) {}
UpdateInfo::~UpdateInfo() {}
SystemTrayDelegate::SystemTrayDelegate() {} SystemTrayDelegate::SystemTrayDelegate() {}
SystemTrayDelegate::~SystemTrayDelegate() {} SystemTrayDelegate::~SystemTrayDelegate() {}
...@@ -59,6 +66,12 @@ bool SystemTrayDelegate::IsUserChild() const { ...@@ -59,6 +66,12 @@ bool SystemTrayDelegate::IsUserChild() const {
return false; return false;
} }
void SystemTrayDelegate::GetSystemUpdateInfo(UpdateInfo* info) const {
info->severity = UpdateInfo::UPDATE_NONE;
info->update_required = false;
info->factory_reset_required = false;
}
bool SystemTrayDelegate::ShouldShowSettings() const { bool SystemTrayDelegate::ShouldShowSettings() const {
return false; return false;
} }
......
...@@ -51,6 +51,24 @@ struct ASH_EXPORT BluetoothDeviceInfo { ...@@ -51,6 +51,24 @@ struct ASH_EXPORT BluetoothDeviceInfo {
using BluetoothDeviceList = std::vector<BluetoothDeviceInfo>; using BluetoothDeviceList = std::vector<BluetoothDeviceInfo>;
struct ASH_EXPORT UpdateInfo {
enum UpdateSeverity {
UPDATE_NONE,
UPDATE_LOW,
UPDATE_ELEVATED,
UPDATE_HIGH,
UPDATE_SEVERE,
UPDATE_CRITICAL,
};
UpdateInfo();
~UpdateInfo();
UpdateSeverity severity;
bool update_required;
bool factory_reset_required;
};
class NetworkingConfigDelegate; class NetworkingConfigDelegate;
// SystemTrayDelegate is intended for delegating tasks in the System Tray to the // SystemTrayDelegate is intended for delegating tasks in the System Tray to the
...@@ -105,6 +123,9 @@ class ASH_EXPORT SystemTrayDelegate { ...@@ -105,6 +123,9 @@ class ASH_EXPORT SystemTrayDelegate {
// crbug.com/443119 // crbug.com/443119
virtual bool IsUserChild() const; virtual bool IsUserChild() const;
// Fills |info| structure (which must not be null) with current update info.
virtual void GetSystemUpdateInfo(UpdateInfo* info) const;
// Returns true if settings menu item should appear. // Returns true if settings menu item should appear.
virtual bool ShouldShowSettings() const; virtual bool ShouldShowSettings() const;
......
...@@ -25,10 +25,6 @@ class SystemTray; ...@@ -25,10 +25,6 @@ class SystemTray;
class SystemTrayBubble; class SystemTrayBubble;
class TrayItemView; class TrayItemView;
// Controller for an item in the system tray. Each item can create these views:
// Tray view - The icon in the status area in the shelf.
// Default view - The row in the top-level menu.
// Detailed view - The submenu shown when the top-level menu row is clicked.
class ASH_EXPORT SystemTrayItem { class ASH_EXPORT SystemTrayItem {
public: public:
// The different types of SystemTrayItems. // The different types of SystemTrayItems.
...@@ -91,7 +87,6 @@ class ASH_EXPORT SystemTrayItem { ...@@ -91,7 +87,6 @@ class ASH_EXPORT SystemTrayItem {
// Returns a notification view for the item. This view is displayed with // Returns a notification view for the item. This view is displayed with
// other notifications and should be the same size as default views. // other notifications and should be the same size as default views.
// DEPRECATED. Use the message center instead.
virtual views::View* CreateNotificationView(LoginStatus status); virtual views::View* CreateNotificationView(LoginStatus status);
// These functions are called when the corresponding view item is about to be // These functions are called when the corresponding view item is about to be
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/common/system/accessibility_observer.h" #include "ash/common/system/accessibility_observer.h"
#include "ash/common/system/date/clock_observer.h" #include "ash/common/system/date/clock_observer.h"
#include "ash/common/system/ime/ime_observer.h" #include "ash/common/system/ime/ime_observer.h"
#include "ash/common/system/update/update_observer.h"
#include "ash/common/system/user/user_observer.h" #include "ash/common/system/user/user_observer.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -91,6 +92,19 @@ void SystemTrayNotifier::NotifyRefreshIMEMenu(bool is_active) { ...@@ -91,6 +92,19 @@ void SystemTrayNotifier::NotifyRefreshIMEMenu(bool is_active) {
observer.OnIMEMenuActivationChanged(is_active); observer.OnIMEMenuActivationChanged(is_active);
} }
void SystemTrayNotifier::AddUpdateObserver(UpdateObserver* observer) {
update_observers_.AddObserver(observer);
}
void SystemTrayNotifier::RemoveUpdateObserver(UpdateObserver* observer) {
update_observers_.RemoveObserver(observer);
}
void SystemTrayNotifier::NotifyUpdateRecommended(const UpdateInfo& info) {
for (auto& observer : update_observers_)
observer.OnUpdateRecommended(info);
}
void SystemTrayNotifier::AddUserObserver(UserObserver* observer) { void SystemTrayNotifier::AddUserObserver(UserObserver* observer) {
user_observers_.AddObserver(observer); user_observers_.AddObserver(observer);
} }
......
...@@ -22,6 +22,8 @@ namespace ash { ...@@ -22,6 +22,8 @@ namespace ash {
class AccessibilityObserver; class AccessibilityObserver;
class ClockObserver; class ClockObserver;
class IMEObserver; class IMEObserver;
struct UpdateInfo;
class UpdateObserver;
class UserObserver; class UserObserver;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -38,10 +40,6 @@ class TracingObserver; ...@@ -38,10 +40,6 @@ class TracingObserver;
class VirtualKeyboardObserver; class VirtualKeyboardObserver;
#endif #endif
namespace mojom {
enum class UpdateSeverity;
}
// Observer and notification manager for the ash system tray. // Observer and notification manager for the ash system tray.
class ASH_EXPORT SystemTrayNotifier { class ASH_EXPORT SystemTrayNotifier {
public: public:
...@@ -68,6 +66,11 @@ class ASH_EXPORT SystemTrayNotifier { ...@@ -68,6 +66,11 @@ class ASH_EXPORT SystemTrayNotifier {
void NotifyRefreshIME(); void NotifyRefreshIME();
void NotifyRefreshIMEMenu(bool is_active); void NotifyRefreshIMEMenu(bool is_active);
// OS updates.
void AddUpdateObserver(UpdateObserver* observer);
void RemoveUpdateObserver(UpdateObserver* observer);
void NotifyUpdateRecommended(const UpdateInfo& info);
// User. // User.
void AddUserObserver(UserObserver* observer); void AddUserObserver(UserObserver* observer);
void RemoveUserObserver(UserObserver* observer); void RemoveUserObserver(UserObserver* observer);
...@@ -144,6 +147,7 @@ class ASH_EXPORT SystemTrayNotifier { ...@@ -144,6 +147,7 @@ class ASH_EXPORT SystemTrayNotifier {
base::ObserverList<AccessibilityObserver> accessibility_observers_; base::ObserverList<AccessibilityObserver> accessibility_observers_;
base::ObserverList<ClockObserver> clock_observers_; base::ObserverList<ClockObserver> clock_observers_;
base::ObserverList<IMEObserver> ime_observers_; base::ObserverList<IMEObserver> ime_observers_;
base::ObserverList<UpdateObserver> update_observers_;
base::ObserverList<UserObserver> user_observers_; base::ObserverList<UserObserver> user_observers_;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -17,7 +17,6 @@ class ImageView; ...@@ -17,7 +17,6 @@ class ImageView;
namespace ash { namespace ash {
class TrayItemView; class TrayItemView;
// A system tray item that uses an image as its "tray view" in the status area.
class ASH_EXPORT TrayImageItem : public SystemTrayItem { class ASH_EXPORT TrayImageItem : public SystemTrayItem {
public: public:
TrayImageItem(SystemTray* system_tray, int resource_id, UmaType uma_type); TrayImageItem(SystemTray* system_tray, int resource_id, UmaType uma_type);
...@@ -58,7 +57,6 @@ class ASH_EXPORT TrayImageItem : public SystemTrayItem { ...@@ -58,7 +57,6 @@ class ASH_EXPORT TrayImageItem : public SystemTrayItem {
// The color of the material design icon in the tray. // The color of the material design icon in the tray.
SkColor icon_color_; SkColor icon_color_;
// The image view in the tray.
TrayItemView* tray_view_; TrayItemView* tray_view_;
DISALLOW_COPY_AND_ASSIGN(TrayImageItem); DISALLOW_COPY_AND_ASSIGN(TrayImageItem);
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include "ash/common/system/tray/system_tray.h" #include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_controller.h" #include "ash/common/system/tray/system_tray_controller.h"
#include "ash/common/system/tray/system_tray_delegate.h" #include "ash/common/system/tray/system_tray_delegate.h"
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/tray/tray_constants.h" #include "ash/common/system/tray/tray_constants.h"
#include "ash/common/system/tray/tray_popup_item_style.h" #include "ash/common/system/tray/tray_popup_item_style.h"
#include "ash/common/system/tray/tray_popup_utils.h" #include "ash/common/system/tray/tray_popup_utils.h"
#include "ash/common/wm_shell.h" #include "ash/common/wm_shell.h"
#include "ash/public/interfaces/update.mojom.h"
#include "ash/resources/vector_icons/vector_icons.h" #include "ash/resources/vector_icons/vector_icons.h"
#include "grit/ash_resources.h" #include "grit/ash_resources.h"
#include "grit/ash_strings.h" #include "grit/ash_strings.h"
...@@ -33,22 +33,22 @@ namespace { ...@@ -33,22 +33,22 @@ namespace {
// severity. // severity.
// TODO(tdanderson): This is only used for non-material design, so remove it // TODO(tdanderson): This is only used for non-material design, so remove it
// when material design is the default. See crbug.com/625692. // when material design is the default. See crbug.com/625692.
int DecideResource(mojom::UpdateSeverity severity, bool dark) { int DecideResource(UpdateInfo::UpdateSeverity severity, bool dark) {
switch (severity) { switch (severity) {
case mojom::UpdateSeverity::NONE: case UpdateInfo::UPDATE_NONE:
case mojom::UpdateSeverity::LOW: case UpdateInfo::UPDATE_LOW:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE; return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK : IDR_AURA_UBER_TRAY_UPDATE;
case mojom::UpdateSeverity::ELEVATED: case UpdateInfo::UPDATE_ELEVATED:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_GREEN
: IDR_AURA_UBER_TRAY_UPDATE_GREEN; : IDR_AURA_UBER_TRAY_UPDATE_GREEN;
case mojom::UpdateSeverity::HIGH: case UpdateInfo::UPDATE_HIGH:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_ORANGE
: IDR_AURA_UBER_TRAY_UPDATE_ORANGE; : IDR_AURA_UBER_TRAY_UPDATE_ORANGE;
case mojom::UpdateSeverity::SEVERE: case UpdateInfo::UPDATE_SEVERE:
case mojom::UpdateSeverity::CRITICAL: case UpdateInfo::UPDATE_CRITICAL:
return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED return dark ? IDR_AURA_UBER_TRAY_UPDATE_DARK_RED
: IDR_AURA_UBER_TRAY_UPDATE_RED; : IDR_AURA_UBER_TRAY_UPDATE_RED;
} }
...@@ -60,19 +60,19 @@ int DecideResource(mojom::UpdateSeverity severity, bool dark) { ...@@ -60,19 +60,19 @@ int DecideResource(mojom::UpdateSeverity severity, bool dark) {
// Returns the color to use for the material design update icon when the update // Returns the color to use for the material design update icon when the update
// severity is |severity|. If |for_menu| is true, the icon color for the system // severity is |severity|. If |for_menu| is true, the icon color for the system
// menu is given, otherwise the icon color for the system tray is given. // menu is given, otherwise the icon color for the system tray is given.
SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, SkColor IconColorForUpdateSeverity(UpdateInfo::UpdateSeverity severity,
bool for_menu) { bool for_menu) {
const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor; const SkColor default_color = for_menu ? kMenuIconColor : kTrayIconColor;
switch (severity) { switch (severity) {
case mojom::UpdateSeverity::NONE: case UpdateInfo::UPDATE_NONE:
return default_color; return default_color;
case mojom::UpdateSeverity::LOW: case UpdateInfo::UPDATE_LOW:
return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor; return for_menu ? gfx::kGoogleGreen700 : kTrayIconColor;
case mojom::UpdateSeverity::ELEVATED: case UpdateInfo::UPDATE_ELEVATED:
return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300; return for_menu ? gfx::kGoogleYellow700 : gfx::kGoogleYellow300;
case mojom::UpdateSeverity::HIGH: case UpdateInfo::UPDATE_HIGH:
case mojom::UpdateSeverity::SEVERE: case UpdateInfo::UPDATE_SEVERE:
case mojom::UpdateSeverity::CRITICAL: case UpdateInfo::UPDATE_CRITICAL:
return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300; return for_menu ? gfx::kGoogleRed700 : gfx::kGoogleRed300;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -81,19 +81,9 @@ SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity, ...@@ -81,19 +81,9 @@ SkColor IconColorForUpdateSeverity(mojom::UpdateSeverity severity,
return default_color; return default_color;
} }
} // namespace class UpdateView : public ActionableView {
// static
bool TrayUpdate::update_required_ = false;
// static
mojom::UpdateSeverity TrayUpdate::severity_ = mojom::UpdateSeverity::NONE;
// static
bool TrayUpdate::factory_reset_required_ = false;
// The "restart to update" item in the system tray menu.
class TrayUpdate::UpdateView : public ActionableView {
public: public:
explicit UpdateView(TrayUpdate* owner) UpdateView(SystemTrayItem* owner, const UpdateInfo& info)
: ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS), : ActionableView(owner, TrayPopupInkDropStyle::FILL_BOUNDS),
label_(nullptr) { label_(nullptr) {
SetLayoutManager(new views::FillLayout); SetLayoutManager(new views::FillLayout);
...@@ -105,16 +95,15 @@ class TrayUpdate::UpdateView : public ActionableView { ...@@ -105,16 +95,15 @@ class TrayUpdate::UpdateView : public ActionableView {
if (MaterialDesignController::IsSystemTrayMenuMaterial()) { if (MaterialDesignController::IsSystemTrayMenuMaterial()) {
image->SetImage(gfx::CreateVectorIcon( image->SetImage(gfx::CreateVectorIcon(
kSystemMenuUpdateIcon, kSystemMenuUpdateIcon,
IconColorForUpdateSeverity(owner->severity_, true))); IconColorForUpdateSeverity(info.severity, true)));
} else { } else {
image->SetImage( image->SetImage(bundle.GetImageNamed(DecideResource(info.severity, true))
bundle.GetImageNamed(DecideResource(owner->severity_, true)) .ToImageSkia());
.ToImageSkia());
} }
tri_view->AddView(TriView::Container::START, image); tri_view->AddView(TriView::Container::START, image);
base::string16 label_text = base::string16 label_text =
owner->factory_reset_required_ info.factory_reset_required
? bundle.GetLocalizedString( ? bundle.GetLocalizedString(
IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE) IDS_ASH_STATUS_TRAY_RESTART_AND_POWERWASH_TO_UPDATE)
: bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE); : bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_UPDATE);
...@@ -160,33 +149,34 @@ class TrayUpdate::UpdateView : public ActionableView { ...@@ -160,33 +149,34 @@ class TrayUpdate::UpdateView : public ActionableView {
DISALLOW_COPY_AND_ASSIGN(UpdateView); DISALLOW_COPY_AND_ASSIGN(UpdateView);
}; };
} // namespace
TrayUpdate::TrayUpdate(SystemTray* system_tray) TrayUpdate::TrayUpdate(SystemTray* system_tray)
: TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {} : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_UPDATE, UMA_UPDATE) {
WmShell::Get()->system_tray_notifier()->AddUpdateObserver(this);
}
TrayUpdate::~TrayUpdate() {} TrayUpdate::~TrayUpdate() {
WmShell::Get()->system_tray_notifier()->RemoveUpdateObserver(this);
}
bool TrayUpdate::GetInitialVisibility() { bool TrayUpdate::GetInitialVisibility() {
// If chrome tells ash there is an update available before this item's system UpdateInfo info;
// tray is constructed then show the icon. WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
return update_required_; return info.update_required;
} }
views::View* TrayUpdate::CreateDefaultView(LoginStatus status) { views::View* TrayUpdate::CreateDefaultView(LoginStatus status) {
return update_required_ ? new UpdateView(this) : nullptr; UpdateInfo info;
WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&info);
return info.update_required ? new UpdateView(this, info) : nullptr;
} }
void TrayUpdate::ShowUpdateIcon(mojom::UpdateSeverity severity, void TrayUpdate::OnUpdateRecommended(const UpdateInfo& info) {
bool factory_reset_required) {
// Cache update info so we can create the default view when the menu opens.
update_required_ = true;
severity_ = severity;
factory_reset_required_ = factory_reset_required;
// Show the icon in the tray.
if (MaterialDesignController::UseMaterialDesignSystemIcons()) if (MaterialDesignController::UseMaterialDesignSystemIcons())
SetIconColor(IconColorForUpdateSeverity(severity_, false)); SetIconColor(IconColorForUpdateSeverity(info.severity, false));
else else
SetImageFromResourceId(DecideResource(severity_, false)); SetImageFromResourceId(DecideResource(info.severity, false));
tray_view()->SetVisible(true); tray_view()->SetVisible(true);
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/common/system/tray/tray_image_item.h" #include "ash/common/system/tray/tray_image_item.h"
#include "ash/common/system/update/update_observer.h"
#include "base/macros.h" #include "base/macros.h"
namespace views { namespace views {
...@@ -15,37 +16,19 @@ class View; ...@@ -15,37 +16,19 @@ class View;
namespace ash { namespace ash {
namespace mojom { // The system update tray item. Exported for test.
enum class UpdateSeverity; class ASH_EXPORT TrayUpdate : public TrayImageItem, public UpdateObserver {
}
// The system update tray item. The tray icon stays visible once an update
// notification is received. The icon only disappears after a reboot to apply
// the update. Exported for test.
class ASH_EXPORT TrayUpdate : public TrayImageItem {
public: public:
explicit TrayUpdate(SystemTray* system_tray); explicit TrayUpdate(SystemTray* system_tray);
~TrayUpdate() override; ~TrayUpdate() override;
// Shows an icon in the system tray indicating that a software update is
// available. Once shown the icon persists until reboot. |severity| and
// |factory_reset_required| are used to set the icon, color, and tooltip.
void ShowUpdateIcon(mojom::UpdateSeverity severity,
bool factory_reset_required);
private: private:
class UpdateView;
// Overridden from TrayImageItem. // Overridden from TrayImageItem.
bool GetInitialVisibility() override; bool GetInitialVisibility() override;
views::View* CreateDefaultView(LoginStatus status) override; views::View* CreateDefaultView(LoginStatus status) override;
// If an external monitor is connected then the system tray may be created // Overridden from UpdateObserver.
// after the update data is sent from chrome, so share the update info between void OnUpdateRecommended(const UpdateInfo& info) override;
// all instances.
static bool update_required_;
static mojom::UpdateSeverity severity_;
static bool factory_reset_required_;
DISALLOW_COPY_AND_ASSIGN(TrayUpdate); DISALLOW_COPY_AND_ASSIGN(TrayUpdate);
}; };
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
#include "ash/common/system/update/tray_update.h" #include "ash/common/system/update/tray_update.h"
#include "ash/common/system/tray/system_tray.h" #include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/tray/system_tray_controller.h" #include "ash/common/system/tray/system_tray_delegate.h"
#include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/test/ash_test.h" #include "ash/common/test/ash_test.h"
#include "ash/common/wm_shell.h" #include "ash/common/wm_shell.h"
#include "ash/public/interfaces/update.mojom.h"
namespace ash { namespace ash {
...@@ -17,14 +17,20 @@ using TrayUpdateTest = AshTest; ...@@ -17,14 +17,20 @@ using TrayUpdateTest = AshTest;
// Tests that the update icon becomes visible when an update becomes // Tests that the update icon becomes visible when an update becomes
// available. // available.
TEST_F(TrayUpdateTest, VisibilityAfterUpdate) { TEST_F(TrayUpdateTest, VisibilityAfterUpdate) {
TrayUpdate* tray_update = GetPrimarySystemTray()->tray_update(); TrayUpdate* tray_update = GetPrimarySystemTray()->GetTrayUpdateForTesting();
// The system starts with no update pending, so the icon isn't visible. // The system starts with no update pending.
UpdateInfo initial_info;
WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&initial_info);
EXPECT_FALSE(initial_info.update_required);
// When no update is pending, the item isn't visible.
EXPECT_FALSE(tray_update->tray_view()->visible()); EXPECT_FALSE(tray_update->tray_view()->visible());
// Simulate an update. // Simulate an update.
WmShell::Get()->system_tray_controller()->ShowUpdateIcon( UpdateInfo info;
mojom::UpdateSeverity::LOW, false); info.update_required = true;
WmShell::Get()->system_tray_notifier()->NotifyUpdateRecommended(info);
// Tray item is now visible. // Tray item is now visible.
EXPECT_TRUE(tray_update->tray_view()->visible()); EXPECT_TRUE(tray_update->tray_view()->visible());
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_COMMON_SYSTEM_UPDATE_UPDATE_OBSERVER_H_
#define ASH_COMMON_SYSTEM_UPDATE_UPDATE_OBSERVER_H_
#include "ash/ash_export.h"
namespace ash {
struct UpdateInfo;
class ASH_EXPORT UpdateObserver {
public:
virtual ~UpdateObserver() {}
virtual void OnUpdateRecommended(const UpdateInfo& info) = 0;
};
} // namespace ash
#endif // ASH_COMMON_SYSTEM_UPDATE_UPDATE_OBSERVER_H_
...@@ -16,6 +16,7 @@ namespace test { ...@@ -16,6 +16,7 @@ namespace test {
namespace { namespace {
bool g_system_update_required = false;
LoginStatus g_initial_status = LoginStatus::USER; LoginStatus g_initial_status = LoginStatus::USER;
} // namespace } // namespace
...@@ -70,6 +71,13 @@ bool TestSystemTrayDelegate::IsUserSupervised() const { ...@@ -70,6 +71,13 @@ bool TestSystemTrayDelegate::IsUserSupervised() const {
return login_status_ == LoginStatus::SUPERVISED; return login_status_ == LoginStatus::SUPERVISED;
} }
void TestSystemTrayDelegate::GetSystemUpdateInfo(UpdateInfo* info) const {
DCHECK(info);
info->severity = UpdateInfo::UPDATE_NONE;
info->update_required = g_system_update_required;
info->factory_reset_required = false;
}
bool TestSystemTrayDelegate::GetSessionStartTime( bool TestSystemTrayDelegate::GetSessionStartTime(
base::TimeTicks* session_start_time) { base::TimeTicks* session_start_time) {
// Just returns TimeTicks::Now(), so the remaining time is always the // Just returns TimeTicks::Now(), so the remaining time is always the
......
...@@ -41,6 +41,7 @@ class TestSystemTrayDelegate : public DefaultSystemTrayDelegate { ...@@ -41,6 +41,7 @@ class TestSystemTrayDelegate : public DefaultSystemTrayDelegate {
// Overridden from SystemTrayDelegate: // Overridden from SystemTrayDelegate:
LoginStatus GetUserLoginStatus() const override; LoginStatus GetUserLoginStatus() const override;
bool IsUserSupervised() const override; bool IsUserSupervised() const override;
void GetSystemUpdateInfo(UpdateInfo* info) const override;
bool GetSessionStartTime(base::TimeTicks* session_start_time) override; bool GetSessionStartTime(base::TimeTicks* session_start_time) override;
bool GetSessionLengthLimit(base::TimeDelta* session_length_limit) override; bool GetSessionLengthLimit(base::TimeDelta* session_length_limit) override;
void GetCurrentIME(IMEInfo* info) override; void GetCurrentIME(IMEInfo* info) override;
......
...@@ -17,7 +17,6 @@ mojom("interfaces") { ...@@ -17,7 +17,6 @@ mojom("interfaces") {
"shutdown.mojom", "shutdown.mojom",
"system_tray.mojom", "system_tray.mojom",
"touch_view.mojom", "touch_view.mojom",
"update.mojom",
"volume.mojom", "volume.mojom",
"vpn_list.mojom", "vpn_list.mojom",
"wallpaper.mojom", "wallpaper.mojom",
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
module ash.mojom; module ash.mojom;
import "ash/public/interfaces/update.mojom";
// Allows clients (e.g. Chrome browser) to control the ash system tray menu. // Allows clients (e.g. Chrome browser) to control the ash system tray menu.
interface SystemTray { interface SystemTray {
// Sets the client interface. // Sets the client interface.
...@@ -14,11 +12,6 @@ interface SystemTray { ...@@ -14,11 +12,6 @@ interface SystemTray {
// Sets the clock to use 24 hour time formatting if |use_24_hour| is true. // Sets the clock to use 24 hour time formatting if |use_24_hour| is true.
// Otherwise sets 12 hour time formatting. // Otherwise sets 12 hour time formatting.
SetUse24HourClock(bool use_24_hour); SetUse24HourClock(bool use_24_hour);
// Shows an icon in the system tray indicating that a software update is
// available. Once shown the icon persists until reboot. |severity| and
// |factory_reset_required| are used to set the icon, color, and tooltip.
ShowUpdateIcon(UpdateSeverity severity, bool factory_reset_required);
}; };
// Allows ash system tray to control a client (e.g. Chrome browser). Requests // Allows ash system tray to control a client (e.g. Chrome browser). Requests
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module ash.mojom;
// Urgency of a pending software update. Sets the system tray update icon color.
// TODO(jamescook): UpgradeDetector::UpgradeNotificationAnnoyanceLevel could be
// replaced with this if this moves into a component shared with non-ash chrome.
enum UpdateSeverity {
NONE,
LOW,
ELEVATED,
HIGH,
SEVERE,
CRITICAL,
};
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/ui/ash/system_tray_client.h" #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chromeos/dbus/dbus_method_call_status.h" #include "chromeos/dbus/dbus_method_call_status.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
...@@ -91,7 +91,8 @@ void LogRegistrationResult(chromeos::DBusMethodCallStatus call_status, ...@@ -91,7 +91,8 @@ void LogRegistrationResult(chromeos::DBusMethodCallStatus call_status,
LOG(ERROR) << "Component flash registration failed"; LOG(ERROR) << "Component flash registration failed";
return; return;
} }
chromeos::SystemTrayClient* tray = chromeos::SystemTrayClient::Get(); chromeos::SystemTrayDelegateChromeOS* tray =
chromeos::SystemTrayDelegateChromeOS::instance();
if (tray) { if (tray) {
tray->SetFlashUpdateAvailable(); tray->SetFlashUpdateAvailable();
} }
......
...@@ -1394,6 +1394,8 @@ split_static_library("ui") { ...@@ -1394,6 +1394,8 @@ split_static_library("ui") {
"ash/session_util.h", "ash/session_util.h",
"ash/system_tray_delegate_chromeos.cc", "ash/system_tray_delegate_chromeos.cc",
"ash/system_tray_delegate_chromeos.h", "ash/system_tray_delegate_chromeos.h",
"ash/system_tray_delegate_utils.cc",
"ash/system_tray_delegate_utils.h",
"ash/volume_controller.cc", "ash/volume_controller.cc",
"ash/volume_controller.h", "ash/volume_controller.h",
"ash/vpn_list_forwarder.cc", "ash/vpn_list_forwarder.cc",
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/accessibility/accessibility_util.h" #include "chrome/browser/chromeos/accessibility/accessibility_util.h"
#include "chrome/browser/chromeos/login/ui/login_display_host.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h"
#include "chrome/browser/chromeos/options/network_config_view.h" #include "chrome/browser/chromeos/options/network_config_view.h"
...@@ -27,13 +26,11 @@ ...@@ -27,13 +26,11 @@
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/singleton_tabs.h" #include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager_client.h" #include "chromeos/dbus/session_manager_client.h"
#include "chromeos/login/login_state.h" #include "chromeos/login/login_state.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "extensions/browser/api/vpn_provider/vpn_service.h" #include "extensions/browser/api/vpn_provider/vpn_service.h"
...@@ -62,26 +59,6 @@ void ShowSettingsSubPageForActiveUser(const std::string& sub_page) { ...@@ -62,26 +59,6 @@ void ShowSettingsSubPageForActiveUser(const std::string& sub_page) {
sub_page); sub_page);
} }
// Returns the severity of a pending Chrome / Chrome OS update.
ash::mojom::UpdateSeverity GetUpdateSeverity(UpgradeDetector* detector) {
switch (detector->upgrade_notification_stage()) {
case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
return ash::mojom::UpdateSeverity::NONE;
case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
return ash::mojom::UpdateSeverity::LOW;
case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
return ash::mojom::UpdateSeverity::ELEVATED;
case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
return ash::mojom::UpdateSeverity::HIGH;
case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
return ash::mojom::UpdateSeverity::SEVERE;
case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
return ash::mojom::UpdateSeverity::CRITICAL;
}
NOTREACHED();
return ash::mojom::UpdateSeverity::CRITICAL;
}
} // namespace } // namespace
SystemTrayClient::SystemTrayClient() : binding_(this) { SystemTrayClient::SystemTrayClient() : binding_(this) {
...@@ -95,13 +72,6 @@ SystemTrayClient::SystemTrayClient() : binding_(this) { ...@@ -95,13 +72,6 @@ SystemTrayClient::SystemTrayClient() : binding_(this) {
// be queued on |system_tray_|. // be queued on |system_tray_|.
g_browser_process->platform_part()->GetSystemClock()->AddObserver(this); g_browser_process->platform_part()->GetSystemClock()->AddObserver(this);
registrar_.Add(this, chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
content::NotificationService::AllSources());
// If an upgrade is available at startup then tell ash about it.
if (UpgradeDetector::GetInstance()->notify_upgrade())
HandleUpdateAvailable();
DCHECK(!g_instance); DCHECK(!g_instance);
g_instance = this; g_instance = this;
} }
...@@ -197,11 +167,6 @@ Widget* SystemTrayClient::CreateUnownedDialogWidget( ...@@ -197,11 +167,6 @@ Widget* SystemTrayClient::CreateUnownedDialogWidget(
return widget; return widget;
} }
void SystemTrayClient::SetFlashUpdateAvailable() {
flash_update_available_ = true;
HandleUpdateAvailable();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// ash::mojom::SystemTrayClient: // ash::mojom::SystemTrayClient:
...@@ -344,27 +309,17 @@ void SystemTrayClient::SignOut() { ...@@ -344,27 +309,17 @@ void SystemTrayClient::SignOut() {
} }
void SystemTrayClient::RequestRestartForUpdate() { void SystemTrayClient::RequestRestartForUpdate() {
// Flash updates on Chrome OS require device reboot. bool component_update = false;
const chrome::RebootPolicy reboot_policy = chromeos::SystemTrayDelegateChromeOS* tray =
flash_update_available_ ? chrome::RebootPolicy::kForceReboot chromeos::SystemTrayDelegateChromeOS::instance();
: chrome::RebootPolicy::kOptionalReboot; if (tray)
component_update = tray->GetFlashUpdateAvailable();
chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy); chrome::RebootPolicy reboot_policy =
} component_update ? chrome::RebootPolicy::kForceReboot
: chrome::RebootPolicy::kOptionalReboot;
void SystemTrayClient::HandleUpdateAvailable() {
// Show an update icon for Chrome updates and Flash component updates.
UpgradeDetector* detector = UpgradeDetector::GetInstance();
DCHECK(detector->notify_upgrade() || flash_update_available_);
// Get the Chrome update severity.
ash::mojom::UpdateSeverity severity = GetUpdateSeverity(detector);
// Flash updates are elevated severity unless the Chrome severity is higher. chrome::NotifyAndTerminate(true /* fast_path */, reboot_policy);
if (flash_update_available_)
severity = std::max(severity, ash::mojom::UpdateSeverity::ELEVATED);
system_tray_->ShowUpdateIcon(severity, detector->is_factory_reset_required());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -374,10 +329,3 @@ void SystemTrayClient::OnSystemClockChanged( ...@@ -374,10 +329,3 @@ void SystemTrayClient::OnSystemClockChanged(
chromeos::system::SystemClock* clock) { chromeos::system::SystemClock* clock) {
system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock()); system_tray_->SetUse24HourClock(clock->ShouldUse24HourClock());
} }
void SystemTrayClient::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK_EQ(chrome::NOTIFICATION_UPGRADE_RECOMMENDED, type);
HandleUpdateAvailable();
}
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
#include "ash/public/interfaces/system_tray.mojom.h" #include "ash/public/interfaces/system_tray.mojom.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/system/system_clock_observer.h" #include "chrome/browser/chromeos/system/system_clock_observer.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
namespace ash { namespace ash {
...@@ -25,8 +23,7 @@ class WidgetDelegate; ...@@ -25,8 +23,7 @@ class WidgetDelegate;
// relevant state changes in chrome. // relevant state changes in chrome.
// TODO: Consider renaming this to SystemTrayClientChromeOS. // TODO: Consider renaming this to SystemTrayClientChromeOS.
class SystemTrayClient : public ash::mojom::SystemTrayClient, class SystemTrayClient : public ash::mojom::SystemTrayClient,
public chromeos::system::SystemClockObserver, public chromeos::system::SystemClockObserver {
public content::NotificationObserver {
public: public:
SystemTrayClient(); SystemTrayClient();
~SystemTrayClient() override; ~SystemTrayClient() override;
...@@ -46,10 +43,6 @@ class SystemTrayClient : public ash::mojom::SystemTrayClient, ...@@ -46,10 +43,6 @@ class SystemTrayClient : public ash::mojom::SystemTrayClient,
static views::Widget* CreateUnownedDialogWidget( static views::Widget* CreateUnownedDialogWidget(
views::WidgetDelegate* widget_delegate); views::WidgetDelegate* widget_delegate);
// Shows an update icon for an Adobe Flash update and forces a device reboot
// when the update is applied.
void SetFlashUpdateAvailable();
// ash::mojom::SystemTrayClient: // ash::mojom::SystemTrayClient:
void ShowSettings() override; void ShowSettings() override;
void ShowDateSettings() override; void ShowDateSettings() override;
...@@ -73,28 +66,15 @@ class SystemTrayClient : public ash::mojom::SystemTrayClient, ...@@ -73,28 +66,15 @@ class SystemTrayClient : public ash::mojom::SystemTrayClient,
void RequestRestartForUpdate() override; void RequestRestartForUpdate() override;
private: private:
// Requests that ash show the update available icon.
void HandleUpdateAvailable();
// chromeos::system::SystemClockObserver: // chromeos::system::SystemClockObserver:
void OnSystemClockChanged(chromeos::system::SystemClock* clock) override; void OnSystemClockChanged(chromeos::system::SystemClock* clock) override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// System tray mojo service in ash. // System tray mojo service in ash.
ash::mojom::SystemTrayPtr system_tray_; ash::mojom::SystemTrayPtr system_tray_;
// Binds this object to the client interface. // Binds this object to the client interface.
mojo::Binding<ash::mojom::SystemTrayClient> binding_; mojo::Binding<ash::mojom::SystemTrayClient> binding_;
// Whether an Adobe Flash component update is available.
bool flash_update_available_ = false;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayClient); DISALLOW_COPY_AND_ASSIGN(SystemTrayClient);
}; };
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/update/tray_update.h"
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/test_utils.h"
ash::TrayUpdate* GetTrayUpdate() {
return ash::WmShell::Get()
->GetPrimaryRootWindowController()
->GetSystemTray()
->tray_update();
}
using SystemTrayClientTest = InProcessBrowserTest;
// Test that a chrome update shows the update icon in the system menu.
IN_PROC_BROWSER_TEST_F(SystemTrayClientTest, UpdateTrayIcon) {
ash::TrayUpdate* tray_update = GetTrayUpdate();
// When no update is pending, the icon isn't visible.
EXPECT_FALSE(tray_update->tray_view()->visible());
// Simulate an upgrade. This sends a mojo message to ash.
UpgradeDetector::GetInstance()->NotifyUpgradeRecommended();
content::RunAllPendingInMessageLoop();
// Tray icon is now visible.
EXPECT_TRUE(tray_update->tray_view()->visible());
}
// Test that a flash update causes the update UI to show in the system menu.
IN_PROC_BROWSER_TEST_F(SystemTrayClientTest, FlashUpdateTrayIcon) {
ash::TrayUpdate* tray_update = GetTrayUpdate();
// When no update is pending, the icon isn't visible.
EXPECT_FALSE(tray_update->tray_view()->visible());
// Simulate a Flash update. This sends a mojo message to ash.
SystemTrayClient::Get()->SetFlashUpdateAvailable();
content::RunAllPendingInMessageLoop();
// Tray icon is now visible.
EXPECT_TRUE(tray_update->tray_view()->visible());
}
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ash/common/system/ime/ime_observer.h" #include "ash/common/system/ime/ime_observer.h"
#include "ash/common/system/tray/system_tray_notifier.h" #include "ash/common/system/tray/system_tray_notifier.h"
#include "ash/common/system/tray_accessibility.h" #include "ash/common/system/tray_accessibility.h"
#include "ash/common/system/update/update_observer.h"
#include "ash/common/system/user/user_observer.h" #include "ash/common/system/user/user_observer.h"
#include "ash/common/wm_shell.h" #include "ash/common/wm_shell.h"
#include "ash/system/chromeos/rotation/tray_rotation_lock.h" #include "ash/system/chromeos/rotation/tray_rotation_lock.h"
...@@ -57,11 +58,13 @@ ...@@ -57,11 +58,13 @@
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h" #include "chrome/browser/ui/ash/networking_config_delegate_chromeos.h"
#include "chrome/browser/ui/ash/system_tray_client.h" #include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/singleton_tabs.h" #include "chrome/browser/ui/singleton_tabs.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/features.h" #include "chrome/common/features.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -106,6 +109,9 @@ const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds. ...@@ -106,6 +109,9 @@ const int kSessionLengthLimitMinMs = 30 * 1000; // 30 seconds.
// The maximum session length limit that can be set. // The maximum session length limit that can be set.
const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours. const int kSessionLengthLimitMaxMs = 24 * 60 * 60 * 1000; // 24 hours.
// A pointer so that callers can access the single class instance.
SystemTrayDelegateChromeOS* g_instance = nullptr;
void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime, void ExtractIMEInfo(const input_method::InputMethodDescriptor& ime,
const input_method::InputMethodUtil& util, const input_method::InputMethodUtil& util,
ash::IMEInfo* info) { ash::IMEInfo* info) {
...@@ -144,6 +150,9 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() ...@@ -144,6 +150,9 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
// Register notifications on construction so that events such as // Register notifications on construction so that events such as
// PROFILE_CREATED do not get missed if they happen before Initialize(). // PROFILE_CREATED do not get missed if they happen before Initialize().
registrar_.reset(new content::NotificationRegistrar); registrar_.reset(new content::NotificationRegistrar);
registrar_->Add(this,
chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
content::NotificationService::AllSources());
registrar_->Add(this, registrar_->Add(this,
chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
...@@ -166,6 +175,14 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS() ...@@ -166,6 +175,14 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
base::Unretained(this))); base::Unretained(this)));
user_manager::UserManager::Get()->AddSessionStateObserver(this); user_manager::UserManager::Get()->AddSessionStateObserver(this);
DCHECK(!g_instance);
g_instance = this;
}
// static
SystemTrayDelegateChromeOS* SystemTrayDelegateChromeOS::instance() {
return g_instance;
} }
void SystemTrayDelegateChromeOS::Initialize() { void SystemTrayDelegateChromeOS::Initialize() {
...@@ -215,6 +232,9 @@ void SystemTrayDelegateChromeOS::InitializeOnAdapterReady( ...@@ -215,6 +232,9 @@ void SystemTrayDelegateChromeOS::InitializeOnAdapterReady(
} }
SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() { SystemTrayDelegateChromeOS::~SystemTrayDelegateChromeOS() {
DCHECK_EQ(this, g_instance);
g_instance = nullptr;
// Unregister PrefChangeRegistrars. // Unregister PrefChangeRegistrars.
local_state_registrar_.reset(); local_state_registrar_.reset();
user_pref_registrar_.reset(); user_pref_registrar_.reset();
...@@ -305,6 +325,15 @@ bool SystemTrayDelegateChromeOS::IsUserChild() const { ...@@ -305,6 +325,15 @@ bool SystemTrayDelegateChromeOS::IsUserChild() const {
return user_manager::UserManager::Get()->IsLoggedInAsChildUser(); return user_manager::UserManager::Get()->IsLoggedInAsChildUser();
} }
void SystemTrayDelegateChromeOS::GetSystemUpdateInfo(
ash::UpdateInfo* info) const {
GetUpdateInfo(UpgradeDetector::GetInstance(), info);
// If a flash component update is available, force the tray to show the user
// the Restart to Update dialog.
if (flash_update_available_)
info->update_required = true;
}
bool SystemTrayDelegateChromeOS::ShouldShowSettings() const { bool SystemTrayDelegateChromeOS::ShouldShowSettings() const {
// Show setting button only when the user flow allows and it's not in the // Show setting button only when the user flow allows and it's not in the
// multi-profile login screen. // multi-profile login screen.
...@@ -595,6 +624,18 @@ void SystemTrayDelegateChromeOS::UserChangedChildStatus( ...@@ -595,6 +624,18 @@ void SystemTrayDelegateChromeOS::UserChangedChildStatus(
ash::WmShell::Get()->UpdateAfterLoginStatusChange(GetUserLoginStatus()); ash::WmShell::Get()->UpdateAfterLoginStatusChange(GetUserLoginStatus());
} }
void SystemTrayDelegateChromeOS::SetFlashUpdateAvailable() {
flash_update_available_ = true;
ash::UpdateInfo info;
GetSystemUpdateInfo(&info);
GetSystemTrayNotifier()->NotifyUpdateRecommended(info);
}
bool SystemTrayDelegateChromeOS::GetFlashUpdateAvailable() {
return flash_update_available_;
}
ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() { ash::SystemTrayNotifier* SystemTrayDelegateChromeOS::GetSystemTrayNotifier() {
return ash::WmShell::Get()->system_tray_notifier(); return ash::WmShell::Get()->system_tray_notifier();
} }
...@@ -762,6 +803,12 @@ void SystemTrayDelegateChromeOS::Observe( ...@@ -762,6 +803,12 @@ void SystemTrayDelegateChromeOS::Observe(
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) { const content::NotificationDetails& details) {
switch (type) { switch (type) {
case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
ash::UpdateInfo info;
GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info);
GetSystemTrayNotifier()->NotifyUpdateRecommended(info);
break;
}
case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: { case chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED: {
// This notification is also sent on login screen when user avatar // This notification is also sent on login screen when user avatar
// is loaded from file. // is loaded from file.
......
...@@ -70,6 +70,10 @@ class SystemTrayDelegateChromeOS ...@@ -70,6 +70,10 @@ class SystemTrayDelegateChromeOS
~SystemTrayDelegateChromeOS() override; ~SystemTrayDelegateChromeOS() override;
// Access a global pointer to the single instance of the
// SystemTrayDelegateChromeOS class.
static SystemTrayDelegateChromeOS* instance();
void InitializeOnAdapterReady( void InitializeOnAdapterReady(
scoped_refptr<device::BluetoothAdapter> adapter); scoped_refptr<device::BluetoothAdapter> adapter);
...@@ -84,6 +88,7 @@ class SystemTrayDelegateChromeOS ...@@ -84,6 +88,7 @@ class SystemTrayDelegateChromeOS
base::string16 GetSupervisedUserMessage() const override; base::string16 GetSupervisedUserMessage() const override;
bool IsUserSupervised() const override; bool IsUserSupervised() const override;
bool IsUserChild() const override; bool IsUserChild() const override;
void GetSystemUpdateInfo(ash::UpdateInfo* info) const override;
bool ShouldShowSettings() const override; bool ShouldShowSettings() const override;
bool ShouldShowNotificationTray() const override; bool ShouldShowNotificationTray() const override;
void ShowEnterpriseInfo() override; void ShowEnterpriseInfo() override;
...@@ -122,6 +127,11 @@ class SystemTrayDelegateChromeOS ...@@ -122,6 +127,11 @@ class SystemTrayDelegateChromeOS
void UserChangedChildStatus(user_manager::User* user) override; void UserChangedChildStatus(user_manager::User* user) override;
// This notifies the system that a flash update is now available, and so the
// user should reboot.
void SetFlashUpdateAvailable();
bool GetFlashUpdateAvailable();
private: private:
ash::SystemTrayNotifier* GetSystemTrayNotifier(); ash::SystemTrayNotifier* GetSystemTrayNotifier();
...@@ -234,6 +244,7 @@ class SystemTrayDelegateChromeOS ...@@ -234,6 +244,7 @@ class SystemTrayDelegateChromeOS
std::string enterprise_realm_; std::string enterprise_realm_;
bool should_run_bluetooth_discovery_ = false; bool should_run_bluetooth_discovery_ = false;
bool session_started_ = false; bool session_started_ = false;
bool flash_update_available_ = false;
scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_;
std::unique_ptr<device::BluetoothDiscoverySession> std::unique_ptr<device::BluetoothDiscoverySession>
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include "ash/common/system/date/tray_date.h" #include "ash/common/system/date/tray_date.h"
#include "ash/common/system/date/tray_system_info.h" #include "ash/common/system/date/tray_system_info.h"
#include "ash/common/system/tray/system_tray.h" #include "ash/common/system/tray/system_tray.h"
#include "ash/common/system/update/tray_update.h"
#include "ash/common/wm_shell.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/login/login_manager_test.h" #include "chrome/browser/chromeos/login/login_manager_test.h"
...@@ -129,4 +131,29 @@ IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest, ...@@ -129,4 +131,29 @@ IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
EXPECT_EQ(base::k24HourClock, GetHourType()); EXPECT_EQ(base::k24HourClock, GetHourType());
} }
// Test that a flash update causes the update UI to show in the system menu.
IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
TestFlashUpdateTrayIcon) {
ash::TrayUpdate* tray_update = ash::Shell::GetInstance()
->GetPrimarySystemTray()
->GetTrayUpdateForTesting();
ash::UpdateInfo initial_info;
ash::WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(
&initial_info);
EXPECT_FALSE(initial_info.update_required);
// When no update is pending, the item isn't visible.
EXPECT_FALSE(tray_update->tray_view()->visible());
chromeos::SystemTrayDelegateChromeOS::instance()->SetFlashUpdateAvailable();
ash::UpdateInfo post_info;
ash::WmShell::Get()->system_tray_delegate()->GetSystemUpdateInfo(&post_info);
EXPECT_TRUE(post_info.update_required);
// Tray item is now visible.
EXPECT_TRUE(tray_update->tray_view()->visible());
}
} // namespace chromeos } // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
#include "ash/common/system/tray/system_tray_delegate.h"
#include "base/logging.h"
#include "chrome/browser/upgrade_detector.h"
void GetUpdateInfo(const UpgradeDetector* detector, ash::UpdateInfo* info) {
DCHECK(detector);
DCHECK(info);
switch (detector->upgrade_notification_stage()) {
case UpgradeDetector::UPGRADE_ANNOYANCE_CRITICAL:
info->severity = ash::UpdateInfo::UPDATE_CRITICAL;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_SEVERE:
info->severity = ash::UpdateInfo::UPDATE_SEVERE;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_HIGH:
info->severity = ash::UpdateInfo::UPDATE_HIGH;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_ELEVATED:
info->severity = ash::UpdateInfo::UPDATE_ELEVATED;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_LOW:
info->severity = ash::UpdateInfo::UPDATE_LOW;
break;
case UpgradeDetector::UPGRADE_ANNOYANCE_NONE:
info->severity = ash::UpdateInfo::UPDATE_NONE;
break;
}
info->update_required = detector->notify_upgrade();
info->factory_reset_required = detector->is_factory_reset_required();
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_UTILS_H_
#define CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_UTILS_H_
class UpgradeDetector;
namespace ash {
struct UpdateInfo;
}
// Fills |info| structure with data from |detector|.
void GetUpdateInfo(const UpgradeDetector* detector, ash::UpdateInfo* info);
#endif // CHROME_BROWSER_UI_ASH_SYSTEM_TRAY_DELEGATE_UTILS_H_
...@@ -135,7 +135,6 @@ class UpgradeDetector { ...@@ -135,7 +135,6 @@ class UpgradeDetector {
private: private:
FRIEND_TEST_ALL_PREFIXES(AppMenuModelTest, Basics); FRIEND_TEST_ALL_PREFIXES(AppMenuModelTest, Basics);
FRIEND_TEST_ALL_PREFIXES(SystemTrayClientTest, UpdateTrayIcon);
// Initiates an Idle check. See IdleCallback below. // Initiates an Idle check. See IdleCallback below.
void CheckIdle(); void CheckIdle();
......
...@@ -2090,7 +2090,6 @@ test("browser_tests") { ...@@ -2090,7 +2090,6 @@ test("browser_tests") {
"../browser/ui/ash/multi_user/multi_user_window_manager_test.h", "../browser/ui/ash/multi_user/multi_user_window_manager_test.h",
"../browser/ui/ash/networking_config_delegate_chromeos_browsertest.cc", "../browser/ui/ash/networking_config_delegate_chromeos_browsertest.cc",
"../browser/ui/ash/shelf_browsertest.cc", "../browser/ui/ash/shelf_browsertest.cc",
"../browser/ui/ash/system_tray_client_browsertest.cc",
"../browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc", "../browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc",
"../browser/ui/ash/system_tray_tray_cast_browsertest_media_router_chromeos.cc", "../browser/ui/ash/system_tray_tray_cast_browsertest_media_router_chromeos.cc",
"../browser/ui/ash/volume_controller_browsertest.cc", "../browser/ui/ash/volume_controller_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment