diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-13 04:18:44 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-13 04:18:44 +0000 |
commit | be0a84b5a8b1e4e801788fc5d4f42037a88f8c45 (patch) | |
tree | 4033971ac6f11af82464359f4f4e55015eb926f0 /ppapi/shared_impl | |
parent | 5e6c226780eb1617aa9ed980c627af66685d52e4 (diff) | |
download | chromium_src-be0a84b5a8b1e4e801788fc5d4f42037a88f8c45.zip chromium_src-be0a84b5a8b1e4e801788fc5d4f42037a88f8c45.tar.gz chromium_src-be0a84b5a8b1e4e801788fc5d4f42037a88f8c45.tar.bz2 |
Move host resource from the proxy to the shared_impl.
This is needed by my new unified resoruce tracker, which will use this file from the shared_impl in the new resource base object.
I fixed up the namespaces for the callers. Longer term, I want to put the
proxy in the ppapi namespace which will eliminate some of this mess.
Review URL: http://codereview.chromium.org/7623018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r-- | ppapi/shared_impl/host_resource.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/ppapi/shared_impl/host_resource.h b/ppapi/shared_impl/host_resource.h new file mode 100644 index 0000000..0d9b3bf --- /dev/null +++ b/ppapi/shared_impl/host_resource.h @@ -0,0 +1,68 @@ +// Copyright (c) 2011 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 PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ +#define PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_resource.h" + +namespace ppapi { + +// Represents a PP_Resource sent over the wire. This just wraps a PP_Resource. +// The point is to prevent mistakes where the wrong resource value is sent. +// Resource values are remapped in the plugin so that it can talk to multiple +// hosts. If all values were PP_Resource, it would be easy to forget to do +// this tranformation. +// +// All HostResources respresent IDs valid in the host. +class HostResource { + public: + HostResource() : instance_(0), host_resource_(0) { + } + + bool is_null() const { + return !host_resource_; + } + + // Some resources are plugin-side only and don't have a corresponding + // resource in the host. Yet these resources still need an instance to be + // associated with. This function creates a HostResource with the given + // instances and a 0 host resource ID for these cases. + static HostResource MakeInstanceOnly(PP_Instance instance) { + HostResource resource; + resource.SetHostResource(instance, 0); + return resource; + } + + // Sets and retrieves the internal PP_Resource which is valid for the host + // (a.k.a. renderer, as opposed to the plugin) process. + // + // DO NOT CALL THESE FUNCTIONS IN THE PLUGIN SIDE OF THE PROXY. The values + // will be invalid. See the class comment above. + void SetHostResource(PP_Instance instance, PP_Resource resource) { + instance_ = instance; + host_resource_ = resource; + } + PP_Resource host_resource() const { + return host_resource_; + } + + PP_Instance instance() const { return instance_; } + + // This object is used in maps so we need to provide this sorting operator. + bool operator<(const HostResource& other) const { + if (instance_ != other.instance_) + return instance_ < other.instance_; + return host_resource_ < other.host_resource_; + } + + private: + PP_Instance instance_; + PP_Resource host_resource_; +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ |