| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/extensions/file_browser_handler_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_handler_api.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 const GURL& file_system_root) { | 172 const GURL& file_system_root) { |
| 173 bool success = (error == base::PLATFORM_FILE_OK); | 173 bool success = (error == base::PLATFORM_FILE_OK); |
| 174 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 174 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, |
| 175 base::Bind(callback, success, file_system_name, file_system_root)); | 175 base::Bind(callback, success, file_system_name, file_system_root)); |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace | 178 } // namespace |
| 179 | 179 |
| 180 FileHandlerSelectFileFunction::FileHandlerSelectFileFunction() {} | 180 FileHandlerSelectFileFunction::FileHandlerSelectFileFunction() {} |
| 181 | 181 |
| 182 void FileHandlerSelectFileFunction::OnFilePathSelected( |
| 183 bool success, |
| 184 const FilePath& full_path) { |
| 185 if (!success) { |
| 186 Respond(false, std::string(), GURL(), FilePath()); |
| 187 return; |
| 188 } |
| 189 |
| 190 full_path_ = full_path; |
| 191 |
| 192 BrowserContext::GetFileSystemContext(profile_)->OpenFileSystem( |
| 193 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, |
| 194 base::Bind(&RelayOpenFileSystemCallbackToFileThread, |
| 195 base::Bind(&FileHandlerSelectFileFunction::CreateFileOnFileThread, |
| 196 this))); |
| 197 }; |
| 198 |
| 199 // static |
| 200 void FileHandlerSelectFileFunction::set_file_selector_for_test( |
| 201 FileSelector* file_selector) { |
| 202 FileHandlerSelectFileFunction::file_selector_for_test_ = file_selector; |
| 203 } |
| 204 |
| 205 // static |
| 206 void FileHandlerSelectFileFunction::set_gesture_check_disabled_for_test( |
| 207 bool disabled) { |
| 208 FileHandlerSelectFileFunction::gesture_check_disabled_for_test_ = disabled; |
| 209 } |
| 210 |
| 182 FileHandlerSelectFileFunction::~FileHandlerSelectFileFunction() {} | 211 FileHandlerSelectFileFunction::~FileHandlerSelectFileFunction() {} |
| 183 | 212 |
| 184 bool FileHandlerSelectFileFunction::RunImpl() { | 213 bool FileHandlerSelectFileFunction::RunImpl() { |
| 185 scoped_ptr<SelectFile::Params> params(SelectFile::Params::Create(*args_)); | 214 scoped_ptr<SelectFile::Params> params(SelectFile::Params::Create(*args_)); |
| 186 | 215 |
| 187 FilePath suggested_name(params->selection_params.suggested_name); | 216 FilePath suggested_name(params->selection_params.suggested_name); |
| 188 | 217 |
| 189 if (!user_gesture() && !gesture_check_disabled_for_test_) { | 218 if (!user_gesture() && !gesture_check_disabled_for_test_) { |
| 190 error_ = kNoUserGestureError; | 219 error_ = kNoUserGestureError; |
| 191 return false; | 220 return false; |
| 192 } | 221 } |
| 193 | 222 |
| 194 // If |file_selector_| is set (e.g. in test), use it instesad of creating new | 223 // If |file_selector_| is set (e.g. in test), use it instesad of creating new |
| 195 // file selector. | 224 // file selector. |
| 196 FileSelector* file_selector = GetFileSelector(); | 225 FileSelector* file_selector = GetFileSelector(); |
| 197 file_selector->SelectFile(suggested_name.BaseName(), GetCurrentBrowser()); | 226 file_selector->SelectFile(suggested_name.BaseName(), GetCurrentBrowser()); |
| 198 return true; | 227 return true; |
| 199 } | 228 } |
| 200 | 229 |
| 201 // static | |
| 202 void FileHandlerSelectFileFunction::set_file_selector_for_test( | |
| 203 FileSelector* file_selector) { | |
| 204 FileHandlerSelectFileFunction::file_selector_for_test_ = file_selector; | |
| 205 } | |
| 206 | |
| 207 // static | |
| 208 void FileHandlerSelectFileFunction::set_gesture_check_disabled_for_test( | |
| 209 bool disabled) { | |
| 210 FileHandlerSelectFileFunction::gesture_check_disabled_for_test_ = disabled; | |
| 211 } | |
| 212 | |
| 213 void FileHandlerSelectFileFunction::OnFilePathSelected( | |
| 214 bool success, | |
| 215 const FilePath& full_path) { | |
| 216 if (!success) { | |
| 217 Respond(false, std::string(), GURL(), FilePath()); | |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 full_path_ = full_path; | |
| 222 | |
| 223 BrowserContext::GetFileSystemContext(profile_)->OpenFileSystem( | |
| 224 source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false, | |
| 225 base::Bind(&RelayOpenFileSystemCallbackToFileThread, | |
| 226 base::Bind(&FileHandlerSelectFileFunction::CreateFileOnFileThread, | |
| 227 this))); | |
| 228 }; | |
| 229 | |
| 230 void FileHandlerSelectFileFunction::CreateFileOnFileThread( | 230 void FileHandlerSelectFileFunction::CreateFileOnFileThread( |
| 231 bool success, | 231 bool success, |
| 232 const std::string& file_system_name, | 232 const std::string& file_system_name, |
| 233 const GURL& file_system_root) { | 233 const GURL& file_system_root) { |
| 234 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); | 234 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); |
| 235 | 235 |
| 236 if (success) | 236 if (success) |
| 237 success = DoCreateFile(); | 237 success = DoCreateFile(); |
| 238 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | 238 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 239 base::Bind(&FileHandlerSelectFileFunction::OnFileCreated, this, | 239 base::Bind(&FileHandlerSelectFileFunction::OnFileCreated, this, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 result->set_function_for_test(this); | 315 result->set_function_for_test(this); |
| 316 return result; | 316 return result; |
| 317 } | 317 } |
| 318 return new FileSelectorImpl(this); | 318 return new FileSelectorImpl(this); |
| 319 } | 319 } |
| 320 | 320 |
| 321 FileSelector* FileHandlerSelectFileFunction::file_selector_for_test_ = NULL; | 321 FileSelector* FileHandlerSelectFileFunction::file_selector_for_test_ = NULL; |
| 322 | 322 |
| 323 bool FileHandlerSelectFileFunction::gesture_check_disabled_for_test_ = false; | 323 bool FileHandlerSelectFileFunction::gesture_check_disabled_for_test_ = false; |
| 324 | 324 |
| OLD | NEW |