Commit 6ab6ae10 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Rename SystemClockObserver to ClockModel.

Previously, SystemClockObserver worked as a model class of system clock,
but it was owned by TraySystemInfo. It has several problems:
* It cannot be referenced from UnifiedSystemTray in the future.
* The model variable is duplicated over multi displays.

This CL
* Renames SystemClockObserver to ClockModel and makes it owned by
  SystemTrayModel.
* Moves AddObserver/RemoveObserver from SystemTrayNotifier
* Moves |hour_clock_type_| model variable from SystemTrayController to
  ClockModel.

TEST=ash_unittests
BUG=none

Change-Id: Ia8d852206b1625b0d23aecaceda5f02d95275207
Reviewed-on: https://chromium-review.googlesource.com/977361
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546424}
parent 04eb0c38
......@@ -555,6 +555,8 @@ component("ash") {
"system/locale/locale_notification_controller.h",
"system/media_security/multi_profile_media_tray_item.cc",
"system/media_security/multi_profile_media_tray_item.h",
"system/model/clock_model.cc",
"system/model/clock_model.h",
"system/model/enterprise_domain_model.cc",
"system/model/enterprise_domain_model.h",
"system/model/system_tray_model.cc",
......@@ -698,8 +700,6 @@ component("ash") {
"system/status_area_widget_delegate.h",
"system/supervised/tray_supervised_user.cc",
"system/supervised/tray_supervised_user.h",
"system/system_clock_observer.cc",
"system/system_clock_observer.h",
"system/system_tray_focus_observer.h",
"system/tiles/tiles_default_view.cc",
"system/tiles/tiles_default_view.h",
......
......@@ -6,6 +6,8 @@
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/system_tray_controller.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_item_style.h"
......@@ -83,7 +85,8 @@ void BaseDateTimeView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner)
: ActionableView(owner, TrayPopupInkDropStyle::INSET_BOUNDS),
hour_type_(Shell::Get()->system_tray_controller()->hour_clock_type()) {
hour_type_(
Shell::Get()->system_tray_model()->clock()->hour_clock_type()) {
SetTimer(base::Time::Now());
SetFocusBehavior(FocusBehavior::NEVER);
}
......@@ -158,7 +161,7 @@ void DateView::SetAction(DateAction action) {
}
void DateView::UpdateTimeFormat() {
hour_type_ = Shell::Get()->system_tray_controller()->hour_clock_type();
hour_type_ = Shell::Get()->system_tray_model()->clock()->hour_clock_type();
UpdateText();
}
......@@ -198,7 +201,7 @@ TimeView::TimeView(ClockLayout clock_layout) : BaseDateTimeView(nullptr) {
TimeView::~TimeView() = default;
void TimeView::UpdateTimeFormat() {
hour_type_ = Shell::Get()->system_tray_controller()->hour_clock_type();
hour_type_ = Shell::Get()->system_tray_model()->clock()->hour_clock_type();
UpdateText();
}
......
......@@ -8,7 +8,8 @@
#include "ash/shell.h"
#include "ash/system/date/date_view.h"
#include "ash/system/date/system_info_default_view.h"
#include "ash/system/system_clock_observer.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/tray/tray_item_view.h"
......@@ -19,13 +20,12 @@ TraySystemInfo::TraySystemInfo(SystemTray* system_tray)
: SystemTrayItem(system_tray, UMA_DATE),
tray_view_(nullptr),
default_view_(nullptr),
login_status_(LoginStatus::NOT_LOGGED_IN),
system_clock_observer_(new SystemClockObserver()) {
Shell::Get()->system_tray_notifier()->AddClockObserver(this);
login_status_(LoginStatus::NOT_LOGGED_IN) {
Shell::Get()->system_tray_model()->clock()->AddObserver(this);
}
TraySystemInfo::~TraySystemInfo() {
Shell::Get()->system_tray_notifier()->RemoveClockObserver(this);
Shell::Get()->system_tray_model()->clock()->RemoveObserver(this);
}
const tray::TimeView* TraySystemInfo::GetTimeTrayForTesting() const {
......@@ -58,7 +58,8 @@ views::View* TraySystemInfo::CreateDefaultView(LoginStatus status) {
// Save the login status we created the view with.
login_status_ = status;
OnSystemClockCanSetTimeChanged(system_clock_observer_->can_set_time());
OnSystemClockCanSetTimeChanged(
Shell::Get()->system_tray_model()->clock()->can_set_time());
return default_view_;
}
......
......@@ -18,7 +18,6 @@ class Label;
}
namespace ash {
class SystemClockObserver;
class SystemInfoDefaultView;
namespace tray {
......@@ -57,8 +56,6 @@ class ASH_EXPORT TraySystemInfo : public SystemTrayItem, public ClockObserver {
SystemInfoDefaultView* default_view_;
LoginStatus login_status_;
std::unique_ptr<SystemClockObserver> system_clock_observer_;
DISALLOW_COPY_AND_ASSIGN(TraySystemInfo);
};
......
......@@ -2,39 +2,70 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/system_clock_observer.h"
#include "ash/system/model/clock_model.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/date/clock_observer.h"
#include "chromeos/dbus/dbus_thread_manager.h"
namespace ash {
SystemClockObserver::SystemClockObserver() {
ClockModel::ClockModel() : hour_clock_type_(base::GetHourClockType()) {
chromeos::DBusThreadManager::Get()->GetSystemClockClient()->AddObserver(this);
chromeos::system::TimezoneSettings::GetInstance()->AddObserver(this);
can_set_time_ =
chromeos::DBusThreadManager::Get()->GetSystemClockClient()->CanSetTime();
}
SystemClockObserver::~SystemClockObserver() {
ClockModel::~ClockModel() {
chromeos::DBusThreadManager::Get()->GetSystemClockClient()->RemoveObserver(
this);
chromeos::system::TimezoneSettings::GetInstance()->RemoveObserver(this);
}
void SystemClockObserver::SystemClockUpdated() {
Shell::Get()->system_tray_notifier()->NotifySystemClockTimeUpdated();
void ClockModel::AddObserver(ClockObserver* observer) {
observers_.AddObserver(observer);
}
void SystemClockObserver::SystemClockCanSetTimeChanged(bool can_set_time) {
void ClockModel::RemoveObserver(ClockObserver* observer) {
observers_.RemoveObserver(observer);
}
void ClockModel::SetUse24HourClock(bool use_24_hour) {
hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock;
NotifyDateFormatChanged();
}
void ClockModel::NotifyRefreshClock() {
for (auto& observer : observers_)
observer.Refresh();
}
void ClockModel::NotifyDateFormatChanged() {
for (auto& observer : observers_)
observer.OnDateFormatChanged();
}
void ClockModel::NotifySystemClockTimeUpdated() {
for (auto& observer : observers_)
observer.OnSystemClockTimeUpdated();
}
void ClockModel::NotifySystemClockCanSetTimeChanged(bool can_set_time) {
for (auto& observer : observers_)
observer.OnSystemClockCanSetTimeChanged(can_set_time);
}
void ClockModel::SystemClockUpdated() {
NotifySystemClockTimeUpdated();
}
void ClockModel::SystemClockCanSetTimeChanged(bool can_set_time) {
can_set_time_ = can_set_time;
Shell::Get()->system_tray_notifier()->NotifySystemClockCanSetTimeChanged(
can_set_time_);
NotifySystemClockCanSetTimeChanged(can_set_time_);
}
void SystemClockObserver::TimezoneChanged(const icu::TimeZone& timezone) {
Shell::Get()->system_tray_notifier()->NotifyRefreshClock();
void ClockModel::TimezoneChanged(const icu::TimeZone& timezone) {
NotifyRefreshClock();
}
} // namespace ash
......@@ -2,37 +2,62 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_SYSTEM_CLOCK_OBSERVER_H_
#define ASH_SYSTEM_SYSTEM_CLOCK_OBSERVER_H_
#ifndef ASH_SYSTEM_MODEL_CLOCK_MODEL_H_
#define ASH_SYSTEM_MODEL_CLOCK_MODEL_H_
#include "base/i18n/time_formatting.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "chromeos/dbus/system_clock_client.h"
#include "chromeos/settings/timezone_settings.h"
namespace ash {
class SystemClockObserver
: public chromeos::SystemClockClient::Observer,
public chromeos::system::TimezoneSettings::Observer {
class ClockObserver;
// Model to notify system clock and related configuration change.
class ClockModel : public chromeos::SystemClockClient::Observer,
public chromeos::system::TimezoneSettings::Observer {
public:
SystemClockObserver();
~SystemClockObserver() override;
ClockModel();
~ClockModel() override;
void AddObserver(ClockObserver* observer);
void RemoveObserver(ClockObserver* observer);
void SetUse24HourClock(bool use_24_hour);
// Force observers to refresh clock views e.g. system is resumed or timezone
// is changed.
void NotifyRefreshClock();
// chromeos::SystemClockClient::Observer
// chromeos::SystemClockClient::Observer:
void SystemClockUpdated() override;
void SystemClockCanSetTimeChanged(bool can_set_time) override;
// chromeos::system::TimezoneSettings::Observer
// chromeos::system::TimezoneSettings::Observer:
void TimezoneChanged(const icu::TimeZone& timezone) override;
base::HourClockType hour_clock_type() const { return hour_clock_type_; }
bool can_set_time() { return can_set_time_; }
private:
void NotifyDateFormatChanged();
void NotifySystemClockTimeUpdated();
void NotifySystemClockCanSetTimeChanged(bool can_set_time);
// The type of clock hour display: 12 or 24 hour.
base::HourClockType hour_clock_type_;
// If system clock can be configured by user through SetTimeDialog.
bool can_set_time_;
DISALLOW_COPY_AND_ASSIGN(SystemClockObserver);
base::ObserverList<ClockObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(ClockModel);
};
} // namespace ash
#endif // ASH_SYSTEM_SYSTEM_CLOCK_OBSERVER_H_
#endif // ASH_SYSTEM_MODEL_CLOCK_MODEL_H_
......@@ -4,6 +4,7 @@
#include "ash/system/model/system_tray_model.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/enterprise_domain_model.h"
#include "ash/system/model/tracing_model.h"
#include "ash/system/model/update_model.h"
......@@ -12,7 +13,8 @@
namespace ash {
SystemTrayModel::SystemTrayModel()
: enterprise_domain_(std::make_unique<EnterpriseDomainModel>()),
: clock_(std::make_unique<ClockModel>()),
enterprise_domain_(std::make_unique<EnterpriseDomainModel>()),
tracing_(std::make_unique<TracingModel>()),
update_model_(std::make_unique<UpdateModel>()) {}
......@@ -31,7 +33,7 @@ void SystemTrayModel::SetPrimaryTrayVisible(bool visible) {
}
void SystemTrayModel::SetUse24HourClock(bool use_24_hour) {
NOTIMPLEMENTED();
clock()->SetUse24HourClock(use_24_hour);
}
void SystemTrayModel::SetEnterpriseDisplayDomain(
......
......@@ -12,6 +12,7 @@
namespace ash {
class ClockModel;
class EnterpriseDomainModel;
class TracingModel;
class UpdateModel;
......@@ -37,6 +38,7 @@ class SystemTrayModel : public mojom::SystemTray {
mojom::UpdateType update_type) override;
void SetUpdateOverCellularAvailableIconVisible(bool visible) override;
ClockModel* clock() { return clock_.get(); }
EnterpriseDomainModel* enterprise_domain() {
return enterprise_domain_.get();
}
......@@ -44,13 +46,13 @@ class SystemTrayModel : public mojom::SystemTray {
UpdateModel* update_model() { return update_model_.get(); }
private:
std::unique_ptr<ClockModel> clock_;
std::unique_ptr<EnterpriseDomainModel> enterprise_domain_;
std::unique_ptr<TracingModel> tracing_;
std::unique_ptr<UpdateModel> update_model_;
// TODO(tetsui): Add following as a sub-model of SystemTrayModel:
// * BluetoothModel
// * ClockModel
DISALLOW_COPY_AND_ASSIGN(SystemTrayModel);
};
......
......@@ -11,7 +11,8 @@
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "ash/wm/lock_state_controller.h"
#include "ash/wm/lock_state_observer.h"
......@@ -286,7 +287,7 @@ void PowerEventObserver::SuspendDone(const base::TimeDelta& sleep_duration) {
// here: http://crbug.com/692193
if (Shell::GetAshConfig() != Config::MASH)
Shell::Get()->display_configurator()->ResumeDisplays();
Shell::Get()->system_tray_notifier()->NotifyRefreshClock();
Shell::Get()->system_tray_model()->clock()->NotifyRefreshClock();
// If the suspend request was being blocked while waiting for the lock
// animation to complete, clear the blocker since the suspend has already
......
......@@ -32,6 +32,8 @@
#include "ash/system/ime/tray_ime_chromeos.h"
#include "ash/system/keyboard_brightness/tray_keyboard_brightness.h"
#include "ash/system/media_security/multi_profile_media_tray_item.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/network/tray_network.h"
#include "ash/system/network/tray_vpn.h"
#include "ash/system/night_light/tray_night_light.h"
......@@ -554,7 +556,7 @@ void SystemTray::UpdateWebNotifications() {
base::string16 SystemTray::GetAccessibleTimeString(
const base::Time& now) const {
base::HourClockType hour_type =
Shell::Get()->system_tray_controller()->hour_clock_type();
Shell::Get()->system_tray_model()->clock()->hour_clock_type();
return base::TimeFormatTimeOfDayWithHourClockType(now, hour_type,
base::kKeepAmPm);
}
......
......@@ -6,6 +6,7 @@
#include "ash/root_window_controller.h"
#include "ash/shell.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/enterprise_domain_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/model/tracing_model.h"
......@@ -16,8 +17,7 @@
namespace ash {
SystemTrayController::SystemTrayController()
: hour_clock_type_(base::GetHourClockType()) {}
SystemTrayController::SystemTrayController() {}
SystemTrayController::~SystemTrayController() = default;
......@@ -183,8 +183,7 @@ void SystemTrayController::SetPrimaryTrayVisible(bool visible) {
}
void SystemTrayController::SetUse24HourClock(bool use_24_hour) {
hour_clock_type_ = use_24_hour ? base::k24HourClock : base::k12HourClock;
Shell::Get()->system_tray_notifier()->NotifyDateFormatChanged();
Shell::Get()->system_tray_model()->SetUse24HourClock(use_24_hour);
}
void SystemTrayController::SetEnterpriseDisplayDomain(
......
......@@ -23,8 +23,6 @@ class ASH_EXPORT SystemTrayController : public mojom::SystemTray {
SystemTrayController();
~SystemTrayController() override;
base::HourClockType hour_clock_type() const { return hour_clock_type_; }
// Wrappers around the mojom::SystemTrayClient interface.
void ShowSettings();
void ShowBluetoothSettings();
......@@ -77,9 +75,6 @@ class ASH_EXPORT SystemTrayController : public mojom::SystemTray {
// Bindings for users of the mojo interface.
mojo::BindingSet<mojom::SystemTray> bindings_;
// The type of clock hour display: 12 or 24 hour.
base::HourClockType hour_clock_type_;
DISALLOW_COPY_AND_ASSIGN(SystemTrayController);
};
......
......@@ -5,7 +5,6 @@
#include "ash/system/tray/system_tray_notifier.h"
#include "ash/system/bluetooth/bluetooth_observer.h"
#include "ash/system/date/clock_observer.h"
#include "ash/system/ime/ime_observer.h"
#include "ash/system/network/network_observer.h"
#include "ash/system/network/network_portal_detector_observer.h"
......@@ -39,34 +38,6 @@ void SystemTrayNotifier::NotifyBluetoothDiscoveringChanged() {
observer.OnBluetoothDiscoveringChanged();
}
void SystemTrayNotifier::AddClockObserver(ClockObserver* observer) {
clock_observers_.AddObserver(observer);
}
void SystemTrayNotifier::RemoveClockObserver(ClockObserver* observer) {
clock_observers_.RemoveObserver(observer);
}
void SystemTrayNotifier::NotifyRefreshClock() {
for (auto& observer : clock_observers_)
observer.Refresh();
}
void SystemTrayNotifier::NotifyDateFormatChanged() {
for (auto& observer : clock_observers_)
observer.OnDateFormatChanged();
}
void SystemTrayNotifier::NotifySystemClockTimeUpdated() {
for (auto& observer : clock_observers_)
observer.OnSystemClockTimeUpdated();
}
void SystemTrayNotifier::NotifySystemClockCanSetTimeChanged(bool can_set_time) {
for (auto& observer : clock_observers_)
observer.OnSystemClockCanSetTimeChanged(can_set_time);
}
void SystemTrayNotifier::AddIMEObserver(IMEObserver* observer) {
ime_observers_.AddObserver(observer);
}
......
......@@ -17,7 +17,6 @@
namespace ash {
class BluetoothObserver;
class ClockObserver;
class IMEObserver;
class NetworkObserver;
class NetworkPortalDetectorObserver;
......@@ -42,14 +41,6 @@ class ASH_EXPORT SystemTrayNotifier {
void NotifyRefreshBluetooth();
void NotifyBluetoothDiscoveringChanged();
// Date and time.
void AddClockObserver(ClockObserver* observer);
void RemoveClockObserver(ClockObserver* observer);
void NotifyRefreshClock();
void NotifyDateFormatChanged();
void NotifySystemClockTimeUpdated();
void NotifySystemClockCanSetTimeChanged(bool can_set_time);
// Input methods.
void AddIMEObserver(IMEObserver* observer);
void RemoveIMEObserver(IMEObserver* observer);
......@@ -94,7 +85,6 @@ class ASH_EXPORT SystemTrayNotifier {
private:
base::ObserverList<BluetoothObserver> bluetooth_observers_;
base::ObserverList<ClockObserver> clock_observers_;
base::ObserverList<IMEObserver> ime_observers_;
base::ObserverList<NetworkObserver> network_observers_;
base::ObserverList<NetworkPortalDetectorObserver>
......
......@@ -9,6 +9,7 @@
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/date/clock_observer.h"
#include "ash/system/enterprise/enterprise_domain_observer.h"
#include "ash/system/model/clock_model.h"
#include "ash/system/model/enterprise_domain_model.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/power/power_status.h"
......@@ -70,11 +71,11 @@ DateView::DateView() : label_(new views::Label) {
label_->SetEnabledColor(kUnifiedMenuTextColor);
Update();
Shell::Get()->system_tray_notifier()->AddClockObserver(this);
Shell::Get()->system_tray_model()->clock()->AddObserver(this);
}
DateView::~DateView() {
Shell::Get()->system_tray_notifier()->RemoveClockObserver(this);
Shell::Get()->system_tray_model()->clock()->RemoveObserver(this);
}
void DateView::Update() {
......
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