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

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

Issue 2308413002: Only update watches when directories change. (Closed)
Patch Set: Correctly set changed_dir 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
516 DCHECK(HasValidWatchVector());
517
516 if (!recursive_) 518 if (!recursive_)
517 return; 519 return;
518 520
519 if (!DirectoryExists(target_)) { 521 if (!DirectoryExists(target_)) {
520 RemoveRecursiveWatches(); 522 RemoveRecursiveWatches();
521 return; 523 return;
522 } 524 }
523 525
524 // Check to see if this is a forced update or if some component of |target_| 526 // 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. 527 // has changed. For these cases, redo the watches for |target_| and below.
526 if (!ContainsKey(recursive_paths_by_watch_, fired_watch)) { 528 if (!ContainsKey(recursive_paths_by_watch_, fired_watch) &&
529 fired_watch != watches_.back().watch) {
527 UpdateRecursiveWatchesForPath(target_); 530 UpdateRecursiveWatchesForPath(target_);
528 return; 531 return;
529 } 532 }
530 533
531 // Underneath |target_|, only directory changes trigger watch updates. 534 // Underneath |target_|, only directory changes trigger watch updates.
532 if (!is_dir) 535 if (!is_dir)
533 return; 536 return;
534 537
535 const FilePath& changed_dir = recursive_paths_by_watch_[fired_watch]; 538 const FilePath& changed_dir =
539 ContainsKey(recursive_paths_by_watch_, fired_watch) ?
540 recursive_paths_by_watch_[fired_watch] :
541 target_;
536 542
537 std::map<FilePath, InotifyReader::Watch>::iterator start_it = 543 std::map<FilePath, InotifyReader::Watch>::iterator start_it =
538 recursive_watches_by_path_.lower_bound(changed_dir); 544 recursive_watches_by_path_.lower_bound(changed_dir);
539 std::map<FilePath, InotifyReader::Watch>::iterator end_it = start_it; 545 std::map<FilePath, InotifyReader::Watch>::iterator end_it = start_it;
540 for (; end_it != recursive_watches_by_path_.end(); ++end_it) { 546 for (; end_it != recursive_watches_by_path_.end(); ++end_it) {
541 const FilePath& cur_path = end_it->first; 547 const FilePath& cur_path = end_it->first;
542 if (!changed_dir.IsParent(cur_path)) 548 if (!changed_dir.IsParent(cur_path))
543 break; 549 break;
544 if (!DirectoryExists(cur_path)) 550 if (!DirectoryExists(cur_path))
545 g_inotify_reader.Get().RemoveWatch(end_it->second, this); 551 g_inotify_reader.Get().RemoveWatch(end_it->second, this);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 return watches_.back().subdir.empty(); 658 return watches_.back().subdir.empty();
653 } 659 }
654 660
655 } // namespace 661 } // namespace
656 662
657 FilePathWatcher::FilePathWatcher() { 663 FilePathWatcher::FilePathWatcher() {
658 impl_ = new FilePathWatcherImpl(); 664 impl_ = new FilePathWatcherImpl();
659 } 665 }
660 666
661 } // namespace base 667 } // 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