OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/shared_impl/resource.h" | 5 #include "ppapi/shared_impl/resource.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/shared_impl/resource_tracker.h" | 8 #include "ppapi/shared_impl/resource_tracker.h" |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
10 | 10 |
11 namespace ppapi { | 11 namespace ppapi { |
12 | 12 |
13 Resource::Resource(PP_Instance instance) { | 13 Resource::Resource(ResourceObjectType type, PP_Instance instance) |
| 14 : host_resource_(HostResource::MakeInstanceOnly(instance)) { |
14 // The instance should always be valid (nonzero). | 15 // The instance should always be valid (nonzero). |
15 DCHECK(instance); | 16 DCHECK(instance); |
16 | 17 |
17 // For the in-process case, the host resource and resource are the same. | |
18 // | |
19 // AddResource needs our instance() getter to work, and that goes through | |
20 // the host resource, so we need to fill that first even though we don't | |
21 // have a resource ID yet, then fill the resource in later. | |
22 host_resource_ = HostResource::MakeInstanceOnly(instance); | |
23 pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); | 18 pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); |
24 host_resource_.SetHostResource(instance, pp_resource_); | 19 if (type == OBJECT_IS_IMPL) { |
| 20 // For the in-process case, the host resource and resource are the same. |
| 21 // |
| 22 // Note that we need to have set the instance above (in the initializer |
| 23 // list) since AddResource needs our instance() getter to work, and that |
| 24 // goes through the host resource. When we get the "real" resource ID, |
| 25 // we re-set the host_resource. |
| 26 host_resource_.SetHostResource(instance, pp_resource_); |
| 27 } |
25 } | 28 } |
26 | 29 |
27 Resource::Resource(const HostResource& host_resource) | 30 Resource::Resource(ResourceObjectType type, const HostResource& host_resource) |
28 : host_resource_(host_resource) { | 31 : host_resource_(host_resource) { |
29 pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); | 32 pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); |
| 33 if (type == OBJECT_IS_IMPL) { |
| 34 // When using this constructor for the implementation, the resource ID |
| 35 // should not have been passed in. |
| 36 DCHECK(host_resource_.host_resource() == 0); |
| 37 |
| 38 // See previous constructor. |
| 39 host_resource_.SetHostResource(host_resource.instance(), pp_resource_); |
| 40 } |
30 } | 41 } |
31 | 42 |
32 Resource::~Resource() { | 43 Resource::~Resource() { |
33 PpapiGlobals::Get()->GetResourceTracker()->RemoveResource(this); | 44 PpapiGlobals::Get()->GetResourceTracker()->RemoveResource(this); |
34 } | 45 } |
35 | 46 |
36 PP_Resource Resource::GetReference() { | 47 PP_Resource Resource::GetReference() { |
37 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(pp_resource()); | 48 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(pp_resource()); |
38 return pp_resource(); | 49 return pp_resource(); |
39 } | 50 } |
(...skipping 10 matching lines...) Expand all Loading... |
50 message); | 61 message); |
51 } | 62 } |
52 | 63 |
53 #define DEFINE_TYPE_GETTER(RESOURCE) \ | 64 #define DEFINE_TYPE_GETTER(RESOURCE) \ |
54 thunk::RESOURCE* Resource::As##RESOURCE() { return NULL; } | 65 thunk::RESOURCE* Resource::As##RESOURCE() { return NULL; } |
55 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) | 66 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER) |
56 #undef DEFINE_TYPE_GETTER | 67 #undef DEFINE_TYPE_GETTER |
57 | 68 |
58 } // namespace ppapi | 69 } // namespace ppapi |
59 | 70 |
OLD | NEW |