Chromium Code Reviews| Index: chrome/browser/chromeos/session_length_limiter.h |
| diff --git a/chrome/browser/chromeos/session_length_limiter.h b/chrome/browser/chromeos/session_length_limiter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..19f04935687ceca2dd47ec8f90a5458174505a38 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/session_length_limiter.h |
| @@ -0,0 +1,78 @@ |
| +// 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 CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_ |
| +#define CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/observer_list.h" |
| +#include "base/prefs/public/pref_change_registrar.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "base/time.h" |
| +#include "base/timer.h" |
| +#include "chrome/browser/profiles/profile_keyed_service.h" |
| + |
| +class PrefService; |
| + |
| +namespace chromeos { |
| + |
| +class SessionLengthLimiter : public ProfileKeyedService { |
| + public: |
| + class Observer { |
| + public: |
| + // Notification of the remaining session time, sent by the |
| + // SessionLengthLimiter once per second. When there is no limit or the limit |
| + // is removed, the notification is invoked one more time with |remaining| |
| + // set to |NULL|. |
| + virtual void SessionTimeRemainingChanged( |
| + const base::TimeDelta* remaining) = 0; |
| + |
| + protected: |
| + virtual ~Observer(); |
| + }; |
| + |
| + class Delegate { |
| + public: |
| + virtual ~Delegate(); |
| + |
| + virtual const base::Time GetCurrentTime() const = 0; |
| + virtual void Logout() = 0; |
|
Mattias Nissler (ping if slow)
2012/12/12 10:12:57
Call this StopSession() maybe?
bartfab (slow)
2012/12/13 16:22:48
Done.
|
| + }; |
| + |
| + SessionLengthLimiter(Delegate* delegate, PrefService* prefs); |
| + virtual ~SessionLengthLimiter(); |
| + |
| + // ProfileKeyedService: |
| + virtual void Shutdown() OVERRIDE; |
| + |
| + void AddObserver(Observer* observer); |
| + void RemoveObserver(Observer* observer); |
| + |
| + private: |
| + base::ThreadChecker thread_checker_; |
| + |
| + scoped_ptr<Delegate> delegate_; |
| + PrefChangeRegistrar pref_change_registrar_; |
|
Mattias Nissler (ping if slow)
2012/12/12 10:12:57
Might want to use an IntegerPrefMember instead.
bartfab (slow)
2012/12/13 16:22:48
I used a PrefChangeRegistrary because I want to ac
|
| + |
| + base::RepeatingTimer<SessionLengthLimiter> repeating_timer_; |
| + base::Time session_start_time_; |
| + base::TimeDelta session_length_limit_; |
| + ObserverList<Observer> observers_; |
| + |
| + void OnSessionLengthLimitChanged(); |
| + |
| + void StartTimer(); |
| + void StopTimer(); |
| + void TimerTick(); |
|
Mattias Nissler (ping if slow)
2012/12/12 10:12:57
These functions could use some commenting on what
bartfab (slow)
2012/12/13 16:22:48
Done.
|
| + |
| + scoped_ptr<base::TimeDelta> GetRemainingTime() const; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SessionLengthLimiter); |
| +}; |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_ |