| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/file_handlers/mime_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "net/base/filename_util.h" | 12 #include "net/base/filename_util.h" |
| 12 #include "net/base/mime_sniffer.h" | 13 #include "net/base/mime_sniffer.h" |
| 13 #include "net/base/mime_util.h" | 14 #include "net/base/mime_util.h" |
| 14 #include "storage/browser/fileapi/file_system_url.h" | 15 #include "storage/browser/fileapi/file_system_url.h" |
| 15 | 16 |
| 16 #if defined(OS_CHROMEOS) | 17 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" | 18 #include "chrome/browser/chromeos/file_manager/filesystem_api_util.h" |
| 18 #endif | 19 #endif |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 const CompletionCallback& callback) { | 185 const CompletionCallback& callback) { |
| 185 DCHECK(!callback.is_null()); | 186 DCHECK(!callback.is_null()); |
| 186 callback_ = callback; | 187 callback_ = callback; |
| 187 | 188 |
| 188 DCHECK(!result_.get()); | 189 DCHECK(!result_.get()); |
| 189 result_.reset(new std::vector<std::string>(local_paths.size())); | 190 result_.reset(new std::vector<std::string>(local_paths.size())); |
| 190 left_ = local_paths.size(); | 191 left_ = local_paths.size(); |
| 191 | 192 |
| 192 if (!left_) { | 193 if (!left_) { |
| 193 // Nothing to process. | 194 // Nothing to process. |
| 194 base::MessageLoopProxy::current()->PostTask( | 195 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 195 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); | 196 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); |
| 196 callback_ = CompletionCallback(); | 197 callback_ = CompletionCallback(); |
| 197 return; | 198 return; |
| 198 } | 199 } |
| 199 | 200 |
| 200 for (size_t i = 0; i < local_paths.size(); ++i) { | 201 for (size_t i = 0; i < local_paths.size(); ++i) { |
| 201 GetMimeTypeForLocalPath(profile_, | 202 GetMimeTypeForLocalPath(profile_, |
| 202 local_paths[i], | 203 local_paths[i], |
| 203 base::Bind(&MimeTypeCollector::OnMimeTypeCollected, | 204 base::Bind(&MimeTypeCollector::OnMimeTypeCollected, |
| 204 weak_ptr_factory_.GetWeakPtr(), | 205 weak_ptr_factory_.GetWeakPtr(), |
| 205 i)); | 206 i)); |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 | 209 |
| 209 void MimeTypeCollector::OnMimeTypeCollected(size_t index, | 210 void MimeTypeCollector::OnMimeTypeCollected(size_t index, |
| 210 const std::string& mime_type) { | 211 const std::string& mime_type) { |
| 211 (*result_)[index] = mime_type; | 212 (*result_)[index] = mime_type; |
| 212 if (!--left_) { | 213 if (!--left_) { |
| 213 base::MessageLoopProxy::current()->PostTask( | 214 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 214 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); | 215 FROM_HERE, base::Bind(callback_, base::Passed(&result_))); |
| 215 // Release the callback to avoid a circullar reference in case an instance | 216 // Release the callback to avoid a circullar reference in case an instance |
| 216 // of this class is a member of a ref counted class, which instance is bound | 217 // of this class is a member of a ref counted class, which instance is bound |
| 217 // to this callback. | 218 // to this callback. |
| 218 callback_ = CompletionCallback(); | 219 callback_ = CompletionCallback(); |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 | 222 |
| 222 } // namespace app_file_handler_util | 223 } // namespace app_file_handler_util |
| 223 } // namespace extensions | 224 } // namespace extensions |
| OLD | NEW |