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