Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: net/base/platform_mime_util_linux.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "net/base/platform_mime_util.h" 5 #include "net/base/platform_mime_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 11
12 #if defined(OS_ANDROID) 12 #if defined(OS_ANDROID)
13 #include "net/android/network_library.h" 13 #include "net/android/network_library.h"
14 #else 14 #else
15 #include "base/nix/mime_util_xdg.h" 15 #include "base/nix/mime_util_xdg.h"
16 #endif 16 #endif
17 17
18 namespace net { 18 namespace net {
19 19
20 #if defined(OS_ANDROID) 20 #if defined(OS_ANDROID)
21 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( 21 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
22 const base::FilePath::StringType& ext, std::string* result) const { 22 const base::FilePath::StringType& ext,
23 std::string* result) const {
23 return android::GetMimeTypeFromExtension(ext, result); 24 return android::GetMimeTypeFromExtension(ext, result);
24 } 25 }
25 #else 26 #else
26 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( 27 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
27 const base::FilePath::StringType& ext, std::string* result) const { 28 const base::FilePath::StringType& ext,
29 std::string* result) const {
28 // TODO(thestig): This is a temporary hack until we can fix this 30 // TODO(thestig): This is a temporary hack until we can fix this
29 // properly in test shell / webkit. 31 // properly in test shell / webkit.
30 // We have to play dumb and not return application/x-perl here 32 // We have to play dumb and not return application/x-perl here
31 // to make the reload-subframe-object layout test happy. 33 // to make the reload-subframe-object layout test happy.
32 if (ext == "pl") 34 if (ext == "pl")
33 return false; 35 return false;
34 36
35 base::FilePath dummy_path("foo." + ext); 37 base::FilePath dummy_path("foo." + ext);
36 std::string out = base::nix::GetFileMimeType(dummy_path); 38 std::string out = base::nix::GetFileMimeType(dummy_path);
37 39
(...skipping 15 matching lines...) Expand all
53 } 55 }
54 56
55 #endif // defined(OS_ANDROID) 57 #endif // defined(OS_ANDROID)
56 58
57 struct MimeToExt { 59 struct MimeToExt {
58 const char* mime_type; 60 const char* mime_type;
59 const char* ext; 61 const char* ext;
60 }; 62 };
61 63
62 const struct MimeToExt mime_type_ext_map[] = { 64 const struct MimeToExt mime_type_ext_map[] = {
63 {"application/pdf", "pdf"}, 65 {"application/pdf", "pdf"},
64 {"application/x-tar", "tar"}, 66 {"application/x-tar", "tar"},
65 {"application/zip", "zip"}, 67 {"application/zip", "zip"},
66 {"audio/mpeg", "mp3"}, 68 {"audio/mpeg", "mp3"},
67 {"image/gif", "gif"}, 69 {"image/gif", "gif"},
68 {"image/jpeg", "jpg"}, 70 {"image/jpeg", "jpg"},
69 {"image/png", "png"}, 71 {"image/png", "png"},
70 {"text/html", "html"}, 72 {"text/html", "html"},
71 {"video/mp4", "mp4"}, 73 {"video/mp4", "mp4"},
72 {"video/mpeg", "mpg"}, 74 {"video/mpeg", "mpg"},
73 {"text/plain", "txt"}, 75 {"text/plain", "txt"},
74 {"text/x-sh", "sh"}, 76 {"text/x-sh", "sh"},
75 }; 77 };
76 78
77 bool PlatformMimeUtil::GetPreferredExtensionForMimeType( 79 bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
78 const std::string& mime_type, base::FilePath::StringType* ext) const { 80 const std::string& mime_type,
79 81 base::FilePath::StringType* ext) const {
80 for (size_t x = 0; 82 for (size_t x = 0; x < (sizeof(mime_type_ext_map) / sizeof(MimeToExt)); x++) {
81 x < (sizeof(mime_type_ext_map) / sizeof(MimeToExt));
82 x++) {
83 if (mime_type_ext_map[x].mime_type == mime_type) { 83 if (mime_type_ext_map[x].mime_type == mime_type) {
84 *ext = mime_type_ext_map[x].ext; 84 *ext = mime_type_ext_map[x].ext;
85 return true; 85 return true;
86 } 86 }
87 } 87 }
88 88
89 // TODO(dhg): Fix this the right way by implementing what's said below. 89 // TODO(dhg): Fix this the right way by implementing what's said below.
90 // Unlike GetPlatformMimeTypeFromExtension, this method doesn't have a 90 // Unlike GetPlatformMimeTypeFromExtension, this method doesn't have a
91 // default list that it uses, but for now we are also returning false since 91 // default list that it uses, but for now we are also returning false since
92 // this doesn't really matter as much under Linux. 92 // this doesn't really matter as much under Linux.
93 // 93 //
94 // If we wanted to do this properly, we would read the mime.cache file which 94 // If we wanted to do this properly, we would read the mime.cache file which
95 // has a section where they assign a glob (*.gif) to a mimetype 95 // has a section where they assign a glob (*.gif) to a mimetype
96 // (image/gif). We look up the "heaviest" glob for a certain mime type and 96 // (image/gif). We look up the "heaviest" glob for a certain mime type and
97 // then then try to chop off "*.". 97 // then then try to chop off "*.".
98 98
99 return false; 99 return false;
100 } 100 }
101 101
102 void PlatformMimeUtil::GetPlatformExtensionsForMimeType( 102 void PlatformMimeUtil::GetPlatformExtensionsForMimeType(
103 const std::string& mime_type, 103 const std::string& mime_type,
104 base::hash_set<base::FilePath::StringType>* extensions) const { 104 base::hash_set<base::FilePath::StringType>* extensions) const {
105 base::FilePath::StringType ext; 105 base::FilePath::StringType ext;
106 if (GetPreferredExtensionForMimeType(mime_type, &ext)) 106 if (GetPreferredExtensionForMimeType(mime_type, &ext))
107 extensions->insert(ext); 107 extensions->insert(ext);
108 } 108 }
109 109
110 } // namespace net 110 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698