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

Side by Side Diff: chrome/common/file_system/file_system_dispatcher.cc

Issue 6624066: Put file_system messages in their own file and move them to content, in prepa... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/common/file_system/file_system_dispatcher.h" 5 #include "chrome/common/file_system/file_system_dispatcher.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "chrome/common/child_thread.h" 8 #include "chrome/common/child_thread.h"
9 #include "chrome/common/render_messages.h" 9 #include "content/common/file_system_messages.h"
10 #include "chrome/common/render_messages_params.h"
11 10
12 FileSystemDispatcher::FileSystemDispatcher() { 11 FileSystemDispatcher::FileSystemDispatcher() {
13 } 12 }
14 13
15 FileSystemDispatcher::~FileSystemDispatcher() { 14 FileSystemDispatcher::~FileSystemDispatcher() {
16 // Make sure we fire all the remaining callbacks. 15 // Make sure we fire all the remaining callbacks.
17 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator 16 for (IDMap<fileapi::FileSystemCallbackDispatcher, IDMapOwnPointer>::iterator
18 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) { 17 iter(&dispatchers_); !iter.IsAtEnd(); iter.Advance()) {
19 int request_id = iter.GetCurrentKey(); 18 int request_id = iter.GetCurrentKey();
20 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue(); 19 fileapi::FileSystemCallbackDispatcher* dispatcher = iter.GetCurrentValue();
21 DCHECK(dispatcher); 20 DCHECK(dispatcher);
22 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT); 21 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
23 dispatchers_.Remove(request_id); 22 dispatchers_.Remove(request_id);
24 } 23 }
25 } 24 }
26 25
27 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) { 26 bool FileSystemDispatcher::OnMessageReceived(const IPC::Message& msg) {
28 bool handled = true; 27 bool handled = true;
29 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg) 28 IPC_BEGIN_MESSAGE_MAP(FileSystemDispatcher, msg)
30 IPC_MESSAGE_HANDLER(ViewMsg_OpenFileSystemRequest_Complete, 29 IPC_MESSAGE_HANDLER(FileSystemMsg_OpenComplete, OnOpenComplete)
31 OnOpenFileSystemRequestComplete) 30 IPC_MESSAGE_HANDLER(FileSystemMsg_DidSucceed, OnDidSucceed)
32 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidSucceed, DidSucceed) 31 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadDirectory, OnDidReadDirectory)
33 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadDirectory, DidReadDirectory) 32 IPC_MESSAGE_HANDLER(FileSystemMsg_DidReadMetadata, OnDidReadMetadata)
34 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidReadMetadata, DidReadMetadata) 33 IPC_MESSAGE_HANDLER(FileSystemMsg_DidFail, OnDidFail)
35 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidFail, DidFail) 34 IPC_MESSAGE_HANDLER(FileSystemMsg_DidWrite, OnDidWrite)
36 IPC_MESSAGE_HANDLER(ViewMsg_FileSystem_DidWrite, DidWrite)
37 IPC_MESSAGE_UNHANDLED(handled = false) 35 IPC_MESSAGE_UNHANDLED(handled = false)
38 IPC_END_MESSAGE_MAP() 36 IPC_END_MESSAGE_MAP()
39 return handled; 37 return handled;
40 } 38 }
41 39
42 bool FileSystemDispatcher::OpenFileSystem( 40 bool FileSystemDispatcher::OpenFileSystem(
43 const GURL& origin_url, fileapi::FileSystemType type, 41 const GURL& origin_url, fileapi::FileSystemType type,
44 long long size, bool create, 42 long long size, bool create,
45 fileapi::FileSystemCallbackDispatcher* dispatcher) { 43 fileapi::FileSystemCallbackDispatcher* dispatcher) {
46 int request_id = dispatchers_.Add(dispatcher); 44 int request_id = dispatchers_.Add(dispatcher);
47 if (!ChildThread::current()->Send(new ViewHostMsg_OpenFileSystemRequest( 45 if (!ChildThread::current()->Send(new FileSystemHostMsg_Open(
48 request_id, origin_url, type, size, create))) { 46 request_id, origin_url, type, size, create))) {
49 dispatchers_.Remove(request_id); // destroys |dispatcher| 47 dispatchers_.Remove(request_id); // destroys |dispatcher|
50 return false; 48 return false;
51 } 49 }
52 50
53 return true; 51 return true;
54 } 52 }
55 53
56 bool FileSystemDispatcher::Move( 54 bool FileSystemDispatcher::Move(
57 const FilePath& src_path, 55 const FilePath& src_path,
58 const FilePath& dest_path, 56 const FilePath& dest_path,
59 fileapi::FileSystemCallbackDispatcher* dispatcher) { 57 fileapi::FileSystemCallbackDispatcher* dispatcher) {
60 int request_id = dispatchers_.Add(dispatcher); 58 int request_id = dispatchers_.Add(dispatcher);
61 if (!ChildThread::current()->Send(new ViewHostMsg_FileSystem_Move( 59 if (!ChildThread::current()->Send(new FileSystemHostMsg_Move(
62 request_id, src_path, dest_path))) { 60 request_id, src_path, dest_path))) {
63 dispatchers_.Remove(request_id); // destroys |dispatcher| 61 dispatchers_.Remove(request_id); // destroys |dispatcher|
64 return false; 62 return false;
65 } 63 }
66 64
67 return true; 65 return true;
68 } 66 }
69 67
70 bool FileSystemDispatcher::Copy( 68 bool FileSystemDispatcher::Copy(
71 const FilePath& src_path, 69 const FilePath& src_path,
72 const FilePath& dest_path, 70 const FilePath& dest_path,
73 fileapi::FileSystemCallbackDispatcher* dispatcher) { 71 fileapi::FileSystemCallbackDispatcher* dispatcher) {
74 int request_id = dispatchers_.Add(dispatcher); 72 int request_id = dispatchers_.Add(dispatcher);
75 if (!ChildThread::current()->Send(new ViewHostMsg_FileSystem_Copy( 73 if (!ChildThread::current()->Send(new FileSystemHostMsg_Copy(
76 request_id, src_path, dest_path))) { 74 request_id, src_path, dest_path))) {
77 dispatchers_.Remove(request_id); // destroys |dispatcher| 75 dispatchers_.Remove(request_id); // destroys |dispatcher|
78 return false; 76 return false;
79 } 77 }
80 78
81 return true; 79 return true;
82 } 80 }
83 81
84 bool FileSystemDispatcher::Remove( 82 bool FileSystemDispatcher::Remove(
85 const FilePath& path, 83 const FilePath& path,
86 bool recursive, 84 bool recursive,
87 fileapi::FileSystemCallbackDispatcher* dispatcher) { 85 fileapi::FileSystemCallbackDispatcher* dispatcher) {
88 int request_id = dispatchers_.Add(dispatcher); 86 int request_id = dispatchers_.Add(dispatcher);
89 if (!ChildThread::current()->Send( 87 if (!ChildThread::current()->Send(
90 new ViewHostMsg_FileSystem_Remove(request_id, path, recursive))) { 88 new FileSystemMsg_Remove(request_id, path, recursive))) {
91 dispatchers_.Remove(request_id); // destroys |dispatcher| 89 dispatchers_.Remove(request_id); // destroys |dispatcher|
92 return false; 90 return false;
93 } 91 }
94 92
95 return true; 93 return true;
96 } 94 }
97 95
98 bool FileSystemDispatcher::ReadMetadata( 96 bool FileSystemDispatcher::ReadMetadata(
99 const FilePath& path, 97 const FilePath& path,
100 fileapi::FileSystemCallbackDispatcher* dispatcher) { 98 fileapi::FileSystemCallbackDispatcher* dispatcher) {
101 int request_id = dispatchers_.Add(dispatcher); 99 int request_id = dispatchers_.Add(dispatcher);
102 if (!ChildThread::current()->Send( 100 if (!ChildThread::current()->Send(
103 new ViewHostMsg_FileSystem_ReadMetadata(request_id, path))) { 101 new FileSystemHostMsg_ReadMetadata(request_id, path))) {
104 dispatchers_.Remove(request_id); // destroys |dispatcher| 102 dispatchers_.Remove(request_id); // destroys |dispatcher|
105 return false; 103 return false;
106 } 104 }
107 105
108 return true; 106 return true;
109 } 107 }
110 108
111 bool FileSystemDispatcher::Create( 109 bool FileSystemDispatcher::Create(
112 const FilePath& path, 110 const FilePath& path,
113 bool exclusive, 111 bool exclusive,
114 bool is_directory, 112 bool is_directory,
115 bool recursive, 113 bool recursive,
116 fileapi::FileSystemCallbackDispatcher* dispatcher) { 114 fileapi::FileSystemCallbackDispatcher* dispatcher) {
117 int request_id = dispatchers_.Add(dispatcher); 115 int request_id = dispatchers_.Add(dispatcher);
118 if (!ChildThread::current()->Send(new ViewHostMsg_FileSystem_Create( 116 if (!ChildThread::current()->Send(new FileSystemHostMsg_Create(
119 request_id, path, exclusive, is_directory, recursive))) { 117 request_id, path, exclusive, is_directory, recursive))) {
120 dispatchers_.Remove(request_id); // destroys |dispatcher| 118 dispatchers_.Remove(request_id); // destroys |dispatcher|
121 return false; 119 return false;
122 } 120 }
123 121
124 return true; 122 return true;
125 } 123 }
126 124
127 bool FileSystemDispatcher::Exists( 125 bool FileSystemDispatcher::Exists(
128 const FilePath& path, 126 const FilePath& path,
129 bool is_directory, 127 bool is_directory,
130 fileapi::FileSystemCallbackDispatcher* dispatcher) { 128 fileapi::FileSystemCallbackDispatcher* dispatcher) {
131 int request_id = dispatchers_.Add(dispatcher); 129 int request_id = dispatchers_.Add(dispatcher);
132 if (!ChildThread::current()->Send( 130 if (!ChildThread::current()->Send(
133 new ViewHostMsg_FileSystem_Exists(request_id, path, is_directory))) { 131 new FileSystemHostMsg_Exists(request_id, path, is_directory))) {
134 dispatchers_.Remove(request_id); // destroys |dispatcher| 132 dispatchers_.Remove(request_id); // destroys |dispatcher|
135 return false; 133 return false;
136 } 134 }
137 135
138 return true; 136 return true;
139 } 137 }
140 138
141 bool FileSystemDispatcher::ReadDirectory( 139 bool FileSystemDispatcher::ReadDirectory(
142 const FilePath& path, 140 const FilePath& path,
143 fileapi::FileSystemCallbackDispatcher* dispatcher) { 141 fileapi::FileSystemCallbackDispatcher* dispatcher) {
144 int request_id = dispatchers_.Add(dispatcher); 142 int request_id = dispatchers_.Add(dispatcher);
145 if (!ChildThread::current()->Send( 143 if (!ChildThread::current()->Send(
146 new ViewHostMsg_FileSystem_ReadDirectory(request_id, path))) { 144 new FileSystemHostMsg_ReadDirectory(request_id, path))) {
147 dispatchers_.Remove(request_id); // destroys |dispatcher| 145 dispatchers_.Remove(request_id); // destroys |dispatcher|
148 return false; 146 return false;
149 } 147 }
150 148
151 return true; 149 return true;
152 } 150 }
153 151
154 bool FileSystemDispatcher::Truncate( 152 bool FileSystemDispatcher::Truncate(
155 const FilePath& path, 153 const FilePath& path,
156 int64 offset, 154 int64 offset,
157 int* request_id_out, 155 int* request_id_out,
158 fileapi::FileSystemCallbackDispatcher* dispatcher) { 156 fileapi::FileSystemCallbackDispatcher* dispatcher) {
159 int request_id = dispatchers_.Add(dispatcher); 157 int request_id = dispatchers_.Add(dispatcher);
160 if (!ChildThread::current()->Send( 158 if (!ChildThread::current()->Send(
161 new ViewHostMsg_FileSystem_Truncate(request_id, path, offset))) { 159 new FileSystemHostMsg_Truncate(request_id, path, offset))) {
162 dispatchers_.Remove(request_id); // destroys |dispatcher| 160 dispatchers_.Remove(request_id); // destroys |dispatcher|
163 return false; 161 return false;
164 } 162 }
165 163
166 if (request_id_out) 164 if (request_id_out)
167 *request_id_out = request_id; 165 *request_id_out = request_id;
168 return true; 166 return true;
169 } 167 }
170 168
171 bool FileSystemDispatcher::Write( 169 bool FileSystemDispatcher::Write(
172 const FilePath& path, 170 const FilePath& path,
173 const GURL& blob_url, 171 const GURL& blob_url,
174 int64 offset, 172 int64 offset,
175 int* request_id_out, 173 int* request_id_out,
176 fileapi::FileSystemCallbackDispatcher* dispatcher) { 174 fileapi::FileSystemCallbackDispatcher* dispatcher) {
177 int request_id = dispatchers_.Add(dispatcher); 175 int request_id = dispatchers_.Add(dispatcher);
178 if (!ChildThread::current()->Send( 176 if (!ChildThread::current()->Send(
179 new ViewHostMsg_FileSystem_Write( 177 new FileSystemHostMsg_Write(request_id, path, blob_url, offset))) {
180 request_id, path, blob_url, offset))) {
181 dispatchers_.Remove(request_id); // destroys |dispatcher| 178 dispatchers_.Remove(request_id); // destroys |dispatcher|
182 return false; 179 return false;
183 } 180 }
184 181
185 if (request_id_out) 182 if (request_id_out)
186 *request_id_out = request_id; 183 *request_id_out = request_id;
187 return true; 184 return true;
188 } 185 }
189 186
190 bool FileSystemDispatcher::Cancel( 187 bool FileSystemDispatcher::Cancel(
191 int request_id_to_cancel, 188 int request_id_to_cancel,
192 fileapi::FileSystemCallbackDispatcher* dispatcher) { 189 fileapi::FileSystemCallbackDispatcher* dispatcher) {
193 int request_id = dispatchers_.Add(dispatcher); 190 int request_id = dispatchers_.Add(dispatcher);
194 if (!ChildThread::current()->Send(new ViewHostMsg_FileSystem_CancelWrite( 191 if (!ChildThread::current()->Send(new FileSystemHostMsg_CancelWrite(
195 request_id, request_id_to_cancel))) { 192 request_id, request_id_to_cancel))) {
196 dispatchers_.Remove(request_id); // destroys |dispatcher| 193 dispatchers_.Remove(request_id); // destroys |dispatcher|
197 return false; 194 return false;
198 } 195 }
199 196
200 return true; 197 return true;
201 } 198 }
202 199
203 bool FileSystemDispatcher::TouchFile( 200 bool FileSystemDispatcher::TouchFile(
204 const FilePath& path, 201 const FilePath& path,
205 const base::Time& last_access_time, 202 const base::Time& last_access_time,
206 const base::Time& last_modified_time, 203 const base::Time& last_modified_time,
207 fileapi::FileSystemCallbackDispatcher* dispatcher) { 204 fileapi::FileSystemCallbackDispatcher* dispatcher) {
208 int request_id = dispatchers_.Add(dispatcher); 205 int request_id = dispatchers_.Add(dispatcher);
209 if (!ChildThread::current()->Send( 206 if (!ChildThread::current()->Send(
210 new ViewHostMsg_FileSystem_TouchFile( 207 new FileSystemHostMsg_TouchFile(
211 request_id, path, last_access_time, last_modified_time))) { 208 request_id, path, last_access_time, last_modified_time))) {
212 dispatchers_.Remove(request_id); // destroys |dispatcher| 209 dispatchers_.Remove(request_id); // destroys |dispatcher|
213 return false; 210 return false;
214 } 211 }
215 212
216 return true; 213 return true;
217 } 214 }
218 215
219 void FileSystemDispatcher::OnOpenFileSystemRequestComplete( 216 void FileSystemDispatcher::OnOpenComplete(
220 int request_id, bool accepted, const std::string& name, 217 int request_id, bool accepted, const std::string& name,
221 const FilePath& root_path) { 218 const FilePath& root_path) {
222 fileapi::FileSystemCallbackDispatcher* dispatcher = 219 fileapi::FileSystemCallbackDispatcher* dispatcher =
223 dispatchers_.Lookup(request_id); 220 dispatchers_.Lookup(request_id);
224 DCHECK(dispatcher); 221 DCHECK(dispatcher);
225 if (accepted) 222 if (accepted)
226 dispatcher->DidOpenFileSystem(name, root_path); 223 dispatcher->DidOpenFileSystem(name, root_path);
227 else 224 else
228 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); 225 dispatcher->DidFail(base::PLATFORM_FILE_ERROR_SECURITY);
229 dispatchers_.Remove(request_id); 226 dispatchers_.Remove(request_id);
230 } 227 }
231 228
232 void FileSystemDispatcher::DidSucceed(int request_id) { 229 void FileSystemDispatcher::OnDidSucceed(int request_id) {
233 fileapi::FileSystemCallbackDispatcher* dispatcher = 230 fileapi::FileSystemCallbackDispatcher* dispatcher =
234 dispatchers_.Lookup(request_id); 231 dispatchers_.Lookup(request_id);
235 DCHECK(dispatcher); 232 DCHECK(dispatcher);
236 dispatcher->DidSucceed(); 233 dispatcher->DidSucceed();
237 dispatchers_.Remove(request_id); 234 dispatchers_.Remove(request_id);
238 } 235 }
239 236
240 void FileSystemDispatcher::DidReadMetadata( 237 void FileSystemDispatcher::OnDidReadMetadata(
241 int request_id, const base::PlatformFileInfo& file_info) { 238 int request_id, const base::PlatformFileInfo& file_info) {
242 fileapi::FileSystemCallbackDispatcher* dispatcher = 239 fileapi::FileSystemCallbackDispatcher* dispatcher =
243 dispatchers_.Lookup(request_id); 240 dispatchers_.Lookup(request_id);
244 DCHECK(dispatcher); 241 DCHECK(dispatcher);
245 dispatcher->DidReadMetadata(file_info); 242 dispatcher->DidReadMetadata(file_info);
246 dispatchers_.Remove(request_id); 243 dispatchers_.Remove(request_id);
247 } 244 }
248 245
249 void FileSystemDispatcher::DidReadDirectory( 246 void FileSystemDispatcher::OnDidReadDirectory(
250 int request_id, 247 int request_id,
251 const std::vector<base::FileUtilProxy::Entry>& entries, 248 const std::vector<base::FileUtilProxy::Entry>& entries,
252 bool has_more) { 249 bool has_more) {
253 fileapi::FileSystemCallbackDispatcher* dispatcher = 250 fileapi::FileSystemCallbackDispatcher* dispatcher =
254 dispatchers_.Lookup(request_id); 251 dispatchers_.Lookup(request_id);
255 DCHECK(dispatcher); 252 DCHECK(dispatcher);
256 dispatcher->DidReadDirectory(entries, has_more); 253 dispatcher->DidReadDirectory(entries, has_more);
257 dispatchers_.Remove(request_id); 254 dispatchers_.Remove(request_id);
258 } 255 }
259 256
260 void FileSystemDispatcher::DidFail( 257 void FileSystemDispatcher::OnDidFail(
261 int request_id, base::PlatformFileError error_code) { 258 int request_id, base::PlatformFileError error_code) {
262 fileapi::FileSystemCallbackDispatcher* dispatcher = 259 fileapi::FileSystemCallbackDispatcher* dispatcher =
263 dispatchers_.Lookup(request_id); 260 dispatchers_.Lookup(request_id);
264 DCHECK(dispatcher); 261 DCHECK(dispatcher);
265 dispatcher->DidFail(error_code); 262 dispatcher->DidFail(error_code);
266 dispatchers_.Remove(request_id); 263 dispatchers_.Remove(request_id);
267 } 264 }
268 265
269 void FileSystemDispatcher::DidWrite( 266 void FileSystemDispatcher::OnDidWrite(
270 int request_id, int64 bytes, bool complete) { 267 int request_id, int64 bytes, bool complete) {
271 fileapi::FileSystemCallbackDispatcher* dispatcher = 268 fileapi::FileSystemCallbackDispatcher* dispatcher =
272 dispatchers_.Lookup(request_id); 269 dispatchers_.Lookup(request_id);
273 DCHECK(dispatcher); 270 DCHECK(dispatcher);
274 dispatcher->DidWrite(bytes, complete); 271 dispatcher->DidWrite(bytes, complete);
275 if (complete) 272 if (complete)
276 dispatchers_.Remove(request_id); 273 dispatchers_.Remove(request_id);
277 } 274 }
OLDNEW
« no previous file with comments | « chrome/common/file_system/file_system_dispatcher.h ('k') | chrome/common/pepper_file_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698