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

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: move platform-specific include 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 #include <gtk/gtk.h>
8 #include <sys/time.h> 7 #include <sys/time.h>
9 #include <time.h> 8 #include <time.h>
10 9
11 #include <cstdlib> 10 #include <cstdlib>
12 #include <list> 11 #include <list>
13 #include <map> 12 #include <map>
14 #include <vector> 13 #include <vector>
15 14
16 #include "base/environment.h" 15 #include "base/environment.h"
17 #include "base/file_util.h" 16 #include "base/file_util.h"
18 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
19 #include "base/logging.h" 18 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
21 #include "base/memory/singleton.h" 20 #include "base/memory/singleton.h"
22 #include "base/message_loop.h" 21 #include "base/message_loop.h"
23 #include "base/nix/xdg_util.h" 22 #include "base/nix/xdg_util.h"
24 #include "base/string_split.h" 23 #include "base/string_split.h"
25 #include "base/string_util.h" 24 #include "base/string_util.h"
26 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
27 #include "base/third_party/xdg_mime/xdgmime.h" 26 #include "base/third_party/xdg_mime/xdgmime.h"
28 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
29 28
29 #if defined(TOOLKIT_USES_GTK)
30 #include <gtk/gtk.h>
31 #endif
32
30 namespace { 33 namespace {
31 34
32 // None of the XDG stuff is thread-safe, so serialize all access under 35 // None of the XDG stuff is thread-safe, so serialize all access under
33 // this lock. 36 // this lock.
34 static base::LazyInstance<base::Lock, 37 static base::LazyInstance<base::Lock,
35 base::LeakyLazyInstanceTraits<base::Lock> > 38 base::LeakyLazyInstanceTraits<base::Lock> >
36 g_mime_util_xdg_lock(base::LINKER_INITIALIZED); 39 g_mime_util_xdg_lock(base::LINKER_INITIALIZED);
37 40
38 class IconTheme; 41 class IconTheme;
39 42
(...skipping 19 matching lines...) Expand all
59 IconFormats icon_formats_; 62 IconFormats icon_formats_;
60 63
61 // Store loaded icon_theme. 64 // Store loaded icon_theme.
62 IconThemeMap icon_themes_; 65 IconThemeMap icon_themes_;
63 66
64 // The default theme. 67 // The default theme.
65 IconTheme* default_themes_[kDefaultThemeNum]; 68 IconTheme* default_themes_[kDefaultThemeNum];
66 69
67 time_t last_check_time_; 70 time_t last_check_time_;
68 71
72 #if defined(TOOLKIT_USES_GTK)
69 // This is set by DetectGtkTheme(). We cache it so that we can access the 73 // 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 74 // theme name from threads that aren't allowed to call
71 // gtk_settings_get_default(). 75 // gtk_settings_get_default().
72 std::string gtk_theme_name_; 76 std::string gtk_theme_name_;
77 #endif
73 78
74 private: 79 private:
75 MimeUtilConstants() 80 MimeUtilConstants()
76 : last_check_time_(0) { 81 : last_check_time_(0) {
77 icon_formats_.push_back(".png"); 82 icon_formats_.push_back(".png");
78 icon_formats_.push_back(".svg"); 83 icon_formats_.push_back(".svg");
79 icon_formats_.push_back(".xpm"); 84 icon_formats_.push_back(".xpm");
80 85
81 for (size_t i = 0; i < kDefaultThemeNum; ++i) 86 for (size_t i = 0; i < kDefaultThemeNum; ++i)
82 default_themes_[i] = NULL; 87 default_themes_[i] = NULL;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 kde_default_theme = "default.kde"; 505 kde_default_theme = "default.kde";
501 kde_fallback_theme = "crystalsvg"; 506 kde_fallback_theme = "crystalsvg";
502 } else { 507 } else {
503 // KDE 4 508 // KDE 4
504 kde_default_theme = "default.kde4"; 509 kde_default_theme = "default.kde4";
505 kde_fallback_theme = "oxygen"; 510 kde_fallback_theme = "oxygen";
506 } 511 }
507 default_themes[1] = IconTheme::LoadTheme(kde_default_theme); 512 default_themes[1] = IconTheme::LoadTheme(kde_default_theme);
508 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); 513 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme);
509 } else { 514 } else {
515 #if defined(TOOLKIT_USES_GTK)
510 // Assume it's Gnome and use GTK to figure out the theme. 516 // Assume it's Gnome and use GTK to figure out the theme.
511 default_themes[1] = IconTheme::LoadTheme( 517 default_themes[1] = IconTheme::LoadTheme(
512 MimeUtilConstants::GetInstance()->gtk_theme_name_); 518 MimeUtilConstants::GetInstance()->gtk_theme_name_);
513 default_themes[2] = IconTheme::LoadTheme("gnome"); 519 default_themes[2] = IconTheme::LoadTheme("gnome");
520 #endif
514 } 521 }
515 // hicolor needs to be last per icon theme spec. 522 // hicolor needs to be last per icon theme spec.
516 default_themes[3] = IconTheme::LoadTheme("hicolor"); 523 default_themes[3] = IconTheme::LoadTheme("hicolor");
517 524
518 for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) { 525 for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) {
519 if (default_themes[i] == NULL) 526 if (default_themes[i] == NULL)
520 continue; 527 continue;
521 // NULL out duplicate pointers. 528 // NULL out duplicate pointers.
522 for (size_t j = i + 1; j < MimeUtilConstants::kDefaultThemeNum; j++) { 529 for (size_t j = i + 1; j < MimeUtilConstants::kDefaultThemeNum; j++) {
523 if (default_themes[j] == default_themes[i]) 530 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()); 567 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
561 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); 568 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str());
562 } 569 }
563 570
564 std::string GetDataMimeType(const std::string& data) { 571 std::string GetDataMimeType(const std::string& data) {
565 base::ThreadRestrictions::AssertIOAllowed(); 572 base::ThreadRestrictions::AssertIOAllowed();
566 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); 573 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
567 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); 574 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL);
568 } 575 }
569 576
577 #if defined(TOOLKIT_USES_GTK)
570 void DetectGtkTheme() { 578 void DetectGtkTheme() {
571 // If the theme name is already loaded, do nothing. Chrome doesn't respond 579 // 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 580 // to changes in the system theme, so we never need to set this more than
573 // once. 581 // once.
574 if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty()) 582 if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty())
575 return; 583 return;
576 584
577 // We should only be called on the UI thread. 585 // We should only be called on the UI thread.
578 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 586 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
579 587
580 gchar* gtk_theme_name; 588 gchar* gtk_theme_name;
581 g_object_get(gtk_settings_get_default(), 589 g_object_get(gtk_settings_get_default(),
582 "gtk-icon-theme-name", 590 "gtk-icon-theme-name",
583 &gtk_theme_name, NULL); 591 &gtk_theme_name, NULL);
584 MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name); 592 MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name);
585 g_free(gtk_theme_name); 593 g_free(gtk_theme_name);
586 } 594 }
595 #endif
587 596
588 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { 597 FilePath GetMimeIcon(const std::string& mime_type, size_t size) {
589 base::ThreadRestrictions::AssertIOAllowed(); 598 base::ThreadRestrictions::AssertIOAllowed();
590 std::vector<std::string> icon_names; 599 std::vector<std::string> icon_names;
591 std::string icon_name; 600 std::string icon_name;
592 FilePath icon_file; 601 FilePath icon_file;
593 602
594 { 603 {
595 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get()); 604 base::AutoLock scoped_lock(g_mime_util_xdg_lock.Get());
596 const char *icon = xdg_mime_get_icon(mime_type.c_str()); 605 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 { 641 } else {
633 icon_file = LookupIconInDefaultTheme(icon_names[i], size); 642 icon_file = LookupIconInDefaultTheme(icon_names[i], size);
634 if (!icon_file.empty()) 643 if (!icon_file.empty())
635 return icon_file; 644 return icon_file;
636 } 645 }
637 } 646 }
638 return FilePath(); 647 return FilePath();
639 } 648 }
640 649
641 } // namespace mime_util 650 } // 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