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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_file_system_browser_host.cc

Issue 55133010: [PPAPI] Fixed FileSystems from JavaScript not having a context. (Closed) Base URL: http://git.chromium.org/chromium/src.git@pepper-fs-fileio-test-disable
Patch Set: Nit: Return early, and un-indent code. Created 7 years, 1 month 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/browser/renderer_host/pepper/pepper_file_system_browser_host.h " 5 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_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/public/browser/browser_ppapi_host.h" 9 #include "content/public/browser/browser_ppapi_host.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 PP_FileSystemType type) 45 PP_FileSystemType type)
46 : ResourceHost(host->GetPpapiHost(), instance, resource), 46 : ResourceHost(host->GetPpapiHost(), instance, resource),
47 browser_ppapi_host_(host), 47 browser_ppapi_host_(host),
48 type_(type), 48 type_(type),
49 opened_(false), 49 opened_(false),
50 fs_context_(NULL), 50 fs_context_(NULL),
51 called_open_(false), 51 called_open_(false),
52 weak_factory_(this) { 52 weak_factory_(this) {
53 } 53 }
54 54
55 PepperFileSystemBrowserHost::PepperFileSystemBrowserHost(BrowserPpapiHost* host, 55 void PepperFileSystemBrowserHost::OpenExisting(const GURL& root_url,
56 PP_Instance instance, 56 const base::Closure& callback) {
57 PP_Resource resource, 57 root_url_ = root_url;
58 const GURL& root_url, 58 int render_process_id = 0;
59 PP_FileSystemType type) 59 int unused;
60 : ResourceHost(host->GetPpapiHost(), instance, resource), 60 if (!browser_ppapi_host_->GetRenderViewIDsForInstance(
61 browser_ppapi_host_(host), 61 pp_instance(), &render_process_id, &unused)) {
62 type_(type), 62 NOTREACHED();
63 opened_(true), 63 }
64 root_url_(root_url), 64 called_open_ = true;
65 fs_context_(NULL), 65 // Get the file system context asynchronously, and then complete the Open
66 called_open_(true), 66 // operation by calling |callback|.
67 weak_factory_(this) { 67 BrowserThread::PostTaskAndReplyWithResult(
68 BrowserThread::UI,
69 FROM_HERE,
70 base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
71 base::Bind(&PepperFileSystemBrowserHost::OpenExistingWithContext,
72 weak_factory_.GetWeakPtr(), callback));
68 } 73 }
69 74
70 PepperFileSystemBrowserHost::~PepperFileSystemBrowserHost() { 75 PepperFileSystemBrowserHost::~PepperFileSystemBrowserHost() {
71 // TODO(teravest): Create a FileSystemOperationRunner 76 // TODO(teravest): Create a FileSystemOperationRunner
72 // per-PepperFileSystemBrowserHost, force users of this FileSystem to use it, 77 // per-PepperFileSystemBrowserHost, force users of this FileSystem to use it,
73 // and call Shutdown() on it here. 78 // and call Shutdown() on it here.
74 } 79 }
75 80
76 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived( 81 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived(
77 const IPC::Message& msg, 82 const IPC::Message& msg,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 BrowserThread::UI, 133 BrowserThread::UI,
129 FROM_HERE, 134 FROM_HERE,
130 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), 135 base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
131 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext, 136 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext,
132 weak_factory_.GetWeakPtr(), 137 weak_factory_.GetWeakPtr(),
133 context->MakeReplyMessageContext(), 138 context->MakeReplyMessageContext(),
134 file_system_type)); 139 file_system_type));
135 return PP_OK_COMPLETIONPENDING; 140 return PP_OK_COMPLETIONPENDING;
136 } 141 }
137 142
143 void PepperFileSystemBrowserHost::OpenExistingWithContext(
144 const base::Closure& callback,
145 scoped_refptr<fileapi::FileSystemContext> fs_context) {
146 if (fs_context.get()) {
147 opened_ = true;
148 } else {
149 // If there is no file system context, we log a warning and continue with an
150 // invalid resource (which will produce errors when used), since we have no
151 // way to communicate the error to the caller.
152 LOG(WARNING) << "Could not retrieve file system context.";
153 }
154 fs_context_ = fs_context;
155 callback.Run();
156 }
157
138 void PepperFileSystemBrowserHost::GotFileSystemContext( 158 void PepperFileSystemBrowserHost::GotFileSystemContext(
139 ppapi::host::ReplyMessageContext reply_context, 159 ppapi::host::ReplyMessageContext reply_context,
140 fileapi::FileSystemType file_system_type, 160 fileapi::FileSystemType file_system_type,
141 scoped_refptr<fileapi::FileSystemContext> fs_context) { 161 scoped_refptr<fileapi::FileSystemContext> fs_context) {
142 if (!fs_context.get()) { 162 if (!fs_context.get()) {
143 OpenFileSystemComplete( 163 OpenFileSystemComplete(
144 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); 164 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED);
145 return; 165 return;
146 } 166 }
147 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( 167 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 BrowserThread::UI, 227 BrowserThread::UI,
208 FROM_HERE, 228 FROM_HERE,
209 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), 229 base::Bind(&GetFileSystemContextFromRenderId, render_process_id),
210 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, 230 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext,
211 weak_factory_.GetWeakPtr(), 231 weak_factory_.GetWeakPtr(),
212 context->MakeReplyMessageContext())); 232 context->MakeReplyMessageContext()));
213 return PP_OK_COMPLETIONPENDING; 233 return PP_OK_COMPLETIONPENDING;
214 } 234 }
215 235
216 } // namespace content 236 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698