Chromium Code Reviews| 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 #ifndef PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ | 5 #ifndef PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ |
| 6 #define PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ | 6 #define PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ |
| 7 | 7 |
| 8 #include "ppapi/c/pp_instance.h" | 8 #include "ppapi/c/pp_instance.h" |
| 9 #include "ppapi/c/pp_resource.h" | 9 #include "ppapi/c/pp_resource.h" |
| 10 #include "ppapi/shared_impl/ppapi_shared_export.h" | 10 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 11 | 11 |
| 12 namespace ppapi { | 12 namespace ppapi { |
| 13 | 13 |
| 14 // Represents a PP_Resource sent over the wire. This just wraps a PP_Resource. | 14 // Represents a PP_Resource sent over the wire. This just wraps a PP_Resource. |
| 15 // The point is to prevent mistakes where the wrong resource value is sent. | 15 // The point is to prevent mistakes where the wrong resource value is sent. |
| 16 // Resource values are remapped in the plugin so that it can talk to multiple | 16 // Resource values are remapped in the plugin so that it can talk to multiple |
| 17 // hosts. If all values were PP_Resource, it would be easy to forget to do | 17 // hosts. If all values were PP_Resource, it would be easy to forget to do |
| 18 // this tranformation. | 18 // this tranformation. |
| 19 // | 19 // |
| 20 // All HostResources respresent IDs valid in the host. | 20 // All HostResources respresent IDs valid in the host. |
| 21 class PPAPI_SHARED_EXPORT HostResource { | 21 class PPAPI_SHARED_EXPORT HostResource { |
| 22 public: | 22 public: |
| 23 HostResource() : instance_(0), host_resource_(0) { | 23 HostResource(); |
|
dmichael (off chromium)
2012/08/16 21:23:17
I moved stuff to a body file when I was trying to
| |
| 24 } | |
| 25 | 24 |
| 26 bool is_null() const { | 25 bool is_null() const { |
| 27 return !host_resource_; | 26 return !host_resource_; |
| 28 } | 27 } |
| 29 | 28 |
| 30 // Some resources are plugin-side only and don't have a corresponding | 29 // Some resources are plugin-side only and don't have a corresponding |
| 31 // resource in the host. Yet these resources still need an instance to be | 30 // resource in the host. Yet these resources still need an instance to be |
| 32 // associated with. This function creates a HostResource with the given | 31 // associated with. This function creates a HostResource with the given |
| 33 // instances and a 0 host resource ID for these cases. | 32 // instances and a 0 host resource ID for these cases. |
| 34 static HostResource MakeInstanceOnly(PP_Instance instance) { | 33 static HostResource MakeInstanceOnly(PP_Instance instance); |
| 35 HostResource resource; | |
| 36 resource.SetHostResource(instance, 0); | |
| 37 return resource; | |
| 38 } | |
| 39 | 34 |
| 40 // Sets and retrieves the internal PP_Resource which is valid for the host | 35 // Sets and retrieves the internal PP_Resource which is valid for the host |
| 41 // (a.k.a. renderer, as opposed to the plugin) process. | 36 // (a.k.a. renderer, as opposed to the plugin) process. |
| 42 // | 37 // |
| 43 // DO NOT CALL THESE FUNCTIONS IN THE PLUGIN SIDE OF THE PROXY. The values | 38 // DO NOT CALL THESE FUNCTIONS IN THE PLUGIN SIDE OF THE PROXY. The values |
| 44 // will be invalid. See the class comment above. | 39 // will be invalid. See the class comment above. |
| 45 void SetHostResource(PP_Instance instance, PP_Resource resource) { | 40 void SetHostResource(PP_Instance instance, PP_Resource resource); |
| 46 instance_ = instance; | |
| 47 host_resource_ = resource; | |
| 48 } | |
| 49 PP_Resource host_resource() const { | 41 PP_Resource host_resource() const { |
| 50 return host_resource_; | 42 return host_resource_; |
| 51 } | 43 } |
| 52 | 44 |
| 53 PP_Instance instance() const { return instance_; } | 45 PP_Instance instance() const { return instance_; } |
| 54 | 46 |
| 55 // This object is used in maps so we need to provide this sorting operator. | 47 // This object is used in maps so we need to provide this sorting operator. |
| 56 bool operator<(const HostResource& other) const { | 48 bool operator<(const HostResource& other) const { |
| 57 if (instance_ != other.instance_) | 49 if (instance_ != other.instance_) |
| 58 return instance_ < other.instance_; | 50 return instance_ < other.instance_; |
| 59 return host_resource_ < other.host_resource_; | 51 return host_resource_ < other.host_resource_; |
| 60 } | 52 } |
| 61 | 53 |
| 62 private: | 54 private: |
| 63 PP_Instance instance_; | 55 PP_Instance instance_; |
| 64 PP_Resource host_resource_; | 56 PP_Resource host_resource_; |
| 65 }; | 57 }; |
| 66 | 58 |
| 67 } // namespace ppapi | 59 } // namespace ppapi |
| 68 | 60 |
| 69 #endif // PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ | 61 #endif // PPAPI_SHARED_IMPL_HOST_RESOURCE_H_ |
| OLD | NEW |