Define DevTools content API
[chromium-blink-merge.git] / ppapi / shared_impl / resource.cc
blob4e1f2a8691f696fcabb97c04b5f84da334c8c721
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
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/resource.h"
7 #include "base/logging.h"
8 #include "ppapi/shared_impl/resource_tracker.h"
9 #include "ppapi/shared_impl/ppapi_globals.h"
11 namespace ppapi {
13 Resource::Resource(PP_Instance instance) {
14 // The instance should always be valid (nonzero).
15 DCHECK(instance);
17 // For the in-process case, the host resource and resource are the same.
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);
24 host_resource_.SetHostResource(instance, pp_resource_);
27 Resource::Resource(const HostResource& host_resource)
28 : host_resource_(host_resource) {
29 pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this);
32 Resource::~Resource() {
33 PpapiGlobals::Get()->GetResourceTracker()->RemoveResource(this);
36 PP_Resource Resource::GetReference() {
37 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(pp_resource());
38 return pp_resource();
41 void Resource::LastPluginRefWasDeleted() {
44 void Resource::InstanceWasDeleted() {
45 host_resource_ = HostResource();
48 #define DEFINE_TYPE_GETTER(RESOURCE) \
49 thunk::RESOURCE* Resource::As##RESOURCE() { return NULL; }
50 FOR_ALL_PPAPI_RESOURCE_APIS(DEFINE_TYPE_GETTER)
51 #undef DEFINE_TYPE_GETTER
53 } // namespace ppapi