summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/pepper_resource_tracker.h
blob: f114549e1fbd63c491ecc0b567eaa90ac2b5ca9a (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
// Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_
#define WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_

#include <set>

#include "base/atomic_sequence_num.h"
#include "base/basictypes.h"
#include "base/lock.h"
#include "base/ref_counted.h"
#include "base/singleton.h"

typedef struct _pp_Resource PP_Resource;

namespace pepper {

class Resource;

// This class maintains a global list of all live pepper resources. It allows
// us to check resource ID validity and to map them to a specific module.
//
// This object is threadsafe.
class ResourceTracker {
 public:
  // Returns the pointer to the singleton object.
  static ResourceTracker* Get();

  // The returned pointer will be NULL if there is no resource.
  Resource* GetResource(PP_Resource res) const;

  // Adds the given resource to the tracker and assigns it a resource ID. The
  // assigned resource ID will be returned.
  void AddResource(Resource* resource);

  void DeleteResource(Resource* resource);

 private:
  friend struct DefaultSingletonTraits<ResourceTracker>;

  ResourceTracker();
  ~ResourceTracker();

  // Hold this lock when accessing this object's members.
  mutable Lock lock_;

  typedef std::set<Resource*> ResourceSet;
  ResourceSet live_resources_;

  DISALLOW_COPY_AND_ASSIGN(ResourceTracker);
};

}  // namespace pepper

#endif  // WEBKIT_GLUE_PLUGINS_PEPPER_RESOURCE_TRACKER_H_