Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 PP_FileSystemType type) | 58 PP_FileSystemType type) |
| 59 : ResourceHost(host->GetPpapiHost(), instance, resource), | 59 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 60 browser_ppapi_host_(host), | 60 browser_ppapi_host_(host), |
| 61 type_(type), | 61 type_(type), |
| 62 opened_(false), | 62 opened_(false), |
| 63 fs_context_(NULL), | 63 fs_context_(NULL), |
| 64 called_open_(false), | 64 called_open_(false), |
| 65 weak_factory_(this) { | 65 weak_factory_(this) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 PepperFileSystemBrowserHost::PepperFileSystemBrowserHost(BrowserPpapiHost* host, | 68 void PepperFileSystemBrowserHost::OpenExisting(const GURL& root_url, |
| 69 PP_Instance instance, | 69 base::Closure callback) { |
| 70 PP_Resource resource, | 70 root_url_ = root_url; |
| 71 const GURL& root_url, | 71 int render_process_id = 0; |
| 72 PP_FileSystemType type) | 72 int unused; |
| 73 : ResourceHost(host->GetPpapiHost(), instance, resource), | 73 if (!browser_ppapi_host_->GetRenderViewIDsForInstance( |
| 74 browser_ppapi_host_(host), | 74 pp_instance(), &render_process_id, &unused)) { |
| 75 type_(type), | 75 NOTREACHED(); |
| 76 opened_(true), | 76 } |
| 77 root_url_(root_url), | 77 called_open_ = true; |
| 78 fs_context_(NULL), | 78 // Get the file system context asynchronously, and then complete the Open |
| 79 called_open_(true), | 79 // operation by calling |callback|. |
| 80 weak_factory_(this) { | 80 BrowserThread::PostTaskAndReplyWithResult( |
| 81 BrowserThread::UI, | |
| 82 FROM_HERE, | |
| 83 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), | |
| 84 base::Bind(&PepperFileSystemBrowserHost::OpenExistingHaveContext, | |
| 85 weak_factory_.GetWeakPtr(), callback)); | |
| 81 } | 86 } |
| 82 | 87 |
| 83 PepperFileSystemBrowserHost::~PepperFileSystemBrowserHost() { | 88 PepperFileSystemBrowserHost::~PepperFileSystemBrowserHost() { |
| 84 // TODO(teravest): Create a FileSystemOperationRunner | 89 // TODO(teravest): Create a FileSystemOperationRunner |
| 85 // per-PepperFileSystemBrowserHost, force users of this FileSystem to use it, | 90 // per-PepperFileSystemBrowserHost, force users of this FileSystem to use it, |
| 86 // and call Shutdown() on it here. | 91 // and call Shutdown() on it here. |
| 87 } | 92 } |
| 88 | 93 |
| 89 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived( | 94 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived( |
| 90 const IPC::Message& msg, | 95 const IPC::Message& msg, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 BrowserThread::UI, | 146 BrowserThread::UI, |
| 142 FROM_HERE, | 147 FROM_HERE, |
| 143 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), | 148 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), |
| 144 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext, | 149 base::Bind(&PepperFileSystemBrowserHost::GotFileSystemContext, |
| 145 weak_factory_.GetWeakPtr(), | 150 weak_factory_.GetWeakPtr(), |
| 146 context->MakeReplyMessageContext(), | 151 context->MakeReplyMessageContext(), |
| 147 file_system_type)); | 152 file_system_type)); |
| 148 return PP_OK_COMPLETIONPENDING; | 153 return PP_OK_COMPLETIONPENDING; |
| 149 } | 154 } |
| 150 | 155 |
| 156 void PepperFileSystemBrowserHost::OpenExistingHaveContext( | |
| 157 base::Closure callback, | |
| 158 scoped_refptr<fileapi::FileSystemContext> fs_context) { | |
| 159 opened_ = true; | |
|
yzshen1
2013/11/01 22:27:39
Is it intended to set it to true even if fs_contex
Matt Giuca
2013/11/01 23:19:47
Good point. I changed it so that opened_ is only t
| |
| 160 // If there is no file system context, we log a warning and continue with an | |
| 161 // invalid resource (which will produce errors when used), since we have no | |
| 162 // way to communicate the error to the caller. | |
| 163 if (!fs_context.get()) | |
| 164 LOG(WARNING) << "Could not retrieve file system context."; | |
| 165 fs_context_ = fs_context; | |
| 166 callback.Run(); | |
| 167 } | |
| 168 | |
| 151 void PepperFileSystemBrowserHost::GotFileSystemContext( | 169 void PepperFileSystemBrowserHost::GotFileSystemContext( |
| 152 ppapi::host::ReplyMessageContext reply_context, | 170 ppapi::host::ReplyMessageContext reply_context, |
| 153 fileapi::FileSystemType file_system_type, | 171 fileapi::FileSystemType file_system_type, |
| 154 scoped_refptr<fileapi::FileSystemContext> fs_context) { | 172 scoped_refptr<fileapi::FileSystemContext> fs_context) { |
| 155 if (!fs_context.get()) { | 173 if (!fs_context.get()) { |
| 156 OpenFileSystemComplete( | 174 OpenFileSystemComplete( |
| 157 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); | 175 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); |
| 158 return; | 176 return; |
| 159 } | 177 } |
| 160 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( | 178 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 BrowserThread::UI, | 238 BrowserThread::UI, |
| 221 FROM_HERE, | 239 FROM_HERE, |
| 222 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), | 240 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), |
| 223 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, | 241 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, |
| 224 weak_factory_.GetWeakPtr(), | 242 weak_factory_.GetWeakPtr(), |
| 225 context->MakeReplyMessageContext())); | 243 context->MakeReplyMessageContext())); |
| 226 return PP_OK_COMPLETIONPENDING; | 244 return PP_OK_COMPLETIONPENDING; |
| 227 } | 245 } |
| 228 | 246 |
| 229 } // namespace content | 247 } // namespace content |
| OLD | NEW |