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

Side by Side Diff: base/mime_util_linux.cc

Issue 173216: Move gtk_settings_get_default() call to the UI thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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
« no previous file with comments | « base/mime_util.h ('k') | chrome/browser/icon_loader.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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> 7 #include <gtk/gtk.h>
8 #include <sys/time.h> 8 #include <sys/time.h>
9 #include <time.h> 9 #include <time.h>
10 10
11 #include <cstdlib> 11 #include <cstdlib>
12 #include <list> 12 #include <list>
13 #include <map> 13 #include <map>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/message_loop.h"
18 #include "base/scoped_ptr.h" 19 #include "base/scoped_ptr.h"
19 #include "base/singleton.h" 20 #include "base/singleton.h"
20 #include "base/string_util.h" 21 #include "base/string_util.h"
21 #include "base/third_party/xdg_mime/xdgmime.h" 22 #include "base/third_party/xdg_mime/xdgmime.h"
22 23
23 namespace { 24 namespace {
24 25
25 class IconTheme; 26 class IconTheme;
26 27
27 class MimeUtilConstants { 28 class MimeUtilConstants {
(...skipping 11 matching lines...) Expand all
39 // Store loaded icon_theme. 40 // Store loaded icon_theme.
40 std::map<std::string, IconTheme*>* icon_themes_; 41 std::map<std::string, IconTheme*>* icon_themes_;
41 42
42 static const size_t kDefaultThemeNum = 4; 43 static const size_t kDefaultThemeNum = 4;
43 44
44 // The default theme. 45 // The default theme.
45 IconTheme* default_themes_[kDefaultThemeNum]; 46 IconTheme* default_themes_[kDefaultThemeNum];
46 47
47 time_t last_check_time_; 48 time_t last_check_time_;
48 49
50 // This is set by DetectGtkTheme(). We cache it so that we can access the
51 // theme name from threads that aren't allowed to call
52 // gtk_settings_get_default().
53 std::string gtk_theme_name_;
54
49 private: 55 private:
50 MimeUtilConstants() 56 MimeUtilConstants()
51 : kUpdateInterval(5), 57 : kUpdateInterval(5),
52 icon_dirs_(NULL), 58 icon_dirs_(NULL),
53 icon_themes_(NULL), 59 icon_themes_(NULL),
54 last_check_time_(0) { 60 last_check_time_(0) {
55 icon_formats_.push_back(".png"); 61 icon_formats_.push_back(".png");
56 icon_formats_.push_back(".svg"); 62 icon_formats_.push_back(".svg");
57 icon_formats_.push_back(".xpm"); 63 icon_formats_.push_back(".xpm");
58 64
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 kde_fallback_theme = "crystalsvg"; 488 kde_fallback_theme = "crystalsvg";
483 } else { 489 } else {
484 // KDE 4 490 // KDE 4
485 kde_default_theme = "default.kde4"; 491 kde_default_theme = "default.kde4";
486 kde_fallback_theme = "oxygen"; 492 kde_fallback_theme = "oxygen";
487 } 493 }
488 default_themes[1] = IconTheme::LoadTheme(kde_default_theme); 494 default_themes[1] = IconTheme::LoadTheme(kde_default_theme);
489 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme); 495 default_themes[2] = IconTheme::LoadTheme(kde_fallback_theme);
490 } else { 496 } else {
491 // Assume it's Gnome and use GTK to figure out the theme. 497 // Assume it's Gnome and use GTK to figure out the theme.
492 gchar* gtk_theme_name; 498 default_themes[1] = IconTheme::LoadTheme(
493 g_object_get(gtk_settings_get_default(), 499 Singleton<MimeUtilConstants>::get()->gtk_theme_name_);
494 "gtk-icon-theme-name",
495 &gtk_theme_name, NULL);
496 default_themes[1] = IconTheme::LoadTheme(gtk_theme_name);
497 default_themes[2] = IconTheme::LoadTheme("gnome"); 500 default_themes[2] = IconTheme::LoadTheme("gnome");
498 g_free(gtk_theme_name);
499 } 501 }
500 // hicolor needs to be last per icon theme spec. 502 // hicolor needs to be last per icon theme spec.
501 default_themes[3] = IconTheme::LoadTheme("hicolor"); 503 default_themes[3] = IconTheme::LoadTheme("hicolor");
502 504
503 for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) { 505 for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) {
504 if (default_themes[i] == NULL) 506 if (default_themes[i] == NULL)
505 continue; 507 continue;
506 // NULL out duplicate pointers. 508 // NULL out duplicate pointers.
507 for (size_t j = i + 1; j < MimeUtilConstants::kDefaultThemeNum; j++) { 509 for (size_t j = i + 1; j < MimeUtilConstants::kDefaultThemeNum; j++) {
508 if (default_themes[j] == default_themes[i]) 510 if (default_themes[j] == default_themes[i])
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 namespace mime_util { 545 namespace mime_util {
544 546
545 std::string GetFileMimeType(const FilePath& filepath) { 547 std::string GetFileMimeType(const FilePath& filepath) {
546 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); 548 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str());
547 } 549 }
548 550
549 std::string GetDataMimeType(const std::string& data) { 551 std::string GetDataMimeType(const std::string& data) {
550 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); 552 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL);
551 } 553 }
552 554
555 void DetectGtkTheme() {
556 // If the theme name is already loaded, do nothing. Chrome doesn't respond
557 // to changes in the system theme, so we never need to set this more than
558 // once.
559 if (!Singleton<MimeUtilConstants>::get()->gtk_theme_name_.empty())
560 return;
561
562 // We should only be called on the UI thread.
563 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
564
565 gchar* gtk_theme_name;
566 g_object_get(gtk_settings_get_default(),
567 "gtk-icon-theme-name",
568 &gtk_theme_name, NULL);
569 Singleton<MimeUtilConstants>::get()->gtk_theme_name_.assign(gtk_theme_name);
570 g_free(gtk_theme_name);
571 }
572
553 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { 573 FilePath GetMimeIcon(const std::string& mime_type, size_t size) {
554 std::vector<std::string> icon_names; 574 std::vector<std::string> icon_names;
555 std::string icon_name; 575 std::string icon_name;
556 FilePath icon_file; 576 FilePath icon_file;
557 577
558 const char* icon = xdg_mime_get_icon(mime_type.c_str()); 578 const char* icon = xdg_mime_get_icon(mime_type.c_str());
559 icon_name = std::string(icon ? icon : ""); 579 icon_name = std::string(icon ? icon : "");
560 if (icon_name.length()) 580 if (icon_name.length())
561 icon_names.push_back(icon_name); 581 icon_names.push_back(icon_name);
562 582
(...skipping 26 matching lines...) Expand all
589 } else { 609 } else {
590 icon_file = LookupIconInDefaultTheme(icon_names[i], size); 610 icon_file = LookupIconInDefaultTheme(icon_names[i], size);
591 if (!icon_file.empty()) 611 if (!icon_file.empty())
592 return icon_file; 612 return icon_file;
593 } 613 }
594 } 614 }
595 return FilePath(); 615 return FilePath();
596 } 616 }
597 617
598 } // namespace mime_util 618 } // namespace mime_util
OLDNEW
« no previous file with comments | « base/mime_util.h ('k') | chrome/browser/icon_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698