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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc

Issue 16316002: extensions: Get rid of RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
index 6d67d59fbaad659c060d38a2ba7afd729cd64ab7..bb870108c67c7346e3b2c900cc5880c8eb23c0b7 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.cc
@@ -454,105 +454,6 @@ std::string MakeWebAppTaskId(const std::string& app_id) {
} // namespace
-class RequestLocalFileSystemFunction::LocalFileSystemCallbackDispatcher {
- public:
- static fileapi::FileSystemContext::OpenFileSystemCallback CreateCallback(
- RequestLocalFileSystemFunction* function,
- scoped_refptr<fileapi::FileSystemContext> file_system_context,
- int child_id,
- scoped_refptr<const Extension> extension) {
- return base::Bind(
- &LocalFileSystemCallbackDispatcher::DidOpenFileSystem,
- base::Owned(new LocalFileSystemCallbackDispatcher(
- function, file_system_context, child_id, extension)));
- }
-
- void DidOpenFileSystem(base::PlatformFileError result,
- const std::string& name,
- const GURL& root_path) {
- if (result != base::PLATFORM_FILE_OK) {
- DidFail(result);
- return;
- }
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- // Set up file permission access.
- if (!SetupFileSystemAccessPermissions()) {
- DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
- return;
- }
-
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(
- &RequestLocalFileSystemFunction::RespondSuccessOnUIThread,
- function_,
- name,
- root_path));
- }
-
- void DidFail(base::PlatformFileError error_code) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(
- &RequestLocalFileSystemFunction::RespondFailedOnUIThread,
- function_,
- error_code));
- }
-
- private:
- LocalFileSystemCallbackDispatcher(
- RequestLocalFileSystemFunction* function,
- scoped_refptr<fileapi::FileSystemContext> file_system_context,
- int child_id,
- scoped_refptr<const Extension> extension)
- : function_(function),
- file_system_context_(file_system_context),
- child_id_(child_id),
- extension_(extension) {
- DCHECK(function_);
- }
-
- // Grants file system access permissions to file browser component.
- bool SetupFileSystemAccessPermissions() {
- if (!extension_.get())
- return false;
-
- // Make sure that only component extension can access the entire
- // local file system.
- if (extension_->location() != extensions::Manifest::COMPONENT) {
- NOTREACHED() << "Private method access by non-component extension "
- << extension_->id();
- return false;
- }
-
- fileapi::ExternalFileSystemMountPointProvider* provider =
- file_system_context_->external_provider();
- if (!provider)
- return false;
-
- // Grant full access to File API from this component extension.
- provider->GrantFullAccessToExtension(extension_->id());
-
- // Grant R/W file permissions to the renderer hosting component
- // extension for all paths exposed by our local file system provider.
- std::vector<base::FilePath> root_dirs = provider->GetRootDirectories();
- for (size_t i = 0; i < root_dirs.size(); ++i) {
- ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
- child_id_, root_dirs[i],
- file_handler_util::GetReadWritePermissions());
- }
- return true;
- }
-
- RequestLocalFileSystemFunction* function_;
- scoped_refptr<fileapi::FileSystemContext> file_system_context_;
- // Renderer process id.
- int child_id_;
- // Extension source URL.
- scoped_refptr<const Extension> extension_;
- DISALLOW_COPY_AND_ASSIGN(LocalFileSystemCallbackDispatcher);
-};
-
FileBrowserPrivateAPI::FileBrowserPrivateAPI(Profile* profile)
: event_router_(new FileManagerEventRouter(profile)) {
(new FileBrowserHandlerParser)->Register();
@@ -614,15 +515,96 @@ void RequestLocalFileSystemFunction::RequestOnFileThread(
scoped_refptr<fileapi::FileSystemContext> file_system_context,
const GURL& source_url,
int child_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
GURL origin_url = source_url.GetOrigin();
file_system_context->OpenFileSystem(
- origin_url, fileapi::kFileSystemTypeExternal,
+ origin_url,
+ fileapi::kFileSystemTypeExternal,
fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT,
- LocalFileSystemCallbackDispatcher::CreateCallback(
+ base::Bind(&RequestLocalFileSystemFunction::DidOpenFileSystem,
+ this,
+ file_system_context,
+ child_id,
+ GetExtension()));
+}
+
+void RequestLocalFileSystemFunction::DidOpenFileSystem(
+ scoped_refptr<fileapi::FileSystemContext> file_system_context,
+ int child_id,
+ scoped_refptr<const extensions::Extension> extension,
+ base::PlatformFileError result,
+ const std::string& name,
+ const GURL& root_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ if (result != base::PLATFORM_FILE_OK) {
+ DidFail(result);
+ return;
+ }
+ // Set up file permission access.
+ if (!SetupFileSystemAccessPermissions(file_system_context,
+ child_id,
+ extension)) {
+ DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
+ return;
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &RequestLocalFileSystemFunction::RespondSuccessOnUIThread,
this,
- file_system_context,
- child_id,
- GetExtension()));
+ name,
+ root_path));
+}
+
+void RequestLocalFileSystemFunction::DidFail(
+ base::PlatformFileError error_code) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ &RequestLocalFileSystemFunction::RespondFailedOnUIThread,
+ this,
+ error_code));
+}
+
+bool RequestLocalFileSystemFunction::SetupFileSystemAccessPermissions(
+ scoped_refptr<fileapi::FileSystemContext> file_system_context,
+ int child_id,
+ scoped_refptr<const extensions::Extension> extension) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ if (!extension.get())
+ return false;
+
+ // Make sure that only component extension can access the entire
+ // local file system.
+ if (extension_->location() != extensions::Manifest::COMPONENT) {
+ NOTREACHED() << "Private method access by non-component extension "
+ << extension->id();
+ return false;
+ }
+
+ fileapi::ExternalFileSystemMountPointProvider* provider =
+ file_system_context->external_provider();
+ if (!provider)
+ return false;
+
+ // Grant full access to File API from this component extension.
+ provider->GrantFullAccessToExtension(extension_->id());
+
+ // Grant R/W file permissions to the renderer hosting component
+ // extension for all paths exposed by our local file system provider.
+ std::vector<base::FilePath> root_dirs = provider->GetRootDirectories();
+ for (size_t i = 0; i < root_dirs.size(); ++i) {
+ ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile(
+ child_id, root_dirs[i],
+ file_handler_util::GetReadWritePermissions());
+ }
+ return true;
}
bool LogoutUserFunction::RunImpl() {
hashimoto 2013/06/03 06:05:29 nit: In file_browser_private_api.cc, LogoutUserFun
satorux1 2013/06/03 07:10:46 Done.
« no previous file with comments | « chrome/browser/chromeos/extensions/file_manager/file_browser_private_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698