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

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl.cc

Issue 7433006: Pepper quota support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated Created 9 years, 5 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
OLDNEW
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 #include "content/renderer/pepper_plugin_delegate_impl.h" 5 #include "content/renderer/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util_proxy.h" 13 #include "base/file_util_proxy.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/string_split.h" 16 #include "base/string_split.h"
17 #include "base/sync_socket.h" 17 #include "base/sync_socket.h"
18 #include "base/task.h" 18 #include "base/task.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "content/common/child_process_messages.h" 20 #include "content/common/child_process_messages.h"
21 #include "content/common/child_process.h" 21 #include "content/common/child_process.h"
22 #include "content/common/child_thread.h" 22 #include "content/common/child_thread.h"
23 #include "content/common/content_switches.h" 23 #include "content/common/content_switches.h"
24 #include "content/common/file_system/file_system_dispatcher.h" 24 #include "content/common/file_system/file_system_dispatcher.h"
25 #include "content/common/media/audio_messages.h" 25 #include "content/common/media/audio_messages.h"
26 #include "content/common/pepper_file_messages.h" 26 #include "content/common/pepper_file_messages.h"
27 #include "content/common/pepper_plugin_registry.h" 27 #include "content/common/pepper_plugin_registry.h"
28 #include "content/common/pepper_messages.h" 28 #include "content/common/pepper_messages.h"
29 #include "content/common/quota_dispatcher.h"
29 #include "content/common/view_messages.h" 30 #include "content/common/view_messages.h"
30 #include "content/renderer/content_renderer_client.h" 31 #include "content/renderer/content_renderer_client.h"
31 #include "content/renderer/gpu/command_buffer_proxy.h" 32 #include "content/renderer/gpu/command_buffer_proxy.h"
32 #include "content/renderer/gpu/gpu_channel_host.h" 33 #include "content/renderer/gpu/gpu_channel_host.h"
33 #include "content/renderer/gpu/renderer_gl_context.h" 34 #include "content/renderer/gpu/renderer_gl_context.h"
34 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" 35 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
35 #include "content/renderer/media/audio_message_filter.h" 36 #include "content/renderer/media/audio_message_filter.h"
36 #include "content/renderer/p2p/p2p_transport_impl.h" 37 #include "content/renderer/p2p/p2p_transport_impl.h"
37 #include "content/renderer/pepper_platform_context_3d_impl.h" 38 #include "content/renderer/pepper_platform_context_3d_impl.h"
38 #include "content/renderer/pepper_platform_video_decoder_impl.h" 39 #include "content/renderer/pepper_platform_video_decoder_impl.h"
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 pp::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get()); 350 pp::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
350 } 351 }
351 virtual void RemoveInstance(PP_Instance instance) { 352 virtual void RemoveInstance(PP_Instance instance) {
352 pp::proxy::HostDispatcher::RemoveForInstance(instance); 353 pp::proxy::HostDispatcher::RemoveForInstance(instance);
353 } 354 }
354 355
355 private: 356 private:
356 scoped_ptr<pp::proxy::HostDispatcher> dispatcher_; 357 scoped_ptr<pp::proxy::HostDispatcher> dispatcher_;
357 }; 358 };
358 359
360 class QuotaCallbackTranslator : public QuotaDispatcher::Callback {
361 public:
362 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback;
363 QuotaCallbackTranslator(PluginCallback* callback) : callback_(callback) {}
364 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
365 callback_->Run(std::max(static_cast<int64>(0), quota - usage));
366 }
367 virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE {
368 NOTREACHED();
369 }
370 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE {
371 callback_->Run(0);
372 }
373
374 private:
375 scoped_ptr<PluginCallback> callback_;
376 };
377
359 } // namespace 378 } // namespace
360 379
361 bool DispatcherWrapper::Init( 380 bool DispatcherWrapper::Init(
362 RenderView* render_view, 381 RenderView* render_view,
363 base::ProcessHandle plugin_process_handle, 382 base::ProcessHandle plugin_process_handle,
364 const IPC::ChannelHandle& channel_handle, 383 const IPC::ChannelHandle& channel_handle,
365 PP_Module pp_module, 384 PP_Module pp_module,
366 pp::proxy::Dispatcher::GetInterfaceFunc local_get_interface) { 385 pp::proxy::Dispatcher::GetInterfaceFunc local_get_interface) {
367 dispatcher_.reset(new pp::proxy::HostDispatcher( 386 dispatcher_.reset(new pp::proxy::HostDispatcher(
368 plugin_process_handle, pp_module, local_get_interface)); 387 plugin_process_handle, pp_module, local_get_interface));
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 } 927 }
909 928
910 void PepperPluginDelegateImpl::OnAsyncFileOpened( 929 void PepperPluginDelegateImpl::OnAsyncFileOpened(
911 base::PlatformFileError error_code, 930 base::PlatformFileError error_code,
912 base::PlatformFile file, 931 base::PlatformFile file,
913 int message_id) { 932 int message_id) {
914 AsyncOpenFileCallback* callback = 933 AsyncOpenFileCallback* callback =
915 messages_waiting_replies_.Lookup(message_id); 934 messages_waiting_replies_.Lookup(message_id);
916 DCHECK(callback); 935 DCHECK(callback);
917 messages_waiting_replies_.Remove(message_id); 936 messages_waiting_replies_.Remove(message_id);
918 callback->Run(error_code, base::PassPlatformFile(&file)); 937 callback->Run(error_code, base::PassPlatformFile(&file), -1);
919 // Make sure we won't leak file handle if the requester has died. 938 // Make sure we won't leak file handle if the requester has died.
920 if (file != base::kInvalidPlatformFileValue) 939 if (file != base::kInvalidPlatformFileValue)
921 base::FileUtilProxy::Close(GetFileThreadMessageLoopProxy(), file, NULL); 940 base::FileUtilProxy::Close(GetFileThreadMessageLoopProxy(), file, NULL);
922 delete callback; 941 delete callback;
923 } 942 }
924 943
925 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) { 944 void PepperPluginDelegateImpl::OnSetFocus(bool has_focus) {
926 for (std::set<webkit::ppapi::PluginInstance*>::iterator i = 945 for (std::set<webkit::ppapi::PluginInstance*>::iterator i =
927 active_instances_.begin(); 946 active_instances_.begin();
928 i != active_instances_.end(); ++i) 947 i != active_instances_.end(); ++i)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 } 1011 }
993 1012
994 bool PepperPluginDelegateImpl::ReadDirectory( 1013 bool PepperPluginDelegateImpl::ReadDirectory(
995 const GURL& directory_path, 1014 const GURL& directory_path,
996 fileapi::FileSystemCallbackDispatcher* dispatcher) { 1015 fileapi::FileSystemCallbackDispatcher* dispatcher) {
997 FileSystemDispatcher* file_system_dispatcher = 1016 FileSystemDispatcher* file_system_dispatcher =
998 ChildThread::current()->file_system_dispatcher(); 1017 ChildThread::current()->file_system_dispatcher();
999 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); 1018 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher);
1000 } 1019 }
1001 1020
1021 bool PepperPluginDelegateImpl::QueryAvailableSpace(
1022 const GURL& origin, quota::StorageType type,
1023 AvailableSpaceCallback* callback) {
1024 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
1025 origin, type, new QuotaCallbackTranslator(callback));
1026 return true;
1027 }
1028
1029 void PepperPluginDelegateImpl::NotifyStorageModified(
1030 quota::QuotaClient::ID client_id, const GURL& origin,
1031 quota::StorageType type, int64 delta) {
1032 ChildThread::current()->quota_dispatcher()->NotifyStorageModified(
1033 client_id, origin, type, delta);
1034 }
1035
1002 class AsyncOpenFileSystemURLCallbackTranslator 1036 class AsyncOpenFileSystemURLCallbackTranslator
1003 : public fileapi::FileSystemCallbackDispatcher { 1037 : public fileapi::FileSystemCallbackDispatcher {
1004 public: 1038 public:
1005 AsyncOpenFileSystemURLCallbackTranslator( 1039 AsyncOpenFileSystemURLCallbackTranslator(
1006 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) 1040 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback)
1007 : callback_(callback) { 1041 : callback_(callback) {
1008 } 1042 }
1009 1043
1010 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} 1044 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {}
1011 1045
(...skipping 10 matching lines...) Expand all
1022 bool has_more) { 1056 bool has_more) {
1023 NOTREACHED(); 1057 NOTREACHED();
1024 } 1058 }
1025 virtual void DidOpenFileSystem(const std::string& name, 1059 virtual void DidOpenFileSystem(const std::string& name,
1026 const GURL& root) { 1060 const GURL& root) {
1027 NOTREACHED(); 1061 NOTREACHED();
1028 } 1062 }
1029 1063
1030 virtual void DidFail(base::PlatformFileError error_code) { 1064 virtual void DidFail(base::PlatformFileError error_code) {
1031 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; 1065 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue;
1032 callback_->Run(error_code, base::PassPlatformFile(&invalid_file)); 1066 callback_->Run(error_code, base::PassPlatformFile(&invalid_file), -1);
1033 } 1067 }
1034 1068
1035 virtual void DidWrite(int64 bytes, bool complete) { 1069 virtual void DidWrite(int64 bytes, bool complete) {
1036 NOTREACHED(); 1070 NOTREACHED();
1037 } 1071 }
1038 1072
1039 virtual void DidOpenFile( 1073 virtual void DidOpenFile(
1040 base::PlatformFile file, 1074 base::PlatformFile file,
1041 base::ProcessHandle unused) { 1075 base::ProcessHandle unused,
1042 callback_->Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file)); 1076 int64 file_size) {
1077 callback_->Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file),
1078 file_size);
1043 // Make sure we won't leak file handle if the requester has died. 1079 // Make sure we won't leak file handle if the requester has died.
1044 if (file != base::kInvalidPlatformFileValue) { 1080 if (file != base::kInvalidPlatformFileValue) {
1045 base::FileUtilProxy::Close( 1081 base::FileUtilProxy::Close(
1046 RenderThread::current()->GetFileThreadMessageLoopProxy(), file, NULL); 1082 RenderThread::current()->GetFileThreadMessageLoopProxy(), file, NULL);
1047 } 1083 }
1048 } 1084 }
1049 1085
1050 private: // TODO(ericu): Delete this? 1086 private:
1051 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback_; 1087 scoped_ptr<webkit::ppapi::PluginDelegate::AsyncOpenFileCallback> callback_;
1052 }; 1088 };
1053 1089
1054 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( 1090 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL(
1055 const GURL& path, int flags, AsyncOpenFileCallback* callback) { 1091 const GURL& path, int flags, AsyncOpenFileCallback* callback) {
1056 1092
1057 FileSystemDispatcher* file_system_dispatcher = 1093 FileSystemDispatcher* file_system_dispatcher =
1058 ChildThread::current()->file_system_dispatcher(); 1094 ChildThread::current()->file_system_dispatcher();
1059 return file_system_dispatcher->OpenFile(path, flags, 1095 return file_system_dispatcher->OpenFile(path, flags,
1060 new AsyncOpenFileSystemURLCallbackTranslator(callback)); 1096 new AsyncOpenFileSystemURLCallbackTranslator(callback));
1061 } 1097 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 if (!base::SharedMemory::IsHandleValid(handle)) { 1380 if (!base::SharedMemory::IsHandleValid(handle)) {
1345 DLOG(WARNING) << "Browser failed to allocate shared memory"; 1381 DLOG(WARNING) << "Browser failed to allocate shared memory";
1346 return NULL; 1382 return NULL;
1347 } 1383 }
1348 return new base::SharedMemory(handle, false); 1384 return new base::SharedMemory(handle, false);
1349 } 1385 }
1350 1386
1351 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { 1387 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() {
1352 return ppapi::Preferences(render_view_->webkit_preferences()); 1388 return ppapi::Preferences(render_view_->webkit_preferences());
1353 } 1389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698