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

Side by Side Diff: base/files/file_path_watcher_linux.cc

Issue 2308413002: Only update watches when directories change. (Closed)
Patch Set: rebase Created 4 years, 3 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
« 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) 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/files/file_path_watcher.h" 5 #include "base/files/file_path_watcher.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <string.h> 9 #include <string.h>
10 #include <sys/inotify.h> 10 #include <sys/inotify.h>
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 g_inotify_reader.Get().RemoveWatch(old_watch, this); 505 g_inotify_reader.Get().RemoveWatch(old_watch, this);
506 path = path.Append(watch_entry.subdir); 506 path = path.Append(watch_entry.subdir);
507 } 507 }
508 508
509 UpdateRecursiveWatches(InotifyReader::kInvalidWatch, 509 UpdateRecursiveWatches(InotifyReader::kInvalidWatch,
510 false /* is directory? */); 510 false /* is directory? */);
511 } 511 }
512 512
513 void FilePathWatcherImpl::UpdateRecursiveWatches( 513 void FilePathWatcherImpl::UpdateRecursiveWatches(
514 InotifyReader::Watch fired_watch, 514 InotifyReader::Watch fired_watch,
515 bool is_dir) { 515 bool is_dir) {
Shuhei Takahashi 2016/09/08 05:10:52 Could you insert DCHECK(HasValidWatchVector()); he
dspaid 2016/09/09 02:00:55 Done.
516 if (!recursive_) 516 if (!recursive_)
517 return; 517 return;
518 518
519 if (!DirectoryExists(target_)) { 519 if (!DirectoryExists(target_)) {
520 RemoveRecursiveWatches(); 520 RemoveRecursiveWatches();
521 return; 521 return;
522 } 522 }
523 523
524 // Underneath |target_|, only directory changes trigger watch updates.
525 if (!is_dir && fired_watch != InotifyReader::kInvalidWatch)
526 return;
527
524 // Check to see if this is a forced update or if some component of |target_| 528 // Check to see if this is a forced update or if some component of |target_|
525 // has changed. For these cases, redo the watches for |target_| and below. 529 // has changed. For these cases, redo the watches for |target_| and below.
526 if (!ContainsKey(recursive_paths_by_watch_, fired_watch)) { 530 if (!ContainsKey(recursive_paths_by_watch_, fired_watch)) {
Shuhei Takahashi 2016/09/08 05:10:52 Hmm, reordering the checks is fragile and I'm afra
dspaid 2016/09/09 02:00:55 Done.
527 UpdateRecursiveWatchesForPath(target_); 531 UpdateRecursiveWatchesForPath(target_);
528 return; 532 return;
529 } 533 }
530 534
531 // Underneath |target_|, only directory changes trigger watch updates.
532 if (!is_dir)
533 return;
534
535 const FilePath& changed_dir = recursive_paths_by_watch_[fired_watch]; 535 const FilePath& changed_dir = recursive_paths_by_watch_[fired_watch];
536 536
537 std::map<FilePath, InotifyReader::Watch>::iterator start_it = 537 std::map<FilePath, InotifyReader::Watch>::iterator start_it =
538 recursive_watches_by_path_.lower_bound(changed_dir); 538 recursive_watches_by_path_.lower_bound(changed_dir);
539 std::map<FilePath, InotifyReader::Watch>::iterator end_it = start_it; 539 std::map<FilePath, InotifyReader::Watch>::iterator end_it = start_it;
540 for (; end_it != recursive_watches_by_path_.end(); ++end_it) { 540 for (; end_it != recursive_watches_by_path_.end(); ++end_it) {
541 const FilePath& cur_path = end_it->first; 541 const FilePath& cur_path = end_it->first;
542 if (!changed_dir.IsParent(cur_path)) 542 if (!changed_dir.IsParent(cur_path))
543 break; 543 break;
544 if (!DirectoryExists(cur_path)) 544 if (!DirectoryExists(cur_path))
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 return watches_.back().subdir.empty(); 652 return watches_.back().subdir.empty();
653 } 653 }
654 654
655 } // namespace 655 } // namespace
656 656
657 FilePathWatcher::FilePathWatcher() { 657 FilePathWatcher::FilePathWatcher() {
658 impl_ = new FilePathWatcherImpl(); 658 impl_ = new FilePathWatcherImpl();
659 } 659 }
660 660
661 } // namespace base 661 } // namespace base
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