146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// found in the LICENSE file.
446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#ifndef MEDIA_CDM_PLAYER_TRACKER_IMPL_H_
646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#define MEDIA_CDM_PLAYER_TRACKER_IMPL_H_
746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include <map>
946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/basictypes.h"
1146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/callback.h"
1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/threading/thread_checker.h"
1346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "media/base/media_export.h"
1446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "media/base/player_tracker.h"
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)namespace media {
1746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
1846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// A common implementation that can be shared by different PlayerTracker
1946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// implementations. This class is not thread safe and should only be called
2046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// on one thread.
2146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class MEDIA_EXPORT PlayerTrackerImpl : public PlayerTracker {
2246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) public:
2346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  PlayerTrackerImpl();
2446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual ~PlayerTrackerImpl();
2546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // PlayerTracker implementation.
2746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual int RegisterPlayer(const base::Closure& new_key_cb,
2846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                             const base::Closure& cdm_unset_cb) OVERRIDE;
2946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  virtual void UnregisterPlayer(int registration_id) OVERRIDE;
3046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Helpers methods to fire registered callbacks.
3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void NotifyNewKey();
3346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  void NotifyCdmUnset();
3446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
3546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) private:
3646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  struct PlayerCallbacks {
3746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    PlayerCallbacks(base::Closure new_key_cb, base::Closure cdm_unset_cb);
3846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    ~PlayerCallbacks();
3946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    base::Closure new_key_cb;
4146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)    base::Closure cdm_unset_cb;
4246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  };
4346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  int next_registration_id_;
4546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  std::map<int, PlayerCallbacks> player_callbacks_map_;
4646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  base::ThreadChecker thread_checker_;
4846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
4946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PlayerTrackerImpl);
5046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)};
5146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
5246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)}  // namespace media
5346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
5446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#endif  // MEDIA_CDM_PLAYER_TRACKER_IMPL_H_
55