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

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: Update CL according to changes in CL 289793002. 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"
47 #include "wtf/Functional.h"
46 48
47 namespace WebCore { 49 namespace WebCore {
48 50
49 namespace { 51 namespace {
50 52
51 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks) 53 void fileSystemNotAllowed(ExecutionContext*, PassOwnPtr<AsyncFileSystemCallbacks > callbacks)
52 { 54 {
53 callbacks->didFail(FileError::ABORT_ERR); 55 callbacks->didFail(FileError::ABORT_ERR);
54 } 56 }
55 57
56 } // namespace 58 } // namespace
57 59
58 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client) 60 PassOwnPtrWillBeRawPtr<LocalFileSystem> LocalFileSystem::create(PassOwnPtr<FileS ystemClient> client)
59 { 61 {
60 return adoptPtrWillBeNoop(new LocalFileSystem(client)); 62 return adoptPtrWillBeNoop(new LocalFileSystem(client));
61 } 63 }
62 64
63 LocalFileSystem::~LocalFileSystem() 65 LocalFileSystem::~LocalFileSystem()
64 { 66 {
65 } 67 }
66 68
67 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 69 void LocalFileSystem::resolveURL(ExecutionContext* context, const KURL& fileSyst emURL, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
68 { 70 {
69 if (!client() || !client()->allowFileSystem(context)) { 71 if (!client() || !client()->requestFileSystemAccessSync(context)) {
kinuko 2014/05/16 10:47:05 Why we call Sync one here? resolveURL could be ca
Xi Han 2014/05/16 19:48:44 Great catch! The deleteFileSystem is the same case
70 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); 72 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
71 return; 73 return;
72 } 74 }
73 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s); 75 blink::Platform::current()->fileSystem()->resolveURL(fileSystemURL, callback s);
74 } 76 }
75 77
76 void LocalFileSystem::requestFileSystem(ExecutionContext* context, FileSystemTyp e type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 78 void LocalFileSystem::requestFileSystemSync(ExecutionContext* context, FileSyste mType type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
77 { 79 {
78 if (!client() || !client()->allowFileSystem(context)) { 80 if (!client() || !client()->requestFileSystemAccessSync(context)) {
79 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); 81 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
80 return; 82 return;
81 } 83 }
82 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); 84 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
83 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks); 85 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks);
84 } 86 }
85 87
88 void LocalFileSystem::requestFileSystemAsync(ExecutionContext* context, FileSyst emType type, long long size, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
89 {
90 if (!client()) {
91 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
92 return;
93 }
94 client()->requestFileSystemAccessAsync(context, PermissionCallbacks::create(
95 bind(&LocalFileSystem::fileSystemAllowedCallbacks, this, context, type, callbacks),
kinuko 2014/05/16 10:47:05 I haven't looked deeper into the bind implementati
Xi Han 2014/05/16 19:48:44 Done.
96 bind(&LocalFileSystem::fileSystemNotAllowedCallbacks, this, context, cal lbacks)));
97 }
98
99 void LocalFileSystem::fileSystemNotAllowedCallbacks(
100 ExecutionContext* context,
101 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) {
102 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
103 }
104
105 void LocalFileSystem::fileSystemAllowedCallbacks(
106 ExecutionContext* context,
107 FileSystemType type,
108 PassOwnPtr<AsyncFileSystemCallbacks> callbacks) {
109 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
110 blink::Platform::current()->fileSystem()->openFileSystem(storagePartition, s tatic_cast<blink::WebFileSystemType>(type), callbacks);
111 }
112
86 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks) 113 void LocalFileSystem::deleteFileSystem(ExecutionContext* context, FileSystemType type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
87 { 114 {
88 ASSERT(context); 115 ASSERT(context);
89 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument()); 116 ASSERT_WITH_SECURITY_IMPLICATION(context->isDocument());
90 117
91 if (!client() || !client()->allowFileSystem(context)) { 118
119 if (!client() || !client()->requestFileSystemAccessSync(context)) {
92 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks)); 120 context->postTask(createCallbackTask(&fileSystemNotAllowed, callbacks));
93 return; 121 return;
94 } 122 }
95 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString()); 123 KURL storagePartition = KURL(KURL(), context->securityOrigin()->toString());
96 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks); 124 blink::Platform::current()->fileSystem()->deleteFileSystem(storagePartition, static_cast<blink::WebFileSystemType>(type), callbacks);
97 } 125 }
98 126
99 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client) 127 LocalFileSystem::LocalFileSystem(PassOwnPtr<FileSystemClient> client)
100 : m_client(client) 128 : m_client(client)
101 { 129 {
(...skipping 18 matching lines...) Expand all
120 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client)); 148 page.provideSupplement(LocalFileSystem::supplementName(), LocalFileSystem::c reate(client));
121 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page)); 149 page.inspectorController().registerModuleAgent(InspectorFileSystemAgent::cre ate(&page));
122 } 150 }
123 151
124 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client) 152 void provideLocalFileSystemToWorker(WorkerClients* clients, PassOwnPtr<FileSyste mClient> client)
125 { 153 {
126 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client)); 154 clients->provideSupplement(LocalFileSystem::supplementName(), LocalFileSyste m::create(client));
127 } 155 }
128 156
129 } // namespace WebCore 157 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698