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

Side by Side Diff: content/renderer/pepper/pepper_file_system_host.cc

Issue 14796018: Cleanup: Deprecate FileSystemCallbackDispatcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/renderer/pepper/pepper_file_system_host.h" 5 #include "content/renderer/pepper/pepper_file_system_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "content/common/child_thread.h" 9 #include "content/common/child_thread.h"
10 #include "content/common/fileapi/file_system_dispatcher.h" 10 #include "content/common/fileapi/file_system_dispatcher.h"
11 #include "content/public/renderer/render_view.h" 11 #include "content/public/renderer/render_view.h"
12 #include "content/public/renderer/renderer_ppapi_host.h" 12 #include "content/public/renderer/renderer_ppapi_host.h"
13 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h"
14 #include "ppapi/c/pp_errors.h" 13 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/host/dispatch_host_message.h" 14 #include "ppapi/host/dispatch_host_message.h"
16 #include "ppapi/host/ppapi_host.h" 15 #include "ppapi/host/ppapi_host.h"
17 #include "ppapi/proxy/ppapi_messages.h" 16 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/shared_impl/file_type_conversion.h" 17 #include "ppapi/shared_impl/file_type_conversion.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
24 #include "webkit/fileapi/file_system_util.h" 23 #include "webkit/fileapi/file_system_util.h"
25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
26 25
27 namespace content { 26 namespace content {
28 27
29 namespace { 28 namespace {
30 29
31 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher {
32 public:
33 explicit PlatformCallbackAdaptor(
34 const base::WeakPtr<PepperFileSystemHost>& weak_host)
35 : weak_host_(weak_host) {}
36
37 virtual ~PlatformCallbackAdaptor() {}
38
39 virtual void DidOpenFileSystem(const std::string& /* unused */,
40 const GURL& root) OVERRIDE {
41 if (weak_host_)
42 weak_host_->OpenFileSystemReply(PP_OK, root);
43 }
44
45 virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE {
46 if (weak_host_) {
47 weak_host_->OpenFileSystemReply(
48 ppapi::PlatformFileErrorToPepperError(platform_error), GURL());
49 }
50 }
51
52 private:
53 base::WeakPtr<PepperFileSystemHost> weak_host_;
54 };
55
56 bool LooksLikeAGuid(const std::string& fsid) { 30 bool LooksLikeAGuid(const std::string& fsid) {
57 const size_t kExpectedFsIdSize = 32; 31 const size_t kExpectedFsIdSize = 32;
58 if (fsid.size() != kExpectedFsIdSize) 32 if (fsid.size() != kExpectedFsIdSize)
59 return false; 33 return false;
60 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { 34 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) {
61 if (('A' <= *it && *it <= 'F') || 35 if (('A' <= *it && *it <= 'F') ||
62 ('0' <= *it && *it <= '9')) 36 ('0' <= *it && *it <= '9'))
63 continue; 37 continue;
64 return false; 38 return false;
65 } 39 }
(...skipping 24 matching lines...) Expand all
90 PPAPI_DISPATCH_HOST_RESOURCE_CALL( 64 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
91 PpapiHostMsg_FileSystem_Open, 65 PpapiHostMsg_FileSystem_Open,
92 OnHostMsgOpen) 66 OnHostMsgOpen)
93 PPAPI_DISPATCH_HOST_RESOURCE_CALL( 67 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
94 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, 68 PpapiHostMsg_FileSystem_InitIsolatedFileSystem,
95 OnHostMsgInitIsolatedFileSystem) 69 OnHostMsgInitIsolatedFileSystem)
96 IPC_END_MESSAGE_MAP() 70 IPC_END_MESSAGE_MAP()
97 return PP_ERROR_FAILED; 71 return PP_ERROR_FAILED;
98 } 72 }
99 73
100 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, 74 void PepperFileSystemHost::OpenFileSystemReply(
101 const GURL& root) { 75 base::PlatformFileError platform_error,
76 const std::string& /* name_unused */,
77 const GURL& root) {
78 int32 pp_error = ppapi::PlatformFileErrorToPepperError(platform_error);
102 opened_ = (pp_error == PP_OK); 79 opened_ = (pp_error == PP_OK);
103 root_url_ = root; 80 root_url_ = root;
104 reply_context_.params.set_result(pp_error); 81 reply_context_.params.set_result(pp_error);
105 host()->SendReply(reply_context_, 82 host()->SendReply(reply_context_,
106 PpapiPluginMsg_FileSystem_OpenReply()); 83 PpapiPluginMsg_FileSystem_OpenReply());
107 reply_context_ = ppapi::host::ReplyMessageContext(); 84 reply_context_ = ppapi::host::ReplyMessageContext();
108 } 85 }
109 86
110 int32_t PepperFileSystemHost::OnHostMsgOpen( 87 int32_t PepperFileSystemHost::OnHostMsgOpen(
111 ppapi::host::HostMessageContext* context, 88 ppapi::host::HostMessageContext* context,
(...skipping 23 matching lines...) Expand all
135 if (!plugin_instance) 112 if (!plugin_instance)
136 return PP_ERROR_FAILED; 113 return PP_ERROR_FAILED;
137 114
138 FileSystemDispatcher* file_system_dispatcher = 115 FileSystemDispatcher* file_system_dispatcher =
139 ChildThread::current()->file_system_dispatcher(); 116 ChildThread::current()->file_system_dispatcher();
140 reply_context_ = context->MakeReplyMessageContext(); 117 reply_context_ = context->MakeReplyMessageContext();
141 if (!file_system_dispatcher->OpenFileSystem( 118 if (!file_system_dispatcher->OpenFileSystem(
142 GURL(plugin_instance->container()->element().document().url()). 119 GURL(plugin_instance->container()->element().document().url()).
143 GetOrigin(), 120 GetOrigin(),
144 file_system_type, expected_size, true /* create */, 121 file_system_type, expected_size, true /* create */,
145 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { 122 base::Bind(&PepperFileSystemHost::OpenFileSystemReply,
123 weak_factory_.GetWeakPtr()))) {
146 return PP_ERROR_FAILED; 124 return PP_ERROR_FAILED;
147 } 125 }
148 126
149 return PP_OK_COMPLETIONPENDING; 127 return PP_OK_COMPLETIONPENDING;
150 } 128 }
151 129
152 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( 130 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem(
153 ppapi::host::HostMessageContext* context, 131 ppapi::host::HostMessageContext* context,
154 const std::string& fsid) { 132 const std::string& fsid) {
155 // Do a sanity check. 133 // Do a sanity check.
156 if (!LooksLikeAGuid(fsid)) 134 if (!LooksLikeAGuid(fsid))
157 return PP_ERROR_BADARGUMENT; 135 return PP_ERROR_BADARGUMENT;
158 RenderView* view = 136 RenderView* view =
159 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); 137 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance());
160 if (!view) 138 if (!view)
161 return PP_ERROR_FAILED; 139 return PP_ERROR_FAILED;
162 const GURL& url = view->GetWebView()->mainFrame()->document().url(); 140 const GURL& url = view->GetWebView()->mainFrame()->document().url();
163 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( 141 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString(
164 url.GetOrigin(), fsid, "crxfs")); 142 url.GetOrigin(), fsid, "crxfs"));
165 opened_ = true; 143 opened_ = true;
166 return PP_OK; 144 return PP_OK;
167 } 145 }
168 146
169 } // namespace content 147 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698