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

Side by Side Diff: base/mime_util_xdg.cc

Issue 8501030: aura: Make the Linux version of IconLoader not require GTK+. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years, 1 month 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
« no previous file with comments | « base/mime_util.h ('k') | build/common.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/mime_util.h" 5 #include "base/mime_util.h"
6 6
7 #if defined(TOOLKIT_USES_GTK)
willchan no longer on Chromium 2011/11/10 21:24:14 Unless it needs to be ordered this way, please mov
Daniel Erat 2011/11/10 21:43:25 Done.
7 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif
8 #include <sys/time.h> 10 #include <sys/time.h>
9 #include <time.h> 11 #include <time.h>
10 12
11 #include <cstdlib> 13 #include <cstdlib>
12 #include <list> 14 #include <list>
13 #include <map> 15 #include <map>
14 #include <vector> 16 #include <vector>
15 17
16 #include "base/environment.h" 18 #include "base/environment.h"
17 #include "base/file_util.h" 19 #include "base/file_util.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 IconFormats icon_formats_; 61 IconFormats icon_formats_;
60 62
61 // Store loaded icon_theme. 63 // Store loaded icon_theme.
62 IconThemeMap icon_themes_; 64 IconThemeMap icon_themes_;
63 65
64 // The default theme. 66 // The default theme.
65 IconTheme* default_themes_[kDefaultThemeNum]; 67 IconTheme* default_themes_[kDefaultThemeNum];
66 68
67 time_t last_check_time_; 69 time_t last_check_time_;
68 70
71 #if defined(TOOLKIT_USES_GTK)
69 // This is set by DetectGtkTheme(). We cache it so that we can access the 72 // This is set by DetectGtkTheme(). We cache it so that we can access the
70 // theme name from threads that aren't allowed to call 73 // theme name from threads that aren't allowed to call
71 // gtk_settings_get_default(). 74 // gtk_settings_get_default().
72 std::string gtk_theme_name_; 75 std::string gtk_theme_name_;
76 #endif
73 77
74 private: 78 private:
75 MimeUtilConstants() 79 MimeUtilConstants()
76 : last_check_time_(0) { 80 : last_check_time_(0) {
77 icon_formats_.push_back(".png"); 81 icon_formats_.push_back(".png");
78 icon_formats_.push_back(".svg"); 82 icon_formats_.push_back(".svg");
79 icon_formats_.push_back(".xpm"); 83 icon_formats_.push_back(".xpm");
80 84
81 for (size_t i = 0; i < kDefaultThemeNum; ++i) 85 for (size_t i = 0; i < kDefaultThemeNum; ++i)
82 default_themes_[i] = NULL; 86 default_themes_[i] = NULL;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 kde_default_theme = "default.kde"; 504 kde_default_theme = "default.kde";
501 kde_fallback_theme = "crystalsvg"; 505 kde_fallback_theme = "crystalsvg";
502 } else { 506 } else {
503 // KDE 4 507 // KDE 4
504 kde_default_theme = "default.kde4"; 508 kde_default_theme = "default.kde4";
505 kde_fallback_theme = "oxygen"; 509 kde_fallback_theme = "oxygen";
506 } 510 }
507 default_themes[1] = IconTheme::LoadTheme(kde_default_theme); 511 default_themes[1] = IconTheme::LoadTheme(kde_default_theme);
508 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); 512 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme);
509 } else { 513 } else {
514 #if defined(TOOLKIT_USES_GTK)
510 // Assume it's Gnome and use GTK to figure out the theme. 515 // Assume it's Gnome and use GTK to figure out the theme.
511 default_themes[1] = IconTheme::LoadTheme( 516 default_themes[1] = IconTheme::LoadTheme(
512 MimeUtilConstants::GetInstance()->gtk_theme_name_); 517 MimeUtilConstants::GetInstance()->gtk_theme_name_);
513 default_themes[2] = IconTheme::LoadTheme("gnome"); 518 default_themes[2] = IconTheme::LoadTheme("gnome");
519 #endif
514 } 520 }
515 // hicolor needs to be last per icon theme spec. 521 // hicolor needs to be last per icon theme spec.
516 default_themes[3] = IconTheme::LoadTheme("hicolor"); 522 default_themes[3] = IconTheme::LoadTheme("hicolor");
517 523
518 for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) { 524 for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) {
519 if (default_themes[i] == NULL) 525 if (default_themes[i] == NULL)
520 continue; 526 continue;
521 // NULL out duplicate pointers. 527 // NULL out duplicate pointers.
522 for (size_t j = i + 1; j < MimeUtilConstants::kDefaultThemeNum; j++) { 528 for (size_t j = i + 1; j < MimeUtilConstants::kDefaultThemeNum; j++) {
523 if (default_themes[j] == default_themes[i]) 529 if (default_themes[j] == default_themes[i])
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); 566 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
561 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); 567 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str());
562 } 568 }
563 569
564 std::string GetDataMimeType(const std::string& data) { 570 std::string GetDataMimeType(const std::string& data) {
565 base::ThreadRestrictions::AssertIOAllowed(); 571 base::ThreadRestrictions::AssertIOAllowed();
566 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); 572 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
567 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); 573 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL);
568 } 574 }
569 575
576 #if defined(TOOLKIT_USES_GTK)
570 void DetectGtkTheme() { 577 void DetectGtkTheme() {
571 // If the theme name is already loaded, do nothing. Chrome doesn't respond 578 // If the theme name is already loaded, do nothing. Chrome doesn't respond
572 // to changes in the system theme, so we never need to set this more than 579 // to changes in the system theme, so we never need to set this more than
573 // once. 580 // once.
574 if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty()) 581 if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty())
575 return; 582 return;
576 583
577 // We should only be called on the UI thread. 584 // We should only be called on the UI thread.
578 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 585 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
579 586
580 gchar* gtk_theme_name; 587 gchar* gtk_theme_name;
581 g_object_get(gtk_settings_get_default(), 588 g_object_get(gtk_settings_get_default(),
582 "gtk-icon-theme-name", 589 "gtk-icon-theme-name",
583 &gtk_theme_name, NULL); 590 &gtk_theme_name, NULL);
584 MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name); 591 MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name);
585 g_free(gtk_theme_name); 592 g_free(gtk_theme_name);
586 } 593 }
594 #endif
587 595
588 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { 596 FilePath GetMimeIcon(const std::string& mime_type, size_t size) {
589 base::ThreadRestrictions::AssertIOAllowed(); 597 base::ThreadRestrictions::AssertIOAllowed();
590 std::vector<std::string> icon_names; 598 std::vector<std::string> icon_names;
591 std::string icon_name; 599 std::string icon_name;
592 FilePath icon_file; 600 FilePath icon_file;
593 601
594 { 602 {
595 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); 603 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
596 const char *icon = xdg_mime_get_icon(mime_type.c_str()); 604 const char *icon = xdg_mime_get_icon(mime_type.c_str());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } else { 640 } else {
633 icon_file = LookupIconInDefaultTheme(icon_names[i], size); 641 icon_file = LookupIconInDefaultTheme(icon_names[i], size);
634 if (!icon_file.empty()) 642 if (!icon_file.empty())
635 return icon_file; 643 return icon_file;
636 } 644 }
637 } 645 }
638 return FilePath(); 646 return FilePath();
639 } 647 }
640 648
641 } // namespace mime_util 649 } // namespace mime_util
OLDNEW
« no previous file with comments | « base/mime_util.h ('k') | build/common.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698