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

Side by Side Diff: chrome/browser/file_path_watcher_win.cc

Issue 3347005: Moving file_util::FileInfo to base::PlatformFileInfo, and adding the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/file_path_watcher.h" 5 #include "chrome/browser/file_path_watcher.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/object_watcher.h" 10 #include "base/object_watcher.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 DCHECK(object == handle_); 92 DCHECK(object == handle_);
93 // Make sure we stay alive through the body of this function. 93 // Make sure we stay alive through the body of this function.
94 scoped_refptr<FilePathWatcherImpl> keep_alive(this); 94 scoped_refptr<FilePathWatcherImpl> keep_alive(this);
95 95
96 if (!UpdateWatch()) { 96 if (!UpdateWatch()) {
97 delegate_->OnError(); 97 delegate_->OnError();
98 return; 98 return;
99 } 99 }
100 100
101 // Check whether the event applies to |target_| and notify the delegate. 101 // Check whether the event applies to |target_| and notify the delegate.
102 file_util::FileInfo file_info; 102 base::PlatformFileInfo file_info;
103 bool file_exists = file_util::GetFileInfo(target_, &file_info); 103 bool file_exists = file_util::GetFileInfo(target_, &file_info);
104 if (file_exists && (last_modified_.is_null() || 104 if (file_exists && (last_modified_.is_null() ||
105 last_modified_ != file_info.last_modified)) { 105 last_modified_ != file_info.last_modified)) {
106 last_modified_ = file_info.last_modified; 106 last_modified_ = file_info.last_modified;
107 first_notification_ = base::Time::Now(); 107 first_notification_ = base::Time::Now();
108 delegate_->OnFilePathChanged(target_); 108 delegate_->OnFilePathChanged(target_);
109 } else if (file_exists && !first_notification_.is_null()) { 109 } else if (file_exists && !first_notification_.is_null()) {
110 // The target's last modification time is equal to what's on record. This 110 // The target's last modification time is equal to what's on record. This
111 // means that either an unrelated event occurred, or the target changed 111 // means that either an unrelated event occurred, or the target changed
112 // again (file modification times only have a resolution of 1s). Comparing 112 // again (file modification times only have a resolution of 1s). Comparing
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 return false; 176 return false;
177 } 177 }
178 178
179 return true; 179 return true;
180 } 180 }
181 181
182 bool FilePathWatcherImpl::UpdateWatch() { 182 bool FilePathWatcherImpl::UpdateWatch() {
183 if (handle_ != INVALID_HANDLE_VALUE) 183 if (handle_ != INVALID_HANDLE_VALUE)
184 DestroyWatch(); 184 DestroyWatch();
185 185
186 file_util::FileInfo file_info; 186 base::PlatformFileInfo file_info;
187 if (file_util::GetFileInfo(target_, &file_info)) { 187 if (file_util::GetFileInfo(target_, &file_info)) {
188 last_modified_ = file_info.last_modified; 188 last_modified_ = file_info.last_modified;
189 first_notification_ = base::Time::Now(); 189 first_notification_ = base::Time::Now();
190 } 190 }
191 191
192 // Start at the target and walk up the directory chain until we succesfully 192 // Start at the target and walk up the directory chain until we succesfully
193 // create a watch handle in |handle_|. |child_dirs| keeps a stack of child 193 // create a watch handle in |handle_|. |child_dirs| keeps a stack of child
194 // directories stripped from target, in reverse order. 194 // directories stripped from target, in reverse order.
195 std::vector<FilePath> child_dirs; 195 std::vector<FilePath> child_dirs;
196 FilePath watched_path(target_); 196 FilePath watched_path(target_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 watcher_.StopWatching(); 234 watcher_.StopWatching();
235 FindCloseChangeNotification(handle_); 235 FindCloseChangeNotification(handle_);
236 handle_ = INVALID_HANDLE_VALUE; 236 handle_ = INVALID_HANDLE_VALUE;
237 } 237 }
238 238
239 } // namespace 239 } // namespace
240 240
241 FilePathWatcher::FilePathWatcher() { 241 FilePathWatcher::FilePathWatcher() {
242 impl_ = new FilePathWatcherImpl(); 242 impl_ = new FilePathWatcherImpl();
243 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698