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 "base/nix/mime_util_xdg.h" | 5 #include "base/nix/mime_util_xdg.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 for (size_t i = 0; i < kDefaultThemeNum; i++) | 581 for (size_t i = 0; i < kDefaultThemeNum; i++) |
582 delete default_themes_[i]; | 582 delete default_themes_[i]; |
583 } | 583 } |
584 | 584 |
585 } // namespace | 585 } // namespace |
586 | 586 |
587 namespace base { | 587 namespace base { |
588 namespace nix { | 588 namespace nix { |
589 | 589 |
590 std::string GetFileMimeType(const FilePath& filepath) { | 590 std::string GetFileMimeType(const FilePath& filepath) { |
591 if (filepath.empty()) return ""; | |
brettw
2012/08/16 03:37:34
Don't use single-line style except in unusual case
benjhayden
2012/08/16 14:33:35
Done.
| |
591 base::ThreadRestrictions::AssertIOAllowed(); | 592 base::ThreadRestrictions::AssertIOAllowed(); |
592 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 593 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
593 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); | 594 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); |
594 } | 595 } |
595 | 596 |
596 std::string GetDataMimeType(const std::string& data) { | 597 std::string GetDataMimeType(const std::string& data) { |
597 base::ThreadRestrictions::AssertIOAllowed(); | 598 base::ThreadRestrictions::AssertIOAllowed(); |
598 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 599 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
599 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); | 600 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); |
600 } | 601 } |
(...skipping 17 matching lines...) Expand all Loading... | |
618 g_free(gtk_theme_name); | 619 g_free(gtk_theme_name); |
619 } | 620 } |
620 #endif | 621 #endif |
621 | 622 |
622 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { | 623 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { |
623 base::ThreadRestrictions::AssertIOAllowed(); | 624 base::ThreadRestrictions::AssertIOAllowed(); |
624 std::vector<std::string> icon_names; | 625 std::vector<std::string> icon_names; |
625 std::string icon_name; | 626 std::string icon_name; |
626 FilePath icon_file; | 627 FilePath icon_file; |
627 | 628 |
628 { | 629 if (mime_type.empty()) { |
630 icon_name = ""; | |
brettw
2012/08/16 03:37:34
Can't this be removed and you put the else case in
benjhayden
2012/08/16 14:33:35
Done.
| |
631 } else { | |
629 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 632 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
630 const char *icon = xdg_mime_get_icon(mime_type.c_str()); | 633 const char *icon = xdg_mime_get_icon(mime_type.c_str()); |
631 icon_name = std::string(icon ? icon : ""); | 634 icon_name = std::string(icon ? icon : ""); |
632 } | 635 } |
633 | 636 |
634 if (icon_name.length()) | 637 if (icon_name.length()) |
635 icon_names.push_back(icon_name); | 638 icon_names.push_back(icon_name); |
636 | 639 |
637 // For text/plain, try text-plain. | 640 // For text/plain, try text-plain. |
638 icon_name = mime_type; | 641 icon_name = mime_type; |
(...skipping 28 matching lines...) Expand all Loading... | |
667 icon_file = LookupIconInDefaultTheme(icon_names[i], size); | 670 icon_file = LookupIconInDefaultTheme(icon_names[i], size); |
668 if (!icon_file.empty()) | 671 if (!icon_file.empty()) |
669 return icon_file; | 672 return icon_file; |
670 } | 673 } |
671 } | 674 } |
672 return FilePath(); | 675 return FilePath(); |
673 } | 676 } |
674 | 677 |
675 } // namespace nix | 678 } // namespace nix |
676 } // namespace base | 679 } // namespace base |
OLD | NEW |