OLD | NEW |
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/browser/file_system/file_system_dispatcher_host.h" | 5 #include "chrome/browser/file_system/file_system_dispatcher_host.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/thread.h" | 8 #include "base/thread.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | |
11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_thread.h" | 11 #include "chrome/browser/chrome_thread.h" |
13 #include "chrome/browser/file_system/browser_file_system_callback_dispatcher.h" | 12 #include "chrome/browser/file_system/browser_file_system_callback_dispatcher.h" |
14 #include "chrome/browser/file_system/file_system_host_context.h" | 13 #include "chrome/browser/file_system/file_system_host_context.h" |
15 #include "chrome/browser/host_content_settings_map.h" | 14 #include "chrome/browser/host_content_settings_map.h" |
16 #include "chrome/browser/renderer_host/browser_render_process_host.h" | 15 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
17 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
18 #include "chrome/common/render_messages_params.h" | 17 #include "chrome/common/render_messages_params.h" |
19 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
20 #include "webkit/glue/webkit_glue.h" | |
21 | 19 |
22 // A class to hold an ongoing openFileSystem completion task. | 20 // A class to hold an ongoing openFileSystem completion task. |
23 struct OpenFileSystemCompletionTask { | 21 struct OpenFileSystemCompletionTask { |
24 public: | 22 public: |
25 static void Run( | 23 static void Run( |
26 int request_id, | 24 int request_id, |
27 int routing_id, | |
28 const std::string& name, | 25 const std::string& name, |
29 const FilePath& root_path, | 26 const FilePath& root_path, |
30 FileSystemDispatcherHost* dispatcher_host) { | 27 FileSystemDispatcherHost* dispatcher_host) { |
31 // The task is self-destructed. | 28 // The task is self-destructed. |
32 new OpenFileSystemCompletionTask(request_id, routing_id, name, root_path, | 29 new OpenFileSystemCompletionTask(request_id, name, root_path, |
33 dispatcher_host); | 30 dispatcher_host); |
34 } | 31 } |
35 | 32 |
36 void DidFinish(base::PlatformFileError error) { | 33 void DidFinish(base::PlatformFileError error) { |
37 if (error == base::PLATFORM_FILE_OK) | 34 if (error == base::PLATFORM_FILE_OK) |
38 dispatcher_host_->Send( | 35 dispatcher_host_->Send( |
39 new ViewMsg_OpenFileSystemRequest_Complete( | 36 new ViewMsg_OpenFileSystemRequest_Complete( |
40 routing_id_, request_id_, true, UTF8ToUTF16(name_), | 37 request_id_, true, name_, root_path_)); |
41 webkit_glue::FilePathToWebString(root_path_))); | |
42 else | 38 else |
43 dispatcher_host_->Send( | 39 dispatcher_host_->Send( |
44 new ViewMsg_OpenFileSystemRequest_Complete( | 40 new ViewMsg_OpenFileSystemRequest_Complete( |
45 routing_id_, request_id_, false, string16(), string16())); | 41 request_id_, false, std::string(), FilePath())); |
46 delete this; | 42 delete this; |
47 } | 43 } |
48 | 44 |
49 private: | 45 private: |
50 OpenFileSystemCompletionTask( | 46 OpenFileSystemCompletionTask( |
51 int request_id, | 47 int request_id, |
52 int routing_id, | |
53 const std::string& name, | 48 const std::string& name, |
54 const FilePath& root_path, | 49 const FilePath& root_path, |
55 FileSystemDispatcherHost* dispatcher_host) | 50 FileSystemDispatcherHost* dispatcher_host) |
56 : request_id_(request_id), | 51 : request_id_(request_id), |
57 routing_id_(routing_id), | |
58 name_(name), | 52 name_(name), |
59 root_path_(root_path), | 53 root_path_(root_path), |
60 dispatcher_host_(dispatcher_host), | 54 dispatcher_host_(dispatcher_host), |
61 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 55 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
62 base::FileUtilProxy::CreateDirectory( | 56 base::FileUtilProxy::CreateDirectory( |
63 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE), | 57 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE), |
64 root_path_, false, true, callback_factory_.NewCallback( | 58 root_path_, false, true, callback_factory_.NewCallback( |
65 &OpenFileSystemCompletionTask::DidFinish)); | 59 &OpenFileSystemCompletionTask::DidFinish)); |
66 } | 60 } |
67 | 61 |
68 int request_id_; | 62 int request_id_; |
69 int routing_id_; | |
70 std::string name_; | 63 std::string name_; |
71 FilePath root_path_; | 64 FilePath root_path_; |
72 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; | 65 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; |
73 base::ScopedCallbackFactory<OpenFileSystemCompletionTask> callback_factory_; | 66 base::ScopedCallbackFactory<OpenFileSystemCompletionTask> callback_factory_; |
74 }; | 67 }; |
75 | 68 |
76 FileSystemDispatcherHost::FileSystemDispatcherHost( | 69 FileSystemDispatcherHost::FileSystemDispatcherHost( |
77 IPC::Message::Sender* sender, | 70 IPC::Message::Sender* sender, |
78 FileSystemHostContext* file_system_host_context, | 71 FileSystemHostContext* file_system_host_context, |
79 HostContentSettingsMap* host_content_settings_map) | 72 HostContentSettingsMap* host_content_settings_map) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata) | 107 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata) |
115 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate) | 108 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate) |
116 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists) | 109 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists) |
117 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadDirectory, OnReadDirectory) | 110 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadDirectory, OnReadDirectory) |
118 IPC_MESSAGE_UNHANDLED(handled = false) | 111 IPC_MESSAGE_UNHANDLED(handled = false) |
119 IPC_END_MESSAGE_MAP_EX() | 112 IPC_END_MESSAGE_MAP_EX() |
120 return handled; | 113 return handled; |
121 } | 114 } |
122 | 115 |
123 void FileSystemDispatcherHost::OnOpenFileSystem( | 116 void FileSystemDispatcherHost::OnOpenFileSystem( |
124 const ViewHostMsg_OpenFileSystemRequest_Params& params) { | 117 int request_id, const GURL& origin_url, fileapi::FileSystemType type, |
| 118 int64 requested_size) { |
125 | 119 |
126 // TODO(kinuko): hook up ContentSettings cookies type checks. | 120 // TODO(kinuko): hook up ContentSettings cookies type checks. |
127 | 121 |
128 FilePath root_path; | 122 FilePath root_path; |
129 std::string name; | 123 std::string name; |
130 | 124 |
131 if (!context_->GetFileSystemRootPath(params.origin_url, | 125 if (!context_->GetFileSystemRootPath(origin_url, |
132 params.type, | 126 type, |
133 &root_path, | 127 &root_path, |
134 &name)) { | 128 &name)) { |
135 Send(new ViewMsg_OpenFileSystemRequest_Complete( | 129 Send(new ViewMsg_OpenFileSystemRequest_Complete( |
136 params.routing_id, | 130 request_id, |
137 params.request_id, | |
138 false, | 131 false, |
139 string16(), | 132 std::string(), |
140 string16())); | 133 FilePath())); |
141 return; | 134 return; |
142 } | 135 } |
143 | 136 |
144 // Run the completion task that creates the root directory and sends | 137 // Run the completion task that creates the root directory and sends |
145 // back the status code to the dispatcher. | 138 // back the status code to the dispatcher. |
146 OpenFileSystemCompletionTask::Run( | 139 OpenFileSystemCompletionTask::Run(request_id, name, root_path, this); |
147 params.request_id, params.routing_id, name, root_path, this); | |
148 } | 140 } |
149 | 141 |
150 void FileSystemDispatcherHost::OnMove( | 142 void FileSystemDispatcherHost::OnMove( |
151 int request_id, const FilePath& src_path, const FilePath& dest_path) { | 143 int request_id, const FilePath& src_path, const FilePath& dest_path) { |
152 if (!CheckValidFileSystemPath(src_path, request_id) || | 144 if (!CheckValidFileSystemPath(src_path, request_id) || |
153 !CheckValidFileSystemPath(dest_path, request_id)) | 145 !CheckValidFileSystemPath(dest_path, request_id)) |
154 return; | 146 return; |
155 | 147 |
156 GetNewOperation(request_id)->Move(src_path, dest_path); | 148 GetNewOperation(request_id)->Move(src_path, dest_path); |
157 } | 149 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 dispatcher, | 226 dispatcher, |
235 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); | 227 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)); |
236 operations_.AddWithID(operation, request_id); | 228 operations_.AddWithID(operation, request_id); |
237 return operation; | 229 return operation; |
238 } | 230 } |
239 | 231 |
240 void FileSystemDispatcherHost::RemoveCompletedOperation(int request_id) { | 232 void FileSystemDispatcherHost::RemoveCompletedOperation(int request_id) { |
241 DCHECK(operations_.Lookup(request_id)); | 233 DCHECK(operations_.Lookup(request_id)); |
242 operations_.Remove(request_id); | 234 operations_.Remove(request_id); |
243 } | 235 } |
OLD | NEW |