summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/screensaver/screensaver_controller.h
blob: 36e9877393629b529cd9b13836713ad51bf3f7a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 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_SCREENSAVER_SCREENSAVER_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_SCREENSAVER_SCREENSAVER_CONTROLLER_H_

#include <string>

#include "ash/wm/user_activity_observer.h"
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/memory/weak_ptr.h"
#include "base/time.h"
#include "chromeos/dbus/power_manager_client.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"

namespace extensions {
class Extension;
}

namespace chromeos {

// This class controls the management of the screensaver extension. It is
// responsible for:
// . Enabling and disabling of the screensaver, along with ensuring that we
//   have only one screensaver at a time.
// . Managing the showing and hiding of the current screensaver based on user
//   activity.
// . Any power management that may be required while a screensaver is active.
class ScreensaverController : public ash::UserActivityObserver,
                              public PowerManagerClient::Observer,
                              public content::NotificationObserver {
 public:
  ScreensaverController();
  virtual ~ScreensaverController();

 private:
  FRIEND_TEST_ALL_PREFIXES(ScreensaverControllerTest, Basic);
  FRIEND_TEST_ALL_PREFIXES(ScreensaverControllerTest, OutOfOrder);

  // Overridden from content::NotificationObserver:
  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE;

  // Overridden from PowerManagerClient::Observer:
  virtual void IdleNotify(int64 threshold) OVERRIDE;

  // UserActivityObserver::Observer overrides:
  virtual void OnUserActivity() OVERRIDE;

  void SetupScreensaver(const std::string& screensaver_extension_id);
  void TeardownScreensaver();

  void RequestNextIdleNotification();

  std::string screensaver_extension_id_;

  content::NotificationRegistrar registrar_;

  base::TimeDelta threshold_;

  base::WeakPtrFactory<ScreensaverController> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(ScreensaverController);
};

}  // namespace chromeos

#endif  // CHROME_BROWSER_CHROMEOS_SCREENSAVER_SCREENSAVER_CONTROLLER_H_