diff options
author | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 17:47:32 +0000 |
---|---|---|
committer | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-21 17:47:32 +0000 |
commit | 7b4460f04c258a841d568d97f43006d145ce65b5 (patch) | |
tree | 24642254d0f73a5199a58fa15581d00a866ccdf4 /chrome/browser | |
parent | 9117e8be9550eea90a0abed960ef60e9db9e7980 (diff) | |
download | chromium_src-7b4460f04c258a841d568d97f43006d145ce65b5.zip chromium_src-7b4460f04c258a841d568d97f43006d145ce65b5.tar.gz chromium_src-7b4460f04c258a841d568d97f43006d145ce65b5.tar.bz2 |
Add notifications for session length countdown
This CL adds a notification view to the session length limiter. The
notification is shown when the user logs in and then again when the
remaining session time reaches a warning threshold, currently set at
5 minutes.
The CL also switches the session length limiter from base::Time, which
can move backward and forward as the clock is adjusted, to base::TimeTicks,
which reliably ticks forward only.
BUG=166307,163402,172766
TEST=Manual, unit tests
TBR=jochen@chromium.org (for chrome/chrome_browser_chromeos.gypi changes)
Review URL: https://codereview.chromium.org/12604016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189651 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/chromeos/login/user_manager_impl.cc | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/session_length_limiter.cc (renamed from chrome/browser/chromeos/power/session_length_limiter.cc) | 17 | ||||
-rw-r--r-- | chrome/browser/chromeos/session_length_limiter.h (renamed from chrome/browser/chromeos/power/session_length_limiter.h) | 10 | ||||
-rw-r--r-- | chrome/browser/chromeos/session_length_limiter_unittest.cc (renamed from chrome/browser/chromeos/power/session_length_limiter_unittest.cc) | 54 | ||||
-rw-r--r-- | chrome/browser/chromeos/system/ash_system_tray_delegate.cc | 63 |
5 files changed, 76 insertions, 70 deletions
diff --git a/chrome/browser/chromeos/login/user_manager_impl.cc b/chrome/browser/chromeos/login/user_manager_impl.cc index 4e888f6..5bbf1c4 100644 --- a/chrome/browser/chromeos/login/user_manager_impl.cc +++ b/chrome/browser/chromeos/login/user_manager_impl.cc @@ -31,7 +31,7 @@ #include "chrome/browser/chromeos/login/remove_user_delegate.h" #include "chrome/browser/chromeos/login/user_image_manager_impl.h" #include "chrome/browser/chromeos/login/wizard_controller.h" -#include "chrome/browser/chromeos/power/session_length_limiter.h" +#include "chrome/browser/chromeos/session_length_limiter.h" #include "chrome/browser/policy/browser_policy_connector.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile_manager.h" diff --git a/chrome/browser/chromeos/power/session_length_limiter.cc b/chrome/browser/chromeos/session_length_limiter.cc index 66dfc38f..14c901b 100644 --- a/chrome/browser/chromeos/power/session_length_limiter.cc +++ b/chrome/browser/chromeos/session_length_limiter.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/power/session_length_limiter.h" +#include "chrome/browser/chromeos/session_length_limiter.h" #include <algorithm> @@ -34,7 +34,7 @@ class SessionLengthLimiterDelegateImpl : public SessionLengthLimiter::Delegate { SessionLengthLimiterDelegateImpl(); virtual ~SessionLengthLimiterDelegateImpl(); - virtual const base::Time GetCurrentTime() const OVERRIDE; + virtual const base::TimeTicks GetCurrentTime() const OVERRIDE; virtual void StopSession() OVERRIDE; private: @@ -47,8 +47,8 @@ SessionLengthLimiterDelegateImpl::SessionLengthLimiterDelegateImpl() { SessionLengthLimiterDelegateImpl::~SessionLengthLimiterDelegateImpl() { } -const base::Time SessionLengthLimiterDelegateImpl::GetCurrentTime() const { - return base::Time::Now(); +const base::TimeTicks SessionLengthLimiterDelegateImpl::GetCurrentTime() const { + return base::TimeTicks::Now(); } void SessionLengthLimiterDelegateImpl::StopSession() { @@ -74,18 +74,19 @@ SessionLengthLimiter::SessionLengthLimiter(Delegate* delegate, // If this is a user login, set the session start time in local state to the // current time. If this a browser restart after a crash, set the session // start time only if its current value appears corrupted (value unset, value - // lying in the future, zero value). + // lying in the future). PrefService* local_state = g_browser_process->local_state(); int64 session_start_time = local_state->GetInt64(prefs::kSessionStartTime); - int64 now = delegate_->GetCurrentTime().ToInternalValue(); + const int64 now = delegate_->GetCurrentTime().ToInternalValue(); if (!browser_restarted || - session_start_time <= 0 || session_start_time > now) { + !local_state->HasPrefPath(prefs::kSessionStartTime) || + session_start_time > now) { local_state->SetInt64(prefs::kSessionStartTime, now); // Ensure that the session start time is persisted to local state. local_state->CommitPendingWrite(); session_start_time = now; } - session_start_time_ = base::Time::FromInternalValue(session_start_time); + session_start_time_ = base::TimeTicks::FromInternalValue(session_start_time); // Listen for changes to the session length limit. pref_change_registrar_.Init(local_state); diff --git a/chrome/browser/chromeos/power/session_length_limiter.h b/chrome/browser/chromeos/session_length_limiter.h index 389117f..f634000 100644 --- a/chrome/browser/chromeos/power/session_length_limiter.h +++ b/chrome/browser/chromeos/session_length_limiter.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_CHROMEOS_POWER_SESSION_LENGTH_LIMITER_H_ -#define CHROME_BROWSER_CHROMEOS_POWER_SESSION_LENGTH_LIMITER_H_ +#ifndef CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_ +#define CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" @@ -25,7 +25,7 @@ class SessionLengthLimiter { public: virtual ~Delegate(); - virtual const base::Time GetCurrentTime() const = 0; + virtual const base::TimeTicks GetCurrentTime() const = 0; virtual void StopSession() = 0; }; @@ -44,11 +44,11 @@ class SessionLengthLimiter { PrefChangeRegistrar pref_change_registrar_; scoped_ptr<base::OneShotTimer<SessionLengthLimiter::Delegate> > timer_; - base::Time session_start_time_; + base::TimeTicks session_start_time_; DISALLOW_COPY_AND_ASSIGN(SessionLengthLimiter); }; } // namespace chromeos -#endif // CHROME_BROWSER_CHROMEOS_POWER_SESSION_LENGTH_LIMITER_H_ +#endif // CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_ diff --git a/chrome/browser/chromeos/power/session_length_limiter_unittest.cc b/chrome/browser/chromeos/session_length_limiter_unittest.cc index 8096560..39495a4 100644 --- a/chrome/browser/chromeos/power/session_length_limiter_unittest.cc +++ b/chrome/browser/chromeos/session_length_limiter_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/chromeos/power/session_length_limiter.h" +#include "chrome/browser/chromeos/session_length_limiter.h" #include <queue> #include <utility> @@ -34,7 +34,7 @@ namespace { class MockSessionLengthLimiterDelegate : public SessionLengthLimiter::Delegate { public: - MOCK_CONST_METHOD0(GetCurrentTime, const base::Time(void)); + MOCK_CONST_METHOD0(GetCurrentTime, const base::TimeTicks(void)); MOCK_METHOD0(StopSession, void(void)); }; @@ -54,7 +54,7 @@ class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner { const base::Closure& task, base::TimeDelta delay) OVERRIDE; - const base::Time& GetCurrentTime() const; + const base::TimeTicks& GetCurrentTime() const; void FastForwardBy(int64 milliseconds); void FastForwardUntilNoTasksRemain(); @@ -64,15 +64,15 @@ class MockTimeSingleThreadTaskRunner : public base::SingleThreadTaskRunner { class TemporalOrder { public: bool operator()( - const std::pair<base::Time, base::Closure>& first_task, - const std::pair<base::Time, base::Closure>& second_task) const; + const std::pair<base::TimeTicks, base::Closure>& first_task, + const std::pair<base::TimeTicks, base::Closure>& second_task) const; }; virtual ~MockTimeSingleThreadTaskRunner(); - base::Time now_; - std::priority_queue<std::pair<base::Time, base::Closure>, - std::vector<std::pair<base::Time, base::Closure> >, + base::TimeTicks now_; + std::priority_queue<std::pair<base::TimeTicks, base::Closure>, + std::vector<std::pair<base::TimeTicks, base::Closure> >, TemporalOrder> tasks_; }; @@ -97,18 +97,15 @@ class SessionLengthLimiterTest : public testing::Test { TestingPrefServiceSimple local_state_; scoped_refptr<MockTimeSingleThreadTaskRunner> runner_; - base::Time session_start_time_; - base::Time session_end_time_; + base::TimeTicks session_start_time_; + base::TimeTicks session_end_time_; MockSessionLengthLimiterDelegate* delegate_; // Owned by // session_length_limiter_. scoped_ptr<SessionLengthLimiter> session_length_limiter_; }; -MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() - // Initialize the mock clock to a fixed value, ensuring that timezone - // differences or DST changes do not affect the test. - : now_(base::Time::UnixEpoch() + base::TimeDelta::FromDays(40 * 365)) { +MockTimeSingleThreadTaskRunner::MockTimeSingleThreadTaskRunner() { } bool MockTimeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const { @@ -119,7 +116,7 @@ bool MockTimeSingleThreadTaskRunner::PostDelayedTask( const tracked_objects::Location& from_here, const base::Closure& task, base::TimeDelta delay) { - tasks_.push(std::pair<base::Time, base::Closure>(now_ + delay, task)); + tasks_.push(std::pair<base::TimeTicks, base::Closure>(now_ + delay, task)); return true; } @@ -131,12 +128,13 @@ bool MockTimeSingleThreadTaskRunner::PostNonNestableDelayedTask( return false; } -const base::Time& MockTimeSingleThreadTaskRunner::GetCurrentTime() const { +const base::TimeTicks& MockTimeSingleThreadTaskRunner::GetCurrentTime() const { return now_; } void MockTimeSingleThreadTaskRunner::FastForwardBy(int64 delta) { - const base::Time latest = now_ + base::TimeDelta::FromMilliseconds(delta); + const base::TimeTicks latest = + now_ + base::TimeDelta::FromMilliseconds(delta); while (!tasks_.empty() && tasks_.top().first <= latest) { now_ = tasks_.top().first; base::Closure task = tasks_.top().second; @@ -156,8 +154,8 @@ void MockTimeSingleThreadTaskRunner::FastForwardUntilNoTasksRemain() { } bool MockTimeSingleThreadTaskRunner::TemporalOrder::operator()( - const std::pair<base::Time, base::Closure>& first_task, - const std::pair<base::Time, base::Closure>& second_task) const { + const std::pair<base::TimeTicks, base::Closure>& first_task, + const std::pair<base::TimeTicks, base::Closure>& second_task) const { return first_task.first >= second_task.first; } @@ -192,7 +190,7 @@ void SessionLengthLimiterTest::SetSessionStartTimePref( } void SessionLengthLimiterTest::VerifySessionStartTimePref() { - base::Time session_start_time(base::Time::FromInternalValue( + base::TimeTicks session_start_time(base::TimeTicks::FromInternalValue( local_state_.GetInt64(prefs::kSessionStartTime))); EXPECT_EQ(session_start_time_, session_start_time); } @@ -233,14 +231,6 @@ TEST_F(SessionLengthLimiterTest, StartWithSessionStartTimeUnset) { } // Verifies that the session start time in local state is updated during login -// if an invalid session start time has been stored before. -TEST_F(SessionLengthLimiterTest, StartWithSessionStartTimeInvalid) { - SetSessionStartTimePref(0); - CreateSessionLengthLimiter(false); - VerifySessionStartTimePref(); -} - -// Verifies that the session start time in local state is updated during login // if a session start time lying in the future has been stored before. TEST_F(SessionLengthLimiterTest, StartWithSessionStartTimeFuture) { SetSessionStartTimePref( @@ -266,14 +256,6 @@ TEST_F(SessionLengthLimiterTest, RestartWithSessionStartTimeUnset) { } // Verifies that the session start time in local state is updated during restart -// after a crash if an invalid session start time has been stored before. -TEST_F(SessionLengthLimiterTest, RestartWithSessionStartTimeInvalid) { - SetSessionStartTimePref(0); - CreateSessionLengthLimiter(true); - VerifySessionStartTimePref(); -} - -// Verifies that the session start time in local state is updated during restart // after a crash if a session start time lying in the future has been stored // before. TEST_F(SessionLengthLimiterTest, RestartWithSessionStartTimeFuture) { diff --git a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc index 4fac333..8d26b59 100644 --- a/chrome/browser/chromeos/system/ash_system_tray_delegate.cc +++ b/chrome/browser/chromeos/system/ash_system_tray_delegate.cc @@ -81,6 +81,7 @@ #include "chrome/browser/upgrade_detector.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" +#include "chrome/common/time_format.h" #include "chrome/common/url_constants.h" #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/dbus_thread_manager.h" @@ -230,6 +231,8 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, clock_type_(base::k24HourClock), search_key_mapped_to_(input_method::kSearchKey), screen_locked_(false), + have_session_start_time_(false), + have_session_length_limit_(false), data_promo_notification_(new DataPromoNotification()), cellular_activating_(false), cellular_out_of_credits_(false), @@ -904,12 +907,16 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, volume_control_delegate_.swap(delegate); } - virtual base::Time GetSessionStartTime() OVERRIDE { - return session_start_time_; + virtual bool GetSessionStartTime( + base::TimeTicks* session_start_time) OVERRIDE { + *session_start_time = session_start_time_; + return have_session_start_time_; } - virtual base::TimeDelta GetSessionLengthLimit() OVERRIDE { - return session_length_limit_; + virtual bool GetSessionLengthLimit( + base::TimeDelta* session_length_limit) OVERRIDE { + *session_length_limit = session_length_limit_; + return have_session_length_limit_; } virtual int GetSystemTrayMenuWidth() OVERRIDE { @@ -917,6 +924,15 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS); } + virtual string16 FormatTimeDuration( + const base::TimeDelta& delta) const OVERRIDE { + return TimeFormat::TimeDurationLong(delta); + } + + virtual void MaybeSpeak(const std::string& utterance) const OVERRIDE { + accessibility::MaybeSpeak(utterance); + } + private: ash::SystemTray* GetPrimarySystemTray() { return ash::Shell::GetInstance()->GetPrimarySystemTray(); @@ -984,26 +1000,31 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, } void UpdateSessionStartTime() { - session_start_time_ = base::Time::FromInternalValue( - local_state_registrar_.prefs()->GetInt64(prefs::kSessionStartTime)); - GetSystemTrayNotifier()->NotifySessionStartTimeChanged(session_start_time_); + const PrefService* local_state = local_state_registrar_.prefs(); + if (local_state->HasPrefPath(prefs::kSessionStartTime)) { + have_session_start_time_ = true; + session_start_time_ = base::TimeTicks::FromInternalValue( + local_state->GetInt64(prefs::kSessionStartTime)); + } else { + have_session_start_time_ = false; + session_start_time_ = base::TimeTicks(); + } + GetSystemTrayNotifier()->NotifySessionStartTimeChanged(); } void UpdateSessionLengthLimit() { - const PrefService::Preference* session_length_limit_pref = - local_state_registrar_.prefs()-> - FindPreference(prefs::kSessionLengthLimit); - int limit; - if (session_length_limit_pref->IsDefaultValue() || - !session_length_limit_pref->GetValue()->GetAsInteger(&limit)) { - session_length_limit_ = base::TimeDelta(); - } else { + const PrefService* local_state = local_state_registrar_.prefs(); + if (local_state->HasPrefPath(prefs::kSessionLengthLimit)) { + have_session_length_limit_ = true; session_length_limit_ = base::TimeDelta::FromMilliseconds( - std::min(std::max(limit, kSessionLengthLimitMinMs), - kSessionLengthLimitMaxMs)); + std::min(std::max(local_state->GetInteger(prefs::kSessionLengthLimit), + kSessionLengthLimitMinMs), + kSessionLengthLimitMaxMs)); + } else { + have_session_length_limit_ = false; + session_length_limit_ = base::TimeDelta(); } - GetSystemTrayNotifier()->NotifySessionLengthLimitChanged( - session_length_limit_); + GetSystemTrayNotifier()->NotifySessionLengthLimitChanged(); } void NotifyRefreshNetwork() { @@ -1482,7 +1503,9 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, base::HourClockType clock_type_; int search_key_mapped_to_; bool screen_locked_; - base::Time session_start_time_; + bool have_session_start_time_; + base::TimeTicks session_start_time_; + bool have_session_length_limit_; base::TimeDelta session_length_limit_; std::string enterprise_domain_; |