BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / chromeos / session_length_limiter.h
blob16c34f8b17c175ad4ac17ebe3f78636b8201e492
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_
6 #define CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/threading/thread_checker.h"
13 #include "base/time/time.h"
14 #include "base/timer/timer.h"
15 #include "ui/base/user_activity/user_activity_observer.h"
17 class PrefService;
18 class PrefRegistrySimple;
20 namespace chromeos {
22 // Enforces a session length limit by terminating the session when the limit is
23 // reached.
24 class SessionLengthLimiter : public ui::UserActivityObserver {
25 public:
26 class Delegate {
27 public:
28 virtual ~Delegate();
30 virtual const base::TimeTicks GetCurrentTime() const = 0;
31 virtual void StopSession() = 0;
34 // Registers preferences.
35 static void RegisterPrefs(PrefRegistrySimple* registry);
37 SessionLengthLimiter(Delegate* delegate, bool browser_restarted);
38 ~SessionLengthLimiter() override;
40 // ui::UserActivityObserver:
41 void OnUserActivity(const ui::Event* event) override;
43 private:
44 // Attempt to restore the session start time and the flag indicating user
45 // activity from local state. Return |true| if the restore is successful.
46 bool RestoreStateAfterCrash();
48 // Update the session start time if possible:
49 // * If instructed to wait for initial user activity, the session start time
50 // advances every time this method is called as long as no user activity has
51 // occurred yet. The time is not persisted in local state.
52 // * If instructed not to wait for initial user activity, the session start
53 // time is set and persisted in local state the first time this method is
54 // called.
55 // The pref indicating whether to wait for initial user activity may change at
56 // any time, switching between the two behaviors.
57 void UpdateSessionStartTime();
59 void UpdateLimit();
61 base::ThreadChecker thread_checker_;
63 scoped_ptr<Delegate> delegate_;
64 PrefChangeRegistrar pref_change_registrar_;
66 scoped_ptr<base::OneShotTimer<SessionLengthLimiter::Delegate> > timer_;
67 base::TimeTicks session_start_time_;
68 bool user_activity_seen_;
70 DISALLOW_COPY_AND_ASSIGN(SessionLengthLimiter);
73 } // namespace chromeos
75 #endif // CHROME_BROWSER_CHROMEOS_SESSION_LENGTH_LIMITER_H_