OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_resource_tracker.h" | 5 #include "webkit/glue/plugins/pepper_resource_tracker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "third_party/ppapi/c/pp_resource.h" | 10 #include "third_party/ppapi/c/pp_resource.h" |
11 #include "webkit/glue/plugins/pepper_buffer.h" | 11 #include "webkit/glue/plugins/pepper_buffer.h" |
12 #include "webkit/glue/plugins/pepper_device_context_2d.h" | 12 #include "webkit/glue/plugins/pepper_device_context_2d.h" |
| 13 #include "webkit/glue/plugins/pepper_directory_reader.h" |
| 14 #include "webkit/glue/plugins/pepper_file_chooser.h" |
| 15 #include "webkit/glue/plugins/pepper_file_io.h" |
| 16 #include "webkit/glue/plugins/pepper_file_ref.h" |
13 #include "webkit/glue/plugins/pepper_image_data.h" | 17 #include "webkit/glue/plugins/pepper_image_data.h" |
14 #include "webkit/glue/plugins/pepper_resource.h" | 18 #include "webkit/glue/plugins/pepper_resource.h" |
15 #include "webkit/glue/plugins/pepper_url_loader.h" | 19 #include "webkit/glue/plugins/pepper_url_loader.h" |
16 #include "webkit/glue/plugins/pepper_url_request_info.h" | 20 #include "webkit/glue/plugins/pepper_url_request_info.h" |
17 #include "webkit/glue/plugins/pepper_url_response_info.h" | 21 #include "webkit/glue/plugins/pepper_url_response_info.h" |
18 | 22 |
19 namespace pepper { | 23 namespace pepper { |
20 | 24 |
21 ResourceTracker::ResourceTracker() { | 25 ResourceTracker::ResourceTracker() { |
22 } | 26 } |
(...skipping 23 matching lines...) Expand all Loading... |
46 void ResourceTracker::DeleteResource(Resource* resource) { | 50 void ResourceTracker::DeleteResource(Resource* resource) { |
47 AutoLock lock(lock_); | 51 AutoLock lock(lock_); |
48 ResourceSet::iterator found = live_resources_.find(resource); | 52 ResourceSet::iterator found = live_resources_.find(resource); |
49 if (found == live_resources_.end()) { | 53 if (found == live_resources_.end()) { |
50 NOTREACHED(); | 54 NOTREACHED(); |
51 return; | 55 return; |
52 } | 56 } |
53 live_resources_.erase(found); | 57 live_resources_.erase(found); |
54 } | 58 } |
55 | 59 |
56 scoped_refptr<DeviceContext2D> ResourceTracker::GetAsDeviceContext2D( | 60 #define GET_AS_TYPE_IMPL(Type) \ |
57 PP_Resource res) const { | 61 scoped_refptr<Type> ResourceTracker::GetAs##Type( \ |
58 scoped_refptr<Resource> resource = GetResource(res); | 62 PP_Resource res) const { \ |
59 if (!resource.get()) | 63 scoped_refptr<Resource> resource = GetResource(res); \ |
60 return scoped_refptr<DeviceContext2D>(); | 64 if (!resource.get()) \ |
61 return scoped_refptr<DeviceContext2D>(resource->AsDeviceContext2D()); | 65 return scoped_refptr<Type>(); \ |
62 } | 66 return scoped_refptr<Type>(resource->As##Type()); \ |
| 67 } |
63 | 68 |
64 scoped_refptr<ImageData> ResourceTracker::GetAsImageData( | 69 GET_AS_TYPE_IMPL(Buffer) |
65 PP_Resource res) const { | 70 GET_AS_TYPE_IMPL(DeviceContext2D) |
66 scoped_refptr<Resource> resource = GetResource(res); | 71 GET_AS_TYPE_IMPL(DirectoryReader) |
67 if (!resource.get()) | 72 GET_AS_TYPE_IMPL(FileChooser) |
68 return scoped_refptr<ImageData>(); | 73 GET_AS_TYPE_IMPL(FileIO) |
69 return scoped_refptr<ImageData>(resource->AsImageData()); | 74 GET_AS_TYPE_IMPL(FileRef) |
70 } | 75 GET_AS_TYPE_IMPL(ImageData) |
71 | 76 GET_AS_TYPE_IMPL(URLLoader) |
72 scoped_refptr<URLLoader> ResourceTracker::GetAsURLLoader( | 77 GET_AS_TYPE_IMPL(URLRequestInfo) |
73 PP_Resource res) const { | 78 GET_AS_TYPE_IMPL(URLResponseInfo) |
74 scoped_refptr<Resource> resource = GetResource(res); | |
75 if (!resource.get()) | |
76 return scoped_refptr<URLLoader>(); | |
77 return scoped_refptr<URLLoader>(resource->AsURLLoader()); | |
78 } | |
79 | |
80 scoped_refptr<URLRequestInfo> ResourceTracker::GetAsURLRequestInfo( | |
81 PP_Resource res) const { | |
82 scoped_refptr<Resource> resource = GetResource(res); | |
83 if (!resource.get()) | |
84 return scoped_refptr<URLRequestInfo>(); | |
85 return scoped_refptr<URLRequestInfo>(resource->AsURLRequestInfo()); | |
86 } | |
87 | |
88 scoped_refptr<URLResponseInfo> ResourceTracker::GetAsURLResponseInfo( | |
89 PP_Resource res) const { | |
90 scoped_refptr<Resource> resource = GetResource(res); | |
91 if (!resource.get()) | |
92 return scoped_refptr<URLResponseInfo>(); | |
93 return scoped_refptr<URLResponseInfo>(resource->AsURLResponseInfo()); | |
94 } | |
95 | |
96 scoped_refptr<Buffer> ResourceTracker::GetAsBuffer( | |
97 PP_Resource res) const { | |
98 scoped_refptr<Resource> resource = GetResource(res); | |
99 if (!resource.get()) | |
100 return scoped_refptr<Buffer>(); | |
101 return scoped_refptr<Buffer>(resource->AsBuffer()); | |
102 } | |
103 | 79 |
104 } // namespace pepper | 80 } // namespace pepper |
OLD | NEW |