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

Side by Side Diff: base/mime_util_xdg.cc

Issue 6312195: Linux: Restrict access to xdg-mime functions to the FILE thread.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 10 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 | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/message_loop.h"
19 #include "base/scoped_ptr.h" 19 #include "base/scoped_ptr.h"
20 #include "base/singleton.h" 20 #include "base/singleton.h"
21 #include "base/string_split.h" 21 #include "base/string_split.h"
22 #include "base/string_util.h" 22 #include "base/string_util.h"
23 #include "base/third_party/xdg_mime/xdgmime.h" 23 #include "base/third_party/xdg_mime/xdgmime.h"
24 #include "base/threading/thread_restrictions.h"
24 25
25 namespace { 26 namespace {
26 27
27 class IconTheme; 28 class IconTheme;
28 29
29 class MimeUtilConstants { 30 class MimeUtilConstants {
30 public: 31 public:
31 static MimeUtilConstants* GetInstance() { 32 static MimeUtilConstants* GetInstance() {
32 return Singleton<MimeUtilConstants>::get(); 33 return Singleton<MimeUtilConstants>::get();
33 } 34 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 149
149 // store the subdirs of this theme and array index of |info_array_|. 150 // store the subdirs of this theme and array index of |info_array_|.
150 std::map<std::string, int> subdirs_; 151 std::map<std::string, int> subdirs_;
151 SubDirInfo* info_array_; // List of sub-directories. 152 SubDirInfo* info_array_; // List of sub-directories.
152 std::string inherits_; // Name of the theme this one inherits from. 153 std::string inherits_; // Name of the theme this one inherits from.
153 }; 154 };
154 155
155 IconTheme::IconTheme(const std::string& name) 156 IconTheme::IconTheme(const std::string& name)
156 : index_theme_loaded_(false), 157 : index_theme_loaded_(false),
157 info_array_(NULL) { 158 info_array_(NULL) {
159 base::ThreadRestrictions::AssertIOAllowed();
158 // Iterate on all icon directories to find directories of the specified 160 // Iterate on all icon directories to find directories of the specified
159 // theme and load the first encountered index.theme. 161 // theme and load the first encountered index.theme.
160 std::map<FilePath, int>::iterator iter; 162 std::map<FilePath, int>::iterator iter;
161 FilePath theme_path; 163 FilePath theme_path;
162 std::map<FilePath, int>* icon_dirs = 164 std::map<FilePath, int>* icon_dirs =
163 MimeUtilConstants::GetInstance()->icon_dirs_; 165 MimeUtilConstants::GetInstance()->icon_dirs_;
164 for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) { 166 for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) {
165 theme_path = iter->first.Append(name); 167 theme_path = iter->first.Append(name);
166 if (!file_util::DirectoryExists(theme_path)) 168 if (!file_util::DirectoryExists(theme_path))
167 continue; 169 continue;
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 delete icon_themes_; 545 delete icon_themes_;
544 for (size_t i = 0; i < kDefaultThemeNum; i++) 546 for (size_t i = 0; i < kDefaultThemeNum; i++)
545 delete default_themes_[i]; 547 delete default_themes_[i];
546 } 548 }
547 549
548 } // namespace 550 } // namespace
549 551
550 namespace mime_util { 552 namespace mime_util {
551 553
552 std::string GetFileMimeType(const FilePath& filepath) { 554 std::string GetFileMimeType(const FilePath& filepath) {
555 base::ThreadRestrictions::AssertIOAllowed();
553 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str()); 556 return xdg_mime_get_mime_type_from_file_name(filepath.value().c_str());
554 } 557 }
555 558
556 std::string GetDataMimeType(const std::string& data) { 559 std::string GetDataMimeType(const std::string& data) {
560 base::ThreadRestrictions::AssertIOAllowed();
557 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL); 561 return xdg_mime_get_mime_type_for_data(data.data(), data.length(), NULL);
558 } 562 }
559 563
560 void DetectGtkTheme() { 564 void DetectGtkTheme() {
561 // If the theme name is already loaded, do nothing. Chrome doesn't respond 565 // If the theme name is already loaded, do nothing. Chrome doesn't respond
562 // to changes in the system theme, so we never need to set this more than 566 // to changes in the system theme, so we never need to set this more than
563 // once. 567 // once.
564 if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty()) 568 if (!MimeUtilConstants::GetInstance()->gtk_theme_name_.empty())
565 return; 569 return;
566 570
567 // We should only be called on the UI thread. 571 // We should only be called on the UI thread.
568 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); 572 DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type());
569 573
570 gchar* gtk_theme_name; 574 gchar* gtk_theme_name;
571 g_object_get(gtk_settings_get_default(), 575 g_object_get(gtk_settings_get_default(),
572 "gtk-icon-theme-name", 576 "gtk-icon-theme-name",
573 &gtk_theme_name, NULL); 577 &gtk_theme_name, NULL);
574 MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name); 578 MimeUtilConstants::GetInstance()->gtk_theme_name_.assign(gtk_theme_name);
575 g_free(gtk_theme_name); 579 g_free(gtk_theme_name);
576 } 580 }
577 581
578 FilePath GetMimeIcon(const std::string& mime_type, size_t size) { 582 FilePath GetMimeIcon(const std::string& mime_type, size_t size) {
583 base::ThreadRestrictions::AssertIOAllowed();
579 std::vector<std::string> icon_names; 584 std::vector<std::string> icon_names;
580 std::string icon_name; 585 std::string icon_name;
581 FilePath icon_file; 586 FilePath icon_file;
582 587
583 const char* icon = xdg_mime_get_icon(mime_type.c_str()); 588 const char* icon = xdg_mime_get_icon(mime_type.c_str());
584 icon_name = std::string(icon ? icon : ""); 589 icon_name = std::string(icon ? icon : "");
585 if (icon_name.length()) 590 if (icon_name.length())
586 icon_names.push_back(icon_name); 591 icon_names.push_back(icon_name);
587 592
588 // For text/plain, try text-plain. 593 // For text/plain, try text-plain.
(...skipping 25 matching lines...) Expand all
614 } else { 619 } else {
615 icon_file = LookupIconInDefaultTheme(icon_names[i], size); 620 icon_file = LookupIconInDefaultTheme(icon_names[i], size);
616 if (!icon_file.empty()) 621 if (!icon_file.empty())
617 return icon_file; 622 return icon_file;
618 } 623 }
619 } 624 }
620 return FilePath(); 625 return FilePath();
621 } 626 }
622 627
623 } // namespace mime_util 628 } // namespace mime_util
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698