Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: ppapi/proxy/host_resource.h

Issue 7623018: Move host resource from the proxy to the shared_impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/enter_proxy.h ('k') | ppapi/proxy/mock_resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef PPAPI_PROXY_HOST_RESOURCE_H_
6 #define PPAPI_PROXY_HOST_RESOURCE_H_
7
8 #include "ppapi/c/pp_instance.h"
9 #include "ppapi/c/pp_resource.h"
10
11 namespace pp {
12 namespace proxy {
13
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.
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
18 // this tranformation.
19 //
20 // All HostResources respresent IDs valid in the host.
21 class HostResource {
22 public:
23 HostResource() : instance_(0), host_resource_(0) {
24 }
25
26 bool is_null() const {
27 return !host_resource_;
28 }
29
30 // 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
32 // associated with. This function creates a HostResource with the given
33 // instances and a 0 host resource ID for these cases.
34 static HostResource MakeInstanceOnly(PP_Instance instance) {
35 HostResource resource;
36 resource.SetHostResource(instance, 0);
37 return resource;
38 }
39
40 // Sets and retrieves the internal PP_Resource which is valid for the host
41 // (a.k.a. renderer, as opposed to the plugin) process.
42 //
43 // DO NOT CALL THESE FUNCTIONS IN THE PLUGIN SIDE OF THE PROXY. The values
44 // will be invalid. See the class comment above.
45 void SetHostResource(PP_Instance instance, PP_Resource resource) {
46 instance_ = instance;
47 host_resource_ = resource;
48 }
49 PP_Resource host_resource() const {
50 return host_resource_;
51 }
52
53 PP_Instance instance() const { return instance_; }
54
55 // This object is used in maps so we need to provide this sorting operator.
56 bool operator<(const HostResource& other) const {
57 if (instance_ != other.instance_)
58 return instance_ < other.instance_;
59 return host_resource_ < other.host_resource_;
60 }
61
62 private:
63 PP_Instance instance_;
64 PP_Resource host_resource_;
65 };
66
67 } // namespace proxy
68 } // namespace pp
69
70 #endif // PPAPI_PROXY_HOST_RESOURCE_H_
OLDNEW
« no previous file with comments | « ppapi/proxy/enter_proxy.h ('k') | ppapi/proxy/mock_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698