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

Unified Diff: base/mime_util_xdg.cc

Issue 8437039: Linux: Periodically check for changes to the icon directories and refresh icons for mime types pe... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mime_util_xdg.cc
===================================================================
--- base/mime_util_xdg.cc (revision 108199)
+++ base/mime_util_xdg.cc (working copy)
@@ -5,8 +5,6 @@
#include "base/mime_util.h"
#include <gtk/gtk.h>
-#include <sys/time.h>
-#include <time.h>
#include <cstdlib>
#include <list>
@@ -26,6 +24,7 @@
#include "base/synchronization/lock.h"
#include "base/third_party/xdg_mime/xdgmime.h"
#include "base/threading/thread_restrictions.h"
+#include "base/time.h"
namespace {
@@ -40,11 +39,11 @@
class MimeUtilConstants {
public:
typedef std::map<std::string, IconTheme*> IconThemeMap;
- typedef std::map<FilePath, int> IconDirMtimeMap;
+ typedef std::map<FilePath, base::Time> IconDirMtimeMap;
willchan no longer on Chromium 2011/11/07 21:37:06 Are you sure you don't want TimeTicks instead? The
Lei Zhang 2011/11/11 00:30:11 The time comes from a stat() call. It's always rel
typedef std::vector<std::string> IconFormats;
- // In seconds, specified by icon theme specs.
- static const int kUpdateInterval = 5;
+ // Specified by XDG icon theme specs.
+ static const int kUpdateIntervalInSeconds = 5;
static const size_t kDefaultThemeNum = 4;
@@ -64,7 +63,7 @@
// The default theme.
IconTheme* default_themes_[kDefaultThemeNum];
- time_t last_check_time_;
+ base::Time last_check_time_;
// This is set by DetectGtkTheme(). We cache it so that we can access the
// theme name from threads that aren't allowed to call
@@ -72,8 +71,7 @@
std::string gtk_theme_name_;
private:
- MimeUtilConstants()
- : last_check_time_(0) {
+ MimeUtilConstants() {
icon_formats_.push_back(".png");
icon_formats_.push_back(".svg");
icon_formats_.push_back(".xpm");
@@ -391,11 +389,23 @@
return true;
}
+bool CheckDirExistsAndGetMtime(const FilePath& dir,
+ base::Time* last_modified) {
+ if (!file_util::DirectoryExists(dir))
+ return false;
+ base::PlatformFileInfo file_info;
+ if (!file_util::GetFileInfo(dir, &file_info))
+ return false;
+ *last_modified = file_info.last_modified;
+ return true;
+}
+
// Make sure |dir| exists and add it to the list of icon directories.
void TryAddIconDir(const FilePath& dir) {
- if (!file_util::DirectoryExists(dir))
+ base::Time last_modified;
+ if (!CheckDirExistsAndGetMtime(dir, &last_modified))
return;
- MimeUtilConstants::GetInstance()->icon_dirs_[dir] = 0;
+ MimeUtilConstants::GetInstance()->icon_dirs_[dir] = last_modified;
}
// For a xdg directory |dir|, add the appropriate icon sub-directories.
@@ -408,7 +418,6 @@
// Add all the xdg icon directories.
void InitIconDir() {
- MimeUtilConstants::GetInstance()->icon_dirs_.clear();
FilePath home = file_util::GetHomeDir();
if (!home.empty()) {
FilePath legacy_data_dir(home);
@@ -441,22 +450,38 @@
}
}
-// Per xdg theme spec, we should check the icon directories every so often for
-// newly added icons. This isn't quite right.
void EnsureUpdated() {
- struct timeval t;
- gettimeofday(&t, NULL);
- time_t now = t.tv_sec;
MimeUtilConstants* constants = MimeUtilConstants::GetInstance();
+ if (constants->last_check_time_.is_null()) {
+ constants->last_check_time_ = base::Time::Now();
+ InitIconDir();
+ return;
+ }
- if (constants->last_check_time_ == 0) {
- InitIconDir();
- constants->last_check_time_ = now;
- } else {
- // TODO(thestig): something changed. start over. Upstream fix to Google
- // Gadgets for Linux.
Lei Zhang 2011/11/02 02:02:10 Google Gadgets for Linux is kinda dead at this poi
- if (now > constants->last_check_time_ + constants->kUpdateInterval) {
+ // Per xdg theme spec, we should check the icon directories every so often
+ // for newly added icons.
+ base::TimeDelta time_since_last_check =
+ base::Time::Now() - constants->last_check_time_;
+ if (time_since_last_check.InSeconds() > constants->kUpdateIntervalInSeconds) {
+ constants->last_check_time_ += time_since_last_check;
+
+ bool rescan_icon_dirs = false;
+ MimeUtilConstants::IconDirMtimeMap* icon_dirs = &constants->icon_dirs_;
+ MimeUtilConstants::IconDirMtimeMap::iterator iter;
+ for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) {
+ base::Time last_modified;
+ if (!CheckDirExistsAndGetMtime(iter->first, &last_modified) ||
+ last_modified != iter->second) {
+ rescan_icon_dirs = true;
+ break;
+ }
}
+
+ if (rescan_icon_dirs) {
+ constants->icon_dirs_.clear();
+ constants->icon_themes_.clear();
Lei Zhang 2011/11/02 02:02:10 Turns out I should clear this too, but it was not
+ InitIconDir();
+ }
}
}
« 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