| 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 // This file provides MIME related utilities. | 5 // This file provides MIME related utilities. |
| 6 | 6 |
| 7 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_MIME_UTIL_H_ | 7 #ifndef CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_MIME_UTIL_H_ |
| 8 #define CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_MIME_UTIL_H_ | 8 #define CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_MIME_UTIL_H_ |
| 9 | 9 |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| 11 | 11 |
| 12 #include <memory> |
| 12 #include <string> | 13 #include <string> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/callback.h" | 16 #include "base/callback.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 | 19 |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 namespace base { | 22 namespace base { |
| 23 class FilePath; | 23 class FilePath; |
| 24 } // namespace base | 24 } // namespace base |
| 25 | 25 |
| 26 namespace storage { | 26 namespace storage { |
| 27 class FileSystemURL; | 27 class FileSystemURL; |
| 28 } // namespace storage | 28 } // namespace storage |
| 29 | 29 |
| 30 namespace extensions { | 30 namespace extensions { |
| 31 namespace app_file_handler_util { | 31 namespace app_file_handler_util { |
| 32 | 32 |
| 33 // Gets a MIME type for a local path and returns it with |callback|. If not | 33 // Gets a MIME type for a local path and returns it with |callback|. If not |
| 34 // found, then the MIME type is an empty string. | 34 // found, then the MIME type is an empty string. |
| 35 void GetMimeTypeForLocalPath( | 35 void GetMimeTypeForLocalPath( |
| 36 Profile* profile, | 36 Profile* profile, |
| 37 const base::FilePath& local_path, | 37 const base::FilePath& local_path, |
| 38 const base::Callback<void(const std::string&)>& callback); | 38 const base::Callback<void(const std::string&)>& callback); |
| 39 | 39 |
| 40 // Collects MIME types for files passed in the input vector. For non-native | 40 // Collects MIME types for files passed in the input vector. For non-native |
| 41 // file systems tries to fetch the MIME type from metadata. For native ones, | 41 // file systems tries to fetch the MIME type from metadata. For native ones, |
| 42 // tries to sniff or guess by looking at the extension. If MIME type is not | 42 // tries to sniff or guess by looking at the extension. If MIME type is not |
| 43 // available, then an empty string is returned in the result vector. | 43 // available, then an empty string is returned in the result vector. |
| 44 class MimeTypeCollector { | 44 class MimeTypeCollector { |
| 45 public: | 45 public: |
| 46 typedef base::Callback<void(scoped_ptr<std::vector<std::string> >)> | 46 typedef base::Callback<void(std::unique_ptr<std::vector<std::string>>)> |
| 47 CompletionCallback; | 47 CompletionCallback; |
| 48 | 48 |
| 49 explicit MimeTypeCollector(Profile* profile); | 49 explicit MimeTypeCollector(Profile* profile); |
| 50 virtual ~MimeTypeCollector(); | 50 virtual ~MimeTypeCollector(); |
| 51 | 51 |
| 52 // Collects all mime types asynchronously for a vector of URLs and upon | 52 // Collects all mime types asynchronously for a vector of URLs and upon |
| 53 // completion, calls the |callback|. It can be called only once. | 53 // completion, calls the |callback|. It can be called only once. |
| 54 void CollectForURLs(const std::vector<storage::FileSystemURL>& urls, | 54 void CollectForURLs(const std::vector<storage::FileSystemURL>& urls, |
| 55 const CompletionCallback& callback); | 55 const CompletionCallback& callback); |
| 56 | 56 |
| 57 // Collects all mime types asynchronously for a vector of local file paths and | 57 // Collects all mime types asynchronously for a vector of local file paths and |
| 58 // upon completion, calls the |callback|. It can be called only once. | 58 // upon completion, calls the |callback|. It can be called only once. |
| 59 void CollectForLocalPaths(const std::vector<base::FilePath>& local_paths, | 59 void CollectForLocalPaths(const std::vector<base::FilePath>& local_paths, |
| 60 const CompletionCallback& callback); | 60 const CompletionCallback& callback); |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 // Called, when the |index|-th input file (or URL) got processed. | 63 // Called, when the |index|-th input file (or URL) got processed. |
| 64 void OnMimeTypeCollected(size_t index, const std::string& mime_type); | 64 void OnMimeTypeCollected(size_t index, const std::string& mime_type); |
| 65 | 65 |
| 66 Profile* profile_; | 66 Profile* profile_; |
| 67 scoped_ptr<std::vector<std::string> > result_; | 67 std::unique_ptr<std::vector<std::string>> result_; |
| 68 size_t left_; | 68 size_t left_; |
| 69 CompletionCallback callback_; | 69 CompletionCallback callback_; |
| 70 base::WeakPtrFactory<MimeTypeCollector> weak_ptr_factory_; | 70 base::WeakPtrFactory<MimeTypeCollector> weak_ptr_factory_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(MimeTypeCollector); | 72 DISALLOW_COPY_AND_ASSIGN(MimeTypeCollector); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 } // namespace app_file_handler_util | 75 } // namespace app_file_handler_util |
| 76 } // namespace extensions | 76 } // namespace extensions |
| 77 | 77 |
| 78 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_MIME_UTIL_H_ | 78 #endif // CHROME_BROWSER_EXTENSIONS_API_FILE_HANDLERS_MIME_UTIL_H_ |
| OLD | NEW |