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

Unified Diff: base/files/file_path_watcher_linux.cc

Issue 2667513003: Remove some LazyInstance use in base/ (Closed)
Patch Set: . Created 3 years, 11 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
Index: base/files/file_path_watcher_linux.cc
diff --git a/base/files/file_path_watcher_linux.cc b/base/files/file_path_watcher_linux.cc
index 9589e9b788dce7807ac0b97a011e6012e6b47860..df4189cd2c9adc71af4fcc9e18a709ae0d80d431 100644
--- a/base/files/file_path_watcher_linux.cc
+++ b/base/files/file_path_watcher_linux.cc
@@ -24,7 +24,6 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
-#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
@@ -63,14 +62,12 @@ class InotifyReader {
void OnInotifyEvent(const inotify_event* event);
private:
- friend struct DefaultLazyInstanceTraits<InotifyReader>;
-
+ friend InotifyReader* GetInotifyReader();
typedef std::set<FilePathWatcherImpl*> WatcherSet;
InotifyReader();
- // There is no destructor because |g_inotify_reader| is a
- // base::LazyInstace::Leaky object. Having a destructor causes build
- // issues with GCC 6 (http://crbug.com/636346).
+ // There is no destructor because GetInotifyReader() is leaky. Having a
+ // destructor causes build issues with GCC 6 (http://crbug.com/636346).
// We keep track of which delegates want to be notified on which watches.
hash_map<Watch, WatcherSet> watchers_;
@@ -243,8 +240,10 @@ void InotifyReaderCallback(InotifyReader* reader, int inotify_fd) {
}
}
-static LazyInstance<InotifyReader>::Leaky g_inotify_reader =
- LAZY_INSTANCE_INITIALIZER;
+InotifyReader* GetInotifyReader() {
+ static auto inotify_reader = new InotifyReader();
+ return inotify_reader;
+}
InotifyReader::InotifyReader()
: thread_("inotify_reader"),
@@ -458,7 +457,7 @@ void FilePathWatcherImpl::Cancel() {
callback_.Reset();
for (size_t i = 0; i < watches_.size(); ++i)
- g_inotify_reader.Get().RemoveWatch(watches_[i].watch, this);
+ GetInotifyReader()->RemoveWatch(watches_[i].watch, this);
watches_.clear();
target_.clear();
RemoveRecursiveWatches();
@@ -477,7 +476,7 @@ void FilePathWatcherImpl::UpdateWatches() {
InotifyReader::Watch old_watch = watch_entry.watch;
watch_entry.watch = InotifyReader::kInvalidWatch;
watch_entry.linkname.clear();
- watch_entry.watch = g_inotify_reader.Get().AddWatch(path, this);
+ watch_entry.watch = GetInotifyReader()->AddWatch(path, this);
if (watch_entry.watch == InotifyReader::kInvalidWatch) {
// Ignore the error code (beyond symlink handling) to attempt to add
// watches on accessible children of unreadable directories. Note that
@@ -487,7 +486,7 @@ void FilePathWatcherImpl::UpdateWatches() {
AddWatchForBrokenSymlink(path, &watch_entry);
}
if (old_watch != watch_entry.watch)
- g_inotify_reader.Get().RemoveWatch(old_watch, this);
+ GetInotifyReader()->RemoveWatch(old_watch, this);
path = path.Append(watch_entry.subdir);
}
@@ -533,7 +532,7 @@ void FilePathWatcherImpl::UpdateRecursiveWatches(
if (!changed_dir.IsParent(cur_path))
break;
if (!DirectoryExists(cur_path))
- g_inotify_reader.Get().RemoveWatch(end_it->second, this);
+ GetInotifyReader()->RemoveWatch(end_it->second, this);
}
recursive_watches_by_path_.erase(start_it, end_it);
UpdateRecursiveWatchesForPath(changed_dir);
@@ -558,17 +557,15 @@ void FilePathWatcherImpl::UpdateRecursiveWatchesForPath(const FilePath& path) {
if (!ContainsKey(recursive_watches_by_path_, current)) {
// Add new watches.
- InotifyReader::Watch watch =
- g_inotify_reader.Get().AddWatch(current, this);
+ InotifyReader::Watch watch = GetInotifyReader()->AddWatch(current, this);
TrackWatchForRecursion(watch, current);
} else {
// Update existing watches.
InotifyReader::Watch old_watch = recursive_watches_by_path_[current];
DCHECK_NE(InotifyReader::kInvalidWatch, old_watch);
- InotifyReader::Watch watch =
- g_inotify_reader.Get().AddWatch(current, this);
+ InotifyReader::Watch watch = GetInotifyReader()->AddWatch(current, this);
if (watch != old_watch) {
- g_inotify_reader.Get().RemoveWatch(old_watch, this);
+ GetInotifyReader()->RemoveWatch(old_watch, this);
recursive_paths_by_watch_.erase(old_watch);
recursive_watches_by_path_.erase(current);
TrackWatchForRecursion(watch, current);
@@ -600,7 +597,7 @@ void FilePathWatcherImpl::RemoveRecursiveWatches() {
recursive_paths_by_watch_.begin();
it != recursive_paths_by_watch_.end();
++it) {
- g_inotify_reader.Get().RemoveWatch(it->first, this);
+ GetInotifyReader()->RemoveWatch(it->first, this);
}
recursive_paths_by_watch_.clear();
recursive_watches_by_path_.clear();
@@ -621,7 +618,7 @@ void FilePathWatcherImpl::AddWatchForBrokenSymlink(const FilePath& path,
// changes to a component "/" which is harmless so no special treatment of
// this case is required.
InotifyReader::Watch watch =
- g_inotify_reader.Get().AddWatch(link.DirName(), this);
+ GetInotifyReader()->AddWatch(link.DirName(), this);
if (watch == InotifyReader::kInvalidWatch) {
// TODO(craig) Symlinks only work if the parent directory for the target
// exist. Ideally we should make sure we've watched all the components of

Powered by Google App Engine
This is Rietveld 408576698