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

Side by Side Diff: base/nix/mime_util_xdg.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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/memory/shared_memory_posix.cc ('k') | base/path_service.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) 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // theme and load the first encountered index.theme. 164 // theme and load the first encountered index.theme.
165 MimeUtilConstants::IconDirMtimeMap::iterator iter; 165 MimeUtilConstants::IconDirMtimeMap::iterator iter;
166 FilePath theme_path; 166 FilePath theme_path;
167 MimeUtilConstants::IconDirMtimeMap* icon_dirs = 167 MimeUtilConstants::IconDirMtimeMap* icon_dirs =
168 &MimeUtilConstants::GetInstance()->icon_dirs_; 168 &MimeUtilConstants::GetInstance()->icon_dirs_;
169 for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) { 169 for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) {
170 theme_path = iter->first.Append(name); 170 theme_path = iter->first.Append(name);
171 if (!file_util::DirectoryExists(theme_path)) 171 if (!file_util::DirectoryExists(theme_path))
172 continue; 172 continue;
173 FilePath theme_index = theme_path.Append("index.theme"); 173 FilePath theme_index = theme_path.Append("index.theme");
174 if (!index_theme_loaded_ && file_util::PathExists(theme_index)) { 174 if (!index_theme_loaded_ && PathExists(theme_index)) {
175 if (!LoadIndexTheme(theme_index)) 175 if (!LoadIndexTheme(theme_index))
176 return; 176 return;
177 index_theme_loaded_ = true; 177 index_theme_loaded_ = true;
178 } 178 }
179 dirs_.push_back(theme_path); 179 dirs_.push_back(theme_path);
180 } 180 }
181 } 181 }
182 182
183 FilePath IconTheme::GetIconPath(const std::string& icon_name, int size, 183 FilePath IconTheme::GetIconPath(const std::string& icon_name, int size,
184 bool inherits) { 184 bool inherits) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 FilePath IconTheme::GetIconPathUnderSubdir(const std::string& icon_name, 241 FilePath IconTheme::GetIconPathUnderSubdir(const std::string& icon_name,
242 const std::string& subdir) { 242 const std::string& subdir) {
243 FilePath icon_path; 243 FilePath icon_path;
244 std::list<FilePath>::iterator dir_iter; 244 std::list<FilePath>::iterator dir_iter;
245 MimeUtilConstants::IconFormats* icon_formats = 245 MimeUtilConstants::IconFormats* icon_formats =
246 &MimeUtilConstants::GetInstance()->icon_formats_; 246 &MimeUtilConstants::GetInstance()->icon_formats_;
247 for (dir_iter = dirs_.begin(); dir_iter != dirs_.end(); ++dir_iter) { 247 for (dir_iter = dirs_.begin(); dir_iter != dirs_.end(); ++dir_iter) {
248 for (size_t i = 0; i < icon_formats->size(); ++i) { 248 for (size_t i = 0; i < icon_formats->size(); ++i) {
249 icon_path = dir_iter->Append(subdir); 249 icon_path = dir_iter->Append(subdir);
250 icon_path = icon_path.Append(icon_name + (*icon_formats)[i]); 250 icon_path = icon_path.Append(icon_name + (*icon_formats)[i]);
251 if (file_util::PathExists(icon_path)) 251 if (PathExists(icon_path))
252 return icon_path; 252 return icon_path;
253 } 253 }
254 } 254 }
255 return FilePath(); 255 return FilePath();
256 } 256 }
257 257
258 bool IconTheme::LoadIndexTheme(const FilePath& file) { 258 bool IconTheme::LoadIndexTheme(const FilePath& file) {
259 FILE* fp = file_util::OpenFile(file, "r"); 259 FILE* fp = file_util::OpenFile(file, "r");
260 SubDirInfo* current_info = NULL; 260 SubDirInfo* current_info = NULL;
261 if (!fp) 261 if (!fp)
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 // Find a fallback icon if we cannot find it in the default theme. 484 // Find a fallback icon if we cannot find it in the default theme.
485 FilePath LookupFallbackIcon(const std::string& icon_name) { 485 FilePath LookupFallbackIcon(const std::string& icon_name) {
486 MimeUtilConstants* constants = MimeUtilConstants::GetInstance(); 486 MimeUtilConstants* constants = MimeUtilConstants::GetInstance();
487 MimeUtilConstants::IconDirMtimeMap::iterator iter; 487 MimeUtilConstants::IconDirMtimeMap::iterator iter;
488 MimeUtilConstants::IconDirMtimeMap* icon_dirs = &constants->icon_dirs_; 488 MimeUtilConstants::IconDirMtimeMap* icon_dirs = &constants->icon_dirs_;
489 MimeUtilConstants::IconFormats* icon_formats = &constants->icon_formats_; 489 MimeUtilConstants::IconFormats* icon_formats = &constants->icon_formats_;
490 for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) { 490 for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) {
491 for (size_t i = 0; i < icon_formats->size(); ++i) { 491 for (size_t i = 0; i < icon_formats->size(); ++i) {
492 FilePath icon = iter->first.Append(icon_name + (*icon_formats)[i]); 492 FilePath icon = iter->first.Append(icon_name + (*icon_formats)[i]);
493 if (file_util::PathExists(icon)) 493 if (PathExists(icon))
494 return icon; 494 return icon;
495 } 495 }
496 } 496 }
497 return FilePath(); 497 return FilePath();
498 } 498 }
499 499
500 // Initialize the list of default themes. 500 // Initialize the list of default themes.
501 void InitDefaultThemes() { 501 void InitDefaultThemes() {
502 IconTheme** default_themes = 502 IconTheme** default_themes =
503 MimeUtilConstants::GetInstance()->default_themes_; 503 MimeUtilConstants::GetInstance()->default_themes_;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // Try generic name like text-x-generic. 633 // Try generic name like text-x-generic.
634 icon_name = mime_type.substr(0, mime_type.find('/')) + "-x-generic"; 634 icon_name = mime_type.substr(0, mime_type.find('/')) + "-x-generic";
635 icon_names.push_back(icon_name); 635 icon_names.push_back(icon_name);
636 636
637 // Last resort 637 // Last resort
638 icon_names.push_back("unknown"); 638 icon_names.push_back("unknown");
639 639
640 for (size_t i = 0; i < icon_names.size(); i++) { 640 for (size_t i = 0; i < icon_names.size(); i++) {
641 if (icon_names[i][0] == '/') { 641 if (icon_names[i][0] == '/') {
642 icon_file = FilePath(icon_names[i]); 642 icon_file = FilePath(icon_names[i]);
643 if (file_util::PathExists(icon_file)) 643 if (PathExists(icon_file))
644 return icon_file; 644 return icon_file;
645 } else { 645 } else {
646 icon_file = LookupIconInDefaultTheme(icon_names[i], size); 646 icon_file = LookupIconInDefaultTheme(icon_names[i], size);
647 if (!icon_file.empty()) 647 if (!icon_file.empty())
648 return icon_file; 648 return icon_file;
649 } 649 }
650 } 650 }
651 return FilePath(); 651 return FilePath();
652 } 652 }
653 653
654 } // namespace nix 654 } // namespace nix
655 } // namespace base 655 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/shared_memory_posix.cc ('k') | base/path_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698