OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_var.h" | 5 #include "ppapi/shared_impl/resource_var.h" |
6 | 6 |
7 #include "ppapi/shared_impl/ppapi_globals.h" | 7 #include "ppapi/shared_impl/ppapi_globals.h" |
8 #include "ppapi/shared_impl/var_tracker.h" | 8 #include "ppapi/shared_impl/var_tracker.h" |
9 | 9 |
10 namespace ppapi { | 10 namespace ppapi { |
11 | 11 |
12 ResourceVar::ResourceVar() : pp_resource_(0) {} | 12 // ResourceVar |
13 | 13 |
14 ResourceVar::ResourceVar(PP_Resource pp_resource) : pp_resource_(pp_resource) {} | 14 HostResourceVar* ResourceVar::AsHostResourceVar() { |
15 | 15 return NULL; |
16 ResourceVar::ResourceVar(const IPC::Message& creation_message) | |
17 : pp_resource_(0), | |
18 creation_message_(creation_message) {} | |
19 | |
20 ResourceVar::~ResourceVar() {} | |
21 | |
22 bool ResourceVar::IsPending() const { | |
23 return pp_resource_ == 0 && creation_message_.type() != 0; | |
24 } | 16 } |
25 | 17 |
26 ResourceVar* ResourceVar::AsResourceVar() { | 18 ResourceVar* ResourceVar::AsResourceVar() { |
27 return this; | 19 return this; |
28 } | 20 } |
29 | 21 |
30 PP_VarType ResourceVar::GetType() const { | 22 PP_VarType ResourceVar::GetType() const { |
31 return PP_VARTYPE_RESOURCE; | 23 return PP_VARTYPE_RESOURCE; |
32 } | 24 } |
33 | 25 |
34 // static | 26 // static |
35 ResourceVar* ResourceVar::FromPPVar(PP_Var var) { | 27 ResourceVar* ResourceVar::FromPPVar(PP_Var var) { |
36 if (var.type != PP_VARTYPE_RESOURCE) | 28 if (var.type != PP_VARTYPE_RESOURCE) |
37 return NULL; | 29 return NULL; |
38 scoped_refptr<Var> var_object( | 30 scoped_refptr<Var> var_object( |
39 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); | 31 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); |
40 if (!var_object.get()) | 32 if (!var_object.get()) |
41 return NULL; | 33 return NULL; |
42 return var_object->AsResourceVar(); | 34 return var_object->AsResourceVar(); |
43 } | 35 } |
44 | 36 |
| 37 ResourceVar::ResourceVar() {} |
| 38 |
| 39 // HostResourceVar |
| 40 |
| 41 HostResourceVar::HostResourceVar() : pp_resource_(0) {} |
| 42 |
| 43 HostResourceVar::HostResourceVar(PP_Resource pp_resource) |
| 44 : pp_resource_(pp_resource) {} |
| 45 |
| 46 HostResourceVar::HostResourceVar(const IPC::Message& creation_message) |
| 47 : pp_resource_(0), |
| 48 creation_message_(creation_message) {} |
| 49 |
| 50 HostResourceVar::~HostResourceVar() {} |
| 51 |
| 52 PP_Resource HostResourceVar::pp_resource() const { |
| 53 return pp_resource_; |
| 54 } |
| 55 |
| 56 bool HostResourceVar::IsPending() const { |
| 57 return pp_resource_ == 0 && creation_message_.type() != 0; |
| 58 } |
| 59 |
| 60 HostResourceVar* HostResourceVar::AsHostResourceVar() { |
| 61 return this; |
| 62 } |
| 63 |
| 64 // PluginResourceVar |
| 65 |
| 66 PluginResourceVar::PluginResourceVar() : pp_resource_(0) {} |
| 67 |
| 68 PluginResourceVar::PluginResourceVar(PP_Resource pp_resource) |
| 69 : pp_resource_(pp_resource) {} |
| 70 |
| 71 PluginResourceVar::~PluginResourceVar() {} |
| 72 |
| 73 PP_Resource PluginResourceVar::pp_resource() const { |
| 74 return pp_resource_; |
| 75 } |
| 76 |
| 77 bool PluginResourceVar::IsPending() const { |
| 78 return false; |
| 79 } |
| 80 |
45 } // namespace ppapi | 81 } // namespace ppapi |
OLD | NEW |