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

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

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual to the 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/native_library_mac.mm ('k') | base/prefs/json_pref_store_unittest.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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 : index_theme_loaded_(false) { 161 : index_theme_loaded_(false) {
162 base::ThreadRestrictions::AssertIOAllowed(); 162 base::ThreadRestrictions::AssertIOAllowed();
163 // Iterate on all icon directories to find directories of the specified 163 // Iterate on all icon directories to find directories of the specified
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 (!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_ && 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 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 DLOG(WARNING) << "Invalid index.theme: blank subdir"; 380 DLOG(WARNING) << "Invalid index.theme: blank subdir";
381 return false; 381 return false;
382 } 382 }
383 subdirs_[dir] = num++; 383 subdirs_[dir] = num++;
384 info_array_.reset(new SubDirInfo[num]); 384 info_array_.reset(new SubDirInfo[num]);
385 return true; 385 return true;
386 } 386 }
387 387
388 bool CheckDirExistsAndGetMtime(const FilePath& dir, 388 bool CheckDirExistsAndGetMtime(const FilePath& dir,
389 base::Time* last_modified) { 389 base::Time* last_modified) {
390 if (!file_util::DirectoryExists(dir)) 390 if (!DirectoryExists(dir))
391 return false; 391 return false;
392 base::PlatformFileInfo file_info; 392 base::PlatformFileInfo file_info;
393 if (!file_util::GetFileInfo(dir, &file_info)) 393 if (!file_util::GetFileInfo(dir, &file_info))
394 return false; 394 return false;
395 *last_modified = file_info.last_modified; 395 *last_modified = file_info.last_modified;
396 return true; 396 return true;
397 } 397 }
398 398
399 // Make sure |dir| exists and add it to the list of icon directories. 399 // Make sure |dir| exists and add it to the list of icon directories.
400 void TryAddIconDir(const FilePath& dir) { 400 void TryAddIconDir(const FilePath& dir) {
401 base::Time last_modified; 401 base::Time last_modified;
402 if (!CheckDirExistsAndGetMtime(dir, &last_modified)) 402 if (!CheckDirExistsAndGetMtime(dir, &last_modified))
403 return; 403 return;
404 MimeUtilConstants::GetInstance()->icon_dirs_[dir] = last_modified; 404 MimeUtilConstants::GetInstance()->icon_dirs_[dir] = last_modified;
405 } 405 }
406 406
407 // For a xdg directory |dir|, add the appropriate icon sub-directories. 407 // For a xdg directory |dir|, add the appropriate icon sub-directories.
408 void AddXDGDataDir(const FilePath& dir) { 408 void AddXDGDataDir(const FilePath& dir) {
409 if (!file_util::DirectoryExists(dir)) 409 if (!DirectoryExists(dir))
410 return; 410 return;
411 TryAddIconDir(dir.Append("icons")); 411 TryAddIconDir(dir.Append("icons"));
412 TryAddIconDir(dir.Append("pixmaps")); 412 TryAddIconDir(dir.Append("pixmaps"));
413 } 413 }
414 414
415 // Add all the xdg icon directories. 415 // Add all the xdg icon directories.
416 void InitIconDir() { 416 void InitIconDir() {
417 FilePath home = file_util::GetHomeDir(); 417 FilePath home = file_util::GetHomeDir();
418 if (!home.empty()) { 418 if (!home.empty()) {
419 FilePath legacy_data_dir(home); 419 FilePath legacy_data_dir(home);
420 legacy_data_dir = legacy_data_dir.AppendASCII(".icons"); 420 legacy_data_dir = legacy_data_dir.AppendASCII(".icons");
421 if (file_util::DirectoryExists(legacy_data_dir)) 421 if (DirectoryExists(legacy_data_dir))
422 TryAddIconDir(legacy_data_dir); 422 TryAddIconDir(legacy_data_dir);
423 } 423 }
424 const char* env = getenv("XDG_DATA_HOME"); 424 const char* env = getenv("XDG_DATA_HOME");
425 if (env) { 425 if (env) {
426 AddXDGDataDir(FilePath(env)); 426 AddXDGDataDir(FilePath(env));
427 } else if (!home.empty()) { 427 } else if (!home.empty()) {
428 FilePath local_data_dir(home); 428 FilePath local_data_dir(home);
429 local_data_dir = local_data_dir.AppendASCII(".local"); 429 local_data_dir = local_data_dir.AppendASCII(".local");
430 local_data_dir = local_data_dir.AppendASCII("share"); 430 local_data_dir = local_data_dir.AppendASCII("share");
431 AddXDGDataDir(local_data_dir); 431 AddXDGDataDir(local_data_dir);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/native_library_mac.mm ('k') | base/prefs/json_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698