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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_system_impl.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 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 | « webkit/plugins/ppapi/ppb_file_system_impl.h ('k') | webkit/plugins/ppapi/ppb_flash_menu_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/plugins/ppapi/ppb_file_system_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "ppapi/c/pp_completion_callback.h" 8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/ppb_file_system.h" 9 #include "ppapi/c/ppb_file_system.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
14 #include "webkit/fileapi/file_system_types.h" 14 #include "webkit/fileapi/file_system_types.h"
15 #include "webkit/plugins/ppapi/common.h" 15 #include "webkit/plugins/ppapi/common.h"
16 #include "webkit/plugins/ppapi/file_callbacks.h" 16 #include "webkit/plugins/ppapi/file_callbacks.h"
17 #include "webkit/plugins/ppapi/plugin_delegate.h" 17 #include "webkit/plugins/ppapi/plugin_delegate.h"
18 #include "webkit/plugins/ppapi/plugin_module.h" 18 #include "webkit/plugins/ppapi/plugin_module.h"
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h"
21 #include "webkit/plugins/ppapi/resource_helper.h" 21 #include "webkit/plugins/ppapi/resource_helper.h"
22 22
23 using ppapi::thunk::PPB_FileSystem_API; 23 using ppapi::thunk::PPB_FileSystem_API;
24 using ppapi::TrackedCallback;
24 25
25 namespace webkit { 26 namespace webkit {
26 namespace ppapi { 27 namespace ppapi {
27 28
28 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PP_Instance instance, 29 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PP_Instance instance,
29 PP_FileSystemType type) 30 PP_FileSystemType type)
30 : Resource(::ppapi::OBJECT_IS_IMPL, instance), 31 : Resource(::ppapi::OBJECT_IS_IMPL, instance),
31 type_(type), 32 type_(type),
32 opened_(false), 33 opened_(false),
33 called_open_(false) { 34 called_open_(false) {
(...skipping 11 matching lines...) Expand all
45 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) 46 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY)
46 return 0; 47 return 0;
47 return (new PPB_FileSystem_Impl(instance, type))->GetReference(); 48 return (new PPB_FileSystem_Impl(instance, type))->GetReference();
48 } 49 }
49 50
50 PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() { 51 PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() {
51 return this; 52 return this;
52 } 53 }
53 54
54 int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, 55 int32_t PPB_FileSystem_Impl::Open(int64_t expected_size,
55 PP_CompletionCallback callback) { 56 scoped_refptr<TrackedCallback> callback) {
56 if (!callback.func)
57 return PP_ERROR_BLOCKS_MAIN_THREAD;
58
59 // Should not allow multiple opens. 57 // Should not allow multiple opens.
60 if (called_open_) 58 if (called_open_)
61 return PP_ERROR_INPROGRESS; 59 return PP_ERROR_INPROGRESS;
62 called_open_ = true; 60 called_open_ = true;
63 61
64 fileapi::FileSystemType file_system_type; 62 fileapi::FileSystemType file_system_type;
65 switch (type_) { 63 switch (type_) {
66 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: 64 case PP_FILESYSTEMTYPE_LOCALTEMPORARY:
67 file_system_type = fileapi::kFileSystemTypeTemporary; 65 file_system_type = fileapi::kFileSystemTypeTemporary;
68 break; 66 break;
69 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: 67 case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
70 file_system_type = fileapi::kFileSystemTypePersistent; 68 file_system_type = fileapi::kFileSystemTypePersistent;
71 break; 69 break;
72 case PP_FILESYSTEMTYPE_EXTERNAL: 70 case PP_FILESYSTEMTYPE_EXTERNAL:
73 file_system_type = fileapi::kFileSystemTypeExternal; 71 file_system_type = fileapi::kFileSystemTypeExternal;
74 break; 72 break;
75 default: 73 default:
76 return PP_ERROR_FAILED; 74 return PP_ERROR_FAILED;
77 } 75 }
78 76
79 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 77 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
80 if (!plugin_instance) 78 if (!plugin_instance)
81 return PP_ERROR_FAILED; 79 return PP_ERROR_FAILED;
82 80
83 if (!plugin_instance->delegate()->OpenFileSystem( 81 if (!plugin_instance->delegate()->OpenFileSystem(
84 plugin_instance->container()->element().document().url(), 82 plugin_instance->container()->element().document().url(),
85 file_system_type, expected_size, 83 file_system_type, expected_size,
86 new FileCallbacks(this, callback, NULL, 84 new FileCallbacks(this, callback, NULL,
87 scoped_refptr<PPB_FileSystem_Impl>(this), NULL))) 85 scoped_refptr<PPB_FileSystem_Impl>(this), NULL)))
88 return PP_ERROR_FAILED; 86 return PP_ERROR_FAILED;
89 return PP_OK_COMPLETIONPENDING; 87 return PP_OK_COMPLETIONPENDING;
90 } 88 }
91 89
92 PP_FileSystemType PPB_FileSystem_Impl::GetType() { 90 PP_FileSystemType PPB_FileSystem_Impl::GetType() {
93 return type_; 91 return type_;
94 } 92 }
95 93
96 } // namespace ppapi 94 } // namespace ppapi
97 } // namespace webkit 95 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_system_impl.h ('k') | webkit/plugins/ppapi/ppb_flash_menu_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698