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

Side by Side Diff: Source/modules/filesystem/LocalFileSystem.cpp

Issue 277353002: Use asynchronized api for file system request. [blink] (3/4) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Changes are made. Created 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 23 matching lines...) Expand all
34 #include "core/dom/CrossThreadTask.h" 34 #include "core/dom/CrossThreadTask.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "core/fileapi/FileError.h" 38 #include "core/fileapi/FileError.h"
39 #include "core/inspector/InspectorController.h" 39 #include "core/inspector/InspectorController.h"
40 #include "core/workers/WorkerGlobalScope.h" 40 #include "core/workers/WorkerGlobalScope.h"
41 #include "modules/filesystem/FileSystemClient.h" 41 #include "modules/filesystem/FileSystemClient.h"
42 #include "modules/filesystem/InspectorFileSystemAgent.h" 42 #include "modules/filesystem/InspectorFileSystemAgent.h"
43 #include "platform/AsyncFileSystemCallbacks.h" 43 #include "platform/AsyncFileSystemCallbacks.h"
44 #include "platform/PermissionCallbacks.h"
44 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
45 #include "public/platform/WebFileSystem.h" 46 #include "public/platform/WebFileSystem.h"
46 47
47 namespace WebCore { 48 namespace WebCore {
48 49
49 namespace { 50 namespace {
50 51
51 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks) 52 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks)
52 { 53 {
53 callbacks->didFail(FileError::ABORT_ERR); 54 callbacks->didFail(FileError::ABORT_ERR);
54 } 55 }
55 56
56 } // namespace 57 } // namespace
57 58
58 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client) 59 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client)
59 { 60 {
60 return adoptPtrWillBeNoop(new LocalFileSystem(client)); 61 return adoptPtrWillBeNoop(new LocalFileSystem(client));
61 } 62 }
62 63
63 LocalFileSystem::~LocalFileSystem() 64 LocalFileSystem::~LocalFileSystem()
64 { 65 {
65 } 66 }
66 67
67 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 68 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
68 { 69 {
69 if (!client() || !client()->allowFileSystem(context)) { 70 RefPtr<ExecutionContext> contextPtr(context);
70 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); 71 if (!client()) {
72 fileSystemNotAllowedInternal(contextPtr, callbacks);
71 return; 73 return;
72 } 74 }
73 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s); 75 ASSERT(contextPtr);
76 if (!contextPtr->isDocument()) {
77 if (!client()->requestFileSystemAccessSync(contextPtr.get())) {
78 fileSystemNotAllowedInternal(contextPtr, callbacks);
79 return;
80 }
81 resolveURLInternal(fileSystemURL, callbacks);
82 return;
83 }
84 requestFileSystemAccesssAsyncInternal(contextPtr, bind(&LocalFileSystem::res olveURLInternal, this, fileSystemURL, callbacks), bind(&LocalFileSystem::fileSys temNotAllowedInternal, this, contextPtr, callbacks));
kinuko 2014/05/21 07:24:24 Um, looking this closely actually this wouldn't wo
Xi Han 2014/05/21 19:50:05 1. Great catch! I introduced a wrapper RefCounted
kinuko 2014/05/22 10:37:42 Can't the common method do just like: { if (!
Xi Han 2014/05/22 14:21:41 Thank you for the correction and the rough patch.
74 } 85 }
75 86
76 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 87 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
77 { 88 {
78 if (!client() || !client()->allowFileSystem(context)) { 89 RefPtr<ExecutionContext> contextPtr(context);
79 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); 90 if (!client()) {
91 fileSystemNotAllowedInternal(contextPtr, callbacks);
80 return; 92 return;
81 } 93 }
94 ASSERT(contextPtr);
95 if (!contextPtr->isDocument()) {
96 if (!client()->requestFileSystemAccessSync(contextPtr.get())) {
97 fileSystemNotAllowedInternal(contextPtr, callbacks);
98 return;
99 }
100 fileSystemAllowedInternal(contextPtr, type, callbacks);
101 return;
102 }
103 requestFileSystemAccesssAsyncInternal(contextPtr, bind(&LocalFileSystem::fil eSystemAllowedInternal, this, contextPtr, type, callbacks), bind(&LocalFileSyste m::fileSystemNotAllowedInternal, this, contextPtr, callbacks));
104 }
105
106 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
107 {
108 RefPtr<ExecutionContext> contextPtr(context);
109 ASSERT(contextPtr);
110 ASSERT_WITH_SECURITY_IMPLICATION(contextPtr->isDocument());
111 if (!client()) {
112 fileSystemNotAllowedInternal(contextPtr, callbacks);
113 return;
114 }
115 requestFileSystemAccesssAsyncInternal(contextPtr, bind(&LocalFileSystem::del eteFileSystemInternal, this, contextPtr, type, callbacks), bind(&LocalFileSystem ::fileSystemNotAllowedInternal, this, contextPtr, callbacks));
116 }
117
118 void LocalFileSystem::fileSystemNotAllowedInternal(
119 PassRefPtr<ExecutionContext> context,
120 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) {
121 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
122 }
123
124 void LocalFileSystem::fileSystemAllowedInternal(
125 PassRefPtr<ExecutionContext> context,
126 FileSystemType type,
127 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) {
82 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); 128 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
83 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks); 129 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks);
84 } 130 }
85 131
86 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 132 void LocalFileSystem::resolveURLInternal(
87 { 133 const KURL& fileSystemURL,
88 ASSERT(context); 134 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) {
89 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); 135 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s);
136 }
90 137
91 if (!client() || !client()->allowFileSystem(context)) { 138 void LocalFileSystem::deleteFileSystemInternal(
92 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); 139 PassRefPtr<ExecutionContext> context,
93 return; 140 FileSystemType type,
94 } 141 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) {
95 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); 142 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
96 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); 143 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks);
97 } 144 }
98 145
146 void LocalFileSystem::requestFileSystemAccesssAsyncInternal(
147 PassRefPtr<ExecutionContext> context,
148 const Closure& allowedCallback,
149 const Closure& deniedCallback) {
150 client()->requestFileSystemAccessAsync(context.get(), PermissionCallbacks::c reate(allowedCallback, deniedCallback));
151 }
152
99 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) 153 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client)
100 : m_client(client) 154 : m_client(client)
101 { 155 {
102 } 156 }
103 157
104 const char* LocalFileSystem::supplementName() 158 const char* LocalFileSystem::supplementName()
105 { 159 {
106 return "LocalFileSystem"; 160 return "LocalFileSystem";
107 } 161 }
108 162
(...skipping 11 matching lines...) Expand all
120 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client)); 174 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client));
121 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page)); 175 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page));
122 } 176 }
123 177
124 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client) 178 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client)
125 { 179 {
126 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client)); 180 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client));
127 } 181 }
128 182
129 } // namespace WebCore 183 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698