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 "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "webkit/fileapi/file_system_quota.h" | 24 #include "webkit/fileapi/file_system_quota.h" |
25 | 25 |
26 using fileapi::FileSystemQuota; | 26 using fileapi::FileSystemQuota; |
27 | 27 |
28 class FileSystemDispatcherHost::OpenFileSystemTask { | 28 class FileSystemDispatcherHost::OpenFileSystemTask { |
29 public: | 29 public: |
30 static void Start( | 30 static void Start( |
31 int request_id, | 31 int request_id, |
32 const GURL& origin_url, | 32 const GURL& origin_url, |
33 fileapi::FileSystemType type, | 33 fileapi::FileSystemType type, |
| 34 bool create, |
34 FileSystemDispatcherHost* dispatcher_host) { | 35 FileSystemDispatcherHost* dispatcher_host) { |
35 // The task is self-destructed. | 36 // The task is self-destructed. |
36 new OpenFileSystemTask(request_id, origin_url, type, dispatcher_host); | 37 new OpenFileSystemTask( |
| 38 request_id, origin_url, type, create, dispatcher_host); |
37 } | 39 } |
38 | 40 |
39 private: | 41 private: |
40 void DidGetRootPath(bool success, const FilePath& root_path, | 42 void DidGetRootPath(bool success, const FilePath& root_path, |
41 const std::string& name) { | 43 const std::string& name) { |
42 if (success) | 44 if (success) |
43 dispatcher_host_->Send( | 45 dispatcher_host_->Send( |
44 new ViewMsg_OpenFileSystemRequest_Complete( | 46 new ViewMsg_OpenFileSystemRequest_Complete( |
45 request_id_, true, name, root_path)); | 47 request_id_, true, name, root_path)); |
46 else | 48 else |
47 dispatcher_host_->Send( | 49 dispatcher_host_->Send( |
48 new ViewMsg_OpenFileSystemRequest_Complete( | 50 new ViewMsg_OpenFileSystemRequest_Complete( |
49 request_id_, false, std::string(), FilePath())); | 51 request_id_, false, std::string(), FilePath())); |
50 delete this; | 52 delete this; |
51 } | 53 } |
52 | 54 |
53 OpenFileSystemTask( | 55 OpenFileSystemTask( |
54 int request_id, | 56 int request_id, |
55 const GURL& origin_url, | 57 const GURL& origin_url, |
56 fileapi::FileSystemType type, | 58 fileapi::FileSystemType type, |
| 59 bool create, |
57 FileSystemDispatcherHost* dispatcher_host) | 60 FileSystemDispatcherHost* dispatcher_host) |
58 : request_id_(request_id), | 61 : request_id_(request_id), |
59 dispatcher_host_(dispatcher_host), | 62 dispatcher_host_(dispatcher_host), |
60 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 63 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
61 dispatcher_host->context_->path_manager()->GetFileSystemRootPath( | 64 dispatcher_host->context_->path_manager()->GetFileSystemRootPath( |
62 origin_url, type, true /* create */, | 65 origin_url, type, create, |
63 callback_factory_.NewCallback(&OpenFileSystemTask::DidGetRootPath)); | 66 callback_factory_.NewCallback(&OpenFileSystemTask::DidGetRootPath)); |
64 } | 67 } |
65 | 68 |
66 int request_id_; | 69 int request_id_; |
67 std::string name_; | 70 std::string name_; |
68 FilePath root_path_; | 71 FilePath root_path_; |
69 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; | 72 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; |
70 base::ScopedCallbackFactory<OpenFileSystemTask> callback_factory_; | 73 base::ScopedCallbackFactory<OpenFileSystemTask> callback_factory_; |
71 }; | 74 }; |
72 | 75 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Truncate, OnTruncate) | 134 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Truncate, OnTruncate) |
132 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_TouchFile, OnTouchFile) | 135 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_TouchFile, OnTouchFile) |
133 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_CancelWrite, OnCancel) | 136 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_CancelWrite, OnCancel) |
134 IPC_MESSAGE_UNHANDLED(handled = false) | 137 IPC_MESSAGE_UNHANDLED(handled = false) |
135 IPC_END_MESSAGE_MAP_EX() | 138 IPC_END_MESSAGE_MAP_EX() |
136 return handled; | 139 return handled; |
137 } | 140 } |
138 | 141 |
139 void FileSystemDispatcherHost::OnOpenFileSystem( | 142 void FileSystemDispatcherHost::OnOpenFileSystem( |
140 int request_id, const GURL& origin_url, fileapi::FileSystemType type, | 143 int request_id, const GURL& origin_url, fileapi::FileSystemType type, |
141 int64 requested_size) { | 144 int64 requested_size, bool create) { |
142 ContentSetting content_setting = | 145 ContentSetting content_setting = |
143 host_content_settings_map_->GetContentSetting( | 146 host_content_settings_map_->GetContentSetting( |
144 origin_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 147 origin_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
145 DCHECK((content_setting == CONTENT_SETTING_ALLOW) || | 148 DCHECK((content_setting == CONTENT_SETTING_ALLOW) || |
146 (content_setting == CONTENT_SETTING_BLOCK) || | 149 (content_setting == CONTENT_SETTING_BLOCK) || |
147 (content_setting == CONTENT_SETTING_SESSION_ONLY)); | 150 (content_setting == CONTENT_SETTING_SESSION_ONLY)); |
148 if (content_setting == CONTENT_SETTING_BLOCK) { | 151 if (content_setting == CONTENT_SETTING_BLOCK) { |
149 // TODO(kinuko): Need to notify the UI thread to indicate that | 152 // TODO(kinuko): Need to notify the UI thread to indicate that |
150 // there's a blocked content. | 153 // there's a blocked content. |
151 Send(new ViewMsg_OpenFileSystemRequest_Complete( | 154 Send(new ViewMsg_OpenFileSystemRequest_Complete( |
152 request_id, false, std::string(), FilePath())); | 155 request_id, false, std::string(), FilePath())); |
153 return; | 156 return; |
154 } | 157 } |
155 | 158 |
156 OpenFileSystemTask::Start(request_id, origin_url, type, this); | 159 OpenFileSystemTask::Start(request_id, origin_url, type, create, this); |
157 } | 160 } |
158 | 161 |
159 void FileSystemDispatcherHost::OnMove( | 162 void FileSystemDispatcherHost::OnMove( |
160 int request_id, const FilePath& src_path, const FilePath& dest_path) { | 163 int request_id, const FilePath& src_path, const FilePath& dest_path) { |
161 if (!VerifyFileSystemPathForRead(src_path, request_id) || | 164 if (!VerifyFileSystemPathForRead(src_path, request_id) || |
162 !VerifyFileSystemPathForWrite(dest_path, request_id, true /* create */, | 165 !VerifyFileSystemPathForWrite(dest_path, request_id, true /* create */, |
163 FileSystemQuota::kUnknownSize)) | 166 FileSystemQuota::kUnknownSize)) |
164 return; | 167 return; |
165 | 168 |
166 GetNewOperation(request_id)->Move(src_path, dest_path); | 169 GetNewOperation(request_id)->Move(src_path, dest_path); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 dispatcher, | 341 dispatcher, |
339 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | 342 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
340 operations_.AddWithID(operation, request_id); | 343 operations_.AddWithID(operation, request_id); |
341 return operation; | 344 return operation; |
342 } | 345 } |
343 | 346 |
344 void FileSystemDispatcherHost::RemoveCompletedOperation(int request_id) { | 347 void FileSystemDispatcherHost::RemoveCompletedOperation(int request_id) { |
345 DCHECK(operations_.Lookup(request_id)); | 348 DCHECK(operations_.Lookup(request_id)); |
346 operations_.Remove(request_id); | 349 operations_.Remove(request_id); |
347 } | 350 } |
OLD | NEW |