1 // Copyright 2014 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. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_CAMERA_PRESENCE_NOTIFIER_H_ 6 #define CHROME_BROWSER_CHROMEOS_CAMERA_PRESENCE_NOTIFIER_H_ 7 8 #include "base/memory/singleton.h" 9 #include "base/memory/weak_ptr.h" 10 #include "base/observer_list.h" 11 #include "base/timer/timer.h" 12 13 namespace chromeos { 14 15 // Camera presence status dispatcher. 16 class CameraPresenceNotifier { 17 public: 18 class Observer { 19 public: 20 virtual void OnCameraPresenceCheckDone(bool is_camera_present) = 0; 21 protected: 22 virtual ~Observer() {} 23 }; 24 25 static CameraPresenceNotifier* GetInstance(); 26 27 void AddObserver(CameraPresenceNotifier::Observer* observer); 28 void RemoveObserver(CameraPresenceNotifier::Observer* observer); 29 30 private: 31 friend struct DefaultSingletonTraits<CameraPresenceNotifier>; 32 CameraPresenceNotifier(); 33 ~CameraPresenceNotifier(); 34 35 void CheckCameraPresence(); 36 37 // Sends out a camera presence status notification. 38 void OnCameraPresenceCheckDone(); 39 40 base::WeakPtrFactory<CameraPresenceNotifier> weak_factory_; 41 42 bool camera_present_on_last_check_; 43 44 // Timer for camera check cycle. 45 base::RepeatingTimer<CameraPresenceNotifier> camera_check_timer_; 46 47 ObserverList<Observer> observers_; 48 49 DISALLOW_COPY_AND_ASSIGN(CameraPresenceNotifier); 50 }; 51 52 } // namespace chromeos 53 54 #endif // CHROME_BROWSER_CHROMEOS_CAMERA_PRESENCE_NOTIFIER_H_ 55 56