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

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

Issue 101143006: Convert base::file_util to use File instead of PlatformFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove base:: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_win.cc ('k') | base/files/file_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file.h"
9 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/message_loop/message_loop_proxy.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "base/win/object_watcher.h" 15 #include "base/win/object_watcher.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 namespace { 19 namespace {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 DCHECK(object == handle_); 142 DCHECK(object == handle_);
142 // Make sure we stay alive through the body of this function. 143 // Make sure we stay alive through the body of this function.
143 scoped_refptr<FilePathWatcherImpl> keep_alive(this); 144 scoped_refptr<FilePathWatcherImpl> keep_alive(this);
144 145
145 if (!UpdateWatch()) { 146 if (!UpdateWatch()) {
146 callback_.Run(target_, true /* error */); 147 callback_.Run(target_, true /* error */);
147 return; 148 return;
148 } 149 }
149 150
150 // Check whether the event applies to |target_| and notify the callback. 151 // Check whether the event applies to |target_| and notify the callback.
151 PlatformFileInfo file_info; 152 File::Info file_info;
152 bool file_exists = GetFileInfo(target_, &file_info); 153 bool file_exists = GetFileInfo(target_, &file_info);
153 if (file_exists && (last_modified_.is_null() || 154 if (file_exists && (last_modified_.is_null() ||
154 last_modified_ != file_info.last_modified)) { 155 last_modified_ != file_info.last_modified)) {
155 last_modified_ = file_info.last_modified; 156 last_modified_ = file_info.last_modified;
156 first_notification_ = Time::Now(); 157 first_notification_ = Time::Now();
157 callback_.Run(target_, false); 158 callback_.Run(target_, false);
158 } else if (file_exists && !first_notification_.is_null()) { 159 } else if (file_exists && !first_notification_.is_null()) {
159 // The target's last modification time is equal to what's on record. This 160 // The target's last modification time is equal to what's on record. This
160 // means that either an unrelated event occurred, or the target changed 161 // means that either an unrelated event occurred, or the target changed
161 // again (file modification times only have a resolution of 1s). Comparing 162 // again (file modification times only have a resolution of 1s). Comparing
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 return false; 223 return false;
223 } 224 }
224 225
225 return true; 226 return true;
226 } 227 }
227 228
228 bool FilePathWatcherImpl::UpdateWatch() { 229 bool FilePathWatcherImpl::UpdateWatch() {
229 if (handle_ != INVALID_HANDLE_VALUE) 230 if (handle_ != INVALID_HANDLE_VALUE)
230 DestroyWatch(); 231 DestroyWatch();
231 232
232 PlatformFileInfo file_info; 233 File::Info file_info;
233 if (GetFileInfo(target_, &file_info)) { 234 if (GetFileInfo(target_, &file_info)) {
234 last_modified_ = file_info.last_modified; 235 last_modified_ = file_info.last_modified;
235 first_notification_ = Time::Now(); 236 first_notification_ = Time::Now();
236 } 237 }
237 238
238 // Start at the target and walk up the directory chain until we succesfully 239 // Start at the target and walk up the directory chain until we succesfully
239 // create a watch handle in |handle_|. |child_dirs| keeps a stack of child 240 // create a watch handle in |handle_|. |child_dirs| keeps a stack of child
240 // directories stripped from target, in reverse order. 241 // directories stripped from target, in reverse order.
241 std::vector<FilePath> child_dirs; 242 std::vector<FilePath> child_dirs;
242 FilePath watched_path(target_); 243 FilePath watched_path(target_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 handle_ = INVALID_HANDLE_VALUE; 283 handle_ = INVALID_HANDLE_VALUE;
283 } 284 }
284 285
285 } // namespace 286 } // namespace
286 287
287 FilePathWatcher::FilePathWatcher() { 288 FilePathWatcher::FilePathWatcher() {
288 impl_ = new FilePathWatcherImpl(); 289 impl_ = new FilePathWatcherImpl();
289 } 290 }
290 291
291 } // namespace base 292 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_win.cc ('k') | base/files/file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698