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()) | |
Lei Zhang
2012/08/22 05:59:10
Curious, who is calling GetFileMimeType with an em
benjhayden
2012/08/22 14:24:14
Yes, LoadIcon() doesn't early-return for empty pat
| |
592 return std::string(); | |
591 base::ThreadRestrictions::AssertIOAllowed(); | 593 base::ThreadRestrictions::AssertIOAllowed(); |
592 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 594 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
593 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); | 595 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); |
594 } | 596 } |
595 | 597 |
596 std::string GetDataMimeType(const std::string& data) { | 598 std::string GetDataMimeType(const std::string& data) { |
597 base::ThreadRestrictions::AssertIOAllowed(); | 599 base::ThreadRestrictions::AssertIOAllowed(); |
598 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 600 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
599 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); | 601 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); |
600 } | 602 } |
(...skipping 17 matching lines...) Expand all Loading... | |
618 g_free(gtk_theme_name); | 620 g_free(gtk_theme_name); |
619 } | 621 } |
620 #endif | 622 #endif |
621 | 623 |
622 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { | 624 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { |
623 base::ThreadRestrictions::AssertIOAllowed(); | 625 base::ThreadRestrictions::AssertIOAllowed(); |
624 std::vector<std::string> icon_names; | 626 std::vector<std::string> icon_names; |
625 std::string icon_name; | 627 std::string icon_name; |
626 FilePath icon_file; | 628 FilePath icon_file; |
627 | 629 |
628 { | 630 if (!mime_type.empty()) { |
629 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); | 631 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); |
630 const char *icon = xdg_mime_get_icon(mime_type.c_str()); | 632 const char *icon = xdg_mime_get_icon(mime_type.c_str()); |
631 icon_name = std::string(icon ? icon : ""); | 633 icon_name = std::string(icon ? icon : ""); |
632 } | 634 } |
633 | 635 |
634 if (icon_name.length()) | 636 if (icon_name.length()) |
635 icon_names.push_back(icon_name); | 637 icon_names.push_back(icon_name); |
636 | 638 |
637 // For text/plain, try text-plain. | 639 // For text/plain, try text-plain. |
638 icon_name = mime_type; | 640 icon_name = mime_type; |
(...skipping 28 matching lines...) Expand all Loading... | |
667 icon_file = LookupIconInDefaultTheme(icon_names[i], size); | 669 icon_file = LookupIconInDefaultTheme(icon_names[i], size); |
668 if (!icon_file.empty()) | 670 if (!icon_file.empty()) |
669 return icon_file; | 671 return icon_file; |
670 } | 672 } |
671 } | 673 } |
672 return FilePath(); | 674 return FilePath(); |
673 } | 675 } |
674 | 676 |
675 } // namespace nix | 677 } // namespace nix |
676 } // namespace base | 678 } // namespace base |
OLD | NEW |