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

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: '' 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/file_system_messages.h"
25 #include "content/common/media/audio_messages.h" 26 #include "content/common/media/audio_messages.h"
26 #include "content/common/pepper_file_messages.h" 27 #include "content/common/pepper_file_messages.h"
27 #include "content/common/pepper_plugin_registry.h" 28 #include "content/common/pepper_plugin_registry.h"
28 #include "content/common/pepper_messages.h" 29 #include "content/common/pepper_messages.h"
30 #include "content/common/quota_dispatcher.h"
29 #include "content/common/view_messages.h" 31 #include "content/common/view_messages.h"
30 #include "content/renderer/content_renderer_client.h" 32 #include "content/renderer/content_renderer_client.h"
31 #include "content/renderer/gpu/command_buffer_proxy.h" 33 #include "content/renderer/gpu/command_buffer_proxy.h"
32 #include "content/renderer/gpu/gpu_channel_host.h" 34 #include "content/renderer/gpu/gpu_channel_host.h"
33 #include "content/renderer/gpu/renderer_gl_context.h" 35 #include "content/renderer/gpu/renderer_gl_context.h"
34 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" 36 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
35 #include "content/renderer/media/audio_message_filter.h" 37 #include "content/renderer/media/audio_message_filter.h"
36 #include "content/renderer/p2p/p2p_transport_impl.h" 38 #include "content/renderer/p2p/p2p_transport_impl.h"
37 #include "content/renderer/pepper_platform_context_3d_impl.h" 39 #include "content/renderer/pepper_platform_context_3d_impl.h"
38 #include "content/renderer/pepper_platform_video_decoder_impl.h" 40 #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()); 351 pp::proxy::HostDispatcher::SetForInstance(instance, dispatcher_.get());
350 } 352 }
351 virtual void RemoveInstance(PP_Instance instance) { 353 virtual void RemoveInstance(PP_Instance instance) {
352 pp::proxy::HostDispatcher::RemoveForInstance(instance); 354 pp::proxy::HostDispatcher::RemoveForInstance(instance);
353 } 355 }
354 356
355 private: 357 private:
356 scoped_ptr<pp::proxy::HostDispatcher> dispatcher_; 358 scoped_ptr<pp::proxy::HostDispatcher> dispatcher_;
357 }; 359 };
358 360
361 class QuotaCallbackTranslator : public QuotaDispatcher::Callback {
362 public:
363 typedef webkit::ppapi::PluginDelegate::AvailableSpaceCallback PluginCallback;
364 QuotaCallbackTranslator(PluginCallback* callback) : callback_(callback) {}
365 virtual void DidQueryStorageUsageAndQuota(int64 usage, int64 quota) OVERRIDE {
366 callback_->Run(std::max(static_cast<int64>(0), quota - usage));
367 }
368 virtual void DidGrantStorageQuota(int64 granted_quota) OVERRIDE {
369 NOTREACHED();
370 }
371 virtual void DidFail(quota::QuotaStatusCode error) OVERRIDE {
372 callback_->Run(0);
373 }
374
375 private:
376 scoped_ptr<PluginCallback> callback_;
377 };
378
359 } // namespace 379 } // namespace
360 380
361 bool DispatcherWrapper::Init( 381 bool DispatcherWrapper::Init(
362 RenderView* render_view, 382 RenderView* render_view,
363 base::ProcessHandle plugin_process_handle, 383 base::ProcessHandle plugin_process_handle,
364 const IPC::ChannelHandle& channel_handle, 384 const IPC::ChannelHandle& channel_handle,
365 PP_Module pp_module, 385 PP_Module pp_module,
366 pp::proxy::Dispatcher::GetInterfaceFunc local_get_interface) { 386 pp::proxy::Dispatcher::GetInterfaceFunc local_get_interface) {
367 dispatcher_.reset(new pp::proxy::HostDispatcher( 387 dispatcher_.reset(new pp::proxy::HostDispatcher(
368 plugin_process_handle, pp_module, local_get_interface)); 388 plugin_process_handle, pp_module, local_get_interface));
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 } 1012 }
993 1013
994 bool PepperPluginDelegateImpl::ReadDirectory( 1014 bool PepperPluginDelegateImpl::ReadDirectory(
995 const GURL& directory_path, 1015 const GURL& directory_path,
996 fileapi::FileSystemCallbackDispatcher* dispatcher) { 1016 fileapi::FileSystemCallbackDispatcher* dispatcher) {
997 FileSystemDispatcher* file_system_dispatcher = 1017 FileSystemDispatcher* file_system_dispatcher =
998 ChildThread::current()->file_system_dispatcher(); 1018 ChildThread::current()->file_system_dispatcher();
999 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); 1019 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher);
1000 } 1020 }
1001 1021
1022 void PepperPluginDelegateImpl::QueryAvailableSpace(
1023 const GURL& origin, quota::StorageType type,
1024 AvailableSpaceCallback* callback) {
1025 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota(
1026 origin, type, new QuotaCallbackTranslator(callback));
1027 }
1028
1029 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) {
1030 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path));
1031 }
1032
1033 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) {
1034 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta));
1035 }
1036
1002 class AsyncOpenFileSystemURLCallbackTranslator 1037 class AsyncOpenFileSystemURLCallbackTranslator
1003 : public fileapi::FileSystemCallbackDispatcher { 1038 : public fileapi::FileSystemCallbackDispatcher {
1004 public: 1039 public:
1005 AsyncOpenFileSystemURLCallbackTranslator( 1040 AsyncOpenFileSystemURLCallbackTranslator(
1006 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback) 1041 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback)
1007 : callback_(callback) { 1042 : callback_(callback) {
1008 } 1043 }
1009 1044
1010 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} 1045 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {}
1011 1046
(...skipping 28 matching lines...) Expand all
1040 base::PlatformFile file, 1075 base::PlatformFile file,
1041 base::ProcessHandle unused) { 1076 base::ProcessHandle unused) {
1042 callback_->Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file)); 1077 callback_->Run(base::PLATFORM_FILE_OK, base::PassPlatformFile(&file));
1043 // Make sure we won't leak file handle if the requester has died. 1078 // Make sure we won't leak file handle if the requester has died.
1044 if (file != base::kInvalidPlatformFileValue) { 1079 if (file != base::kInvalidPlatformFileValue) {
1045 base::FileUtilProxy::Close( 1080 base::FileUtilProxy::Close(
1046 RenderThread::current()->GetFileThreadMessageLoopProxy(), file, NULL); 1081 RenderThread::current()->GetFileThreadMessageLoopProxy(), file, NULL);
1047 } 1082 }
1048 } 1083 }
1049 1084
1050 private: // TODO(ericu): Delete this? 1085 private:
1051 webkit::ppapi::PluginDelegate::AsyncOpenFileCallback* callback_; 1086 scoped_ptr<webkit::ppapi::PluginDelegate::AsyncOpenFileCallback> callback_;
1052 }; 1087 };
1053 1088
1054 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( 1089 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL(
1055 const GURL& path, int flags, AsyncOpenFileCallback* callback) { 1090 const GURL& path, int flags, AsyncOpenFileCallback* callback) {
1056 1091
1057 FileSystemDispatcher* file_system_dispatcher = 1092 FileSystemDispatcher* file_system_dispatcher =
1058 ChildThread::current()->file_system_dispatcher(); 1093 ChildThread::current()->file_system_dispatcher();
1059 return file_system_dispatcher->OpenFile(path, flags, 1094 return file_system_dispatcher->OpenFile(path, flags,
1060 new AsyncOpenFileSystemURLCallbackTranslator(callback)); 1095 new AsyncOpenFileSystemURLCallbackTranslator(callback));
1061 } 1096 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 if (!base::SharedMemory::IsHandleValid(handle)) { 1379 if (!base::SharedMemory::IsHandleValid(handle)) {
1345 DLOG(WARNING) << "Browser failed to allocate shared memory"; 1380 DLOG(WARNING) << "Browser failed to allocate shared memory";
1346 return NULL; 1381 return NULL;
1347 } 1382 }
1348 return new base::SharedMemory(handle, false); 1383 return new base::SharedMemory(handle, false);
1349 } 1384 }
1350 1385
1351 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() { 1386 ppapi::Preferences PepperPluginDelegateImpl::GetPreferences() {
1352 return ppapi::Preferences(render_view_->webkit_preferences()); 1387 return ppapi::Preferences(render_view_->webkit_preferences());
1353 } 1388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698