1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ash/system/chromeos/session/session_length_limit_observer.h"
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_item.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/compiler_specific.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/strings/string16.h"
14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/timer/timer.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ash {
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace test {
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class TraySessionLengthLimitTest;
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class LabelTrayView;
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Adds a countdown timer to the system tray if the session length is limited.
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class ASH_EXPORT TraySessionLengthLimit : public SystemTrayItem,
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          public SessionLengthLimitObserver {
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)public:
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  enum LimitState {
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LIMIT_NONE,
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LIMIT_SET,
312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    LIMIT_EXPIRING_SOON
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit TraySessionLengthLimit(SystemTray* system_tray);
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~TraySessionLengthLimit();
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // SystemTrayItem:
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
39cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void DestroyDefaultView() OVERRIDE;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // SessionLengthLimitObserver:
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnSessionStartTimeChanged() OVERRIDE;
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void OnSessionLengthLimitChanged() OVERRIDE;
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  friend class test::TraySessionLengthLimitTest;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static const char kNotificationId[];
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Update state, notification and tray bubble view.  Called by the
51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // RepeatingTimer in regular intervals and also by OnSession*Changed().
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  void Update();
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
54cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Recalculate |limit_state_| and |remaining_session_time_|.
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void UpdateState();
56cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
57cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void UpdateNotification();
58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  void UpdateTrayBubbleView() const;
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // These require that the state has been updated before.
61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  base::string16 ComposeNotificationMessage() const;
62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  base::string16 ComposeTrayBubbleMessage() const;
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeTicks session_start_time_;
65cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  base::TimeDelta time_limit_;
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::TimeDelta remaining_session_time_;
67cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
68cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  LimitState limit_state_;       // Current state.
69cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  LimitState last_limit_state_;  // State of last notification update.
70cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
71cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  LabelTrayView* tray_bubble_view_;
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<base::RepeatingTimer<TraySessionLengthLimit> > timer_;
732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TraySessionLengthLimit);
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}  // namespace ash
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
79a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // ASH_SYSTEM_CHROMEOS_SESSION_SESSION_LENGTH_LIMIT_H_
80