1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_WATCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_WATCHER_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h"
20 typedef base::Callback
<void(bool)> StartWatchCallback
;
22 // The class watches modification to Drive files in the cache directory.
23 // This is used for returning a local writable snapshot of Drive files from the
24 // Save-As file dialog, so that the callers of the dialog can save to Drive
25 // without any special handling about Drive.
26 class FileWriteWatcher
{
31 // Starts watching the modification to |path|. When it successfully started
32 // watching, it runs |on_start_callback| by passing true as the argument.
33 // Or if it failed, the callback is run with false.
34 // Detected modification is notified by calling |on_write_callback|.
36 // Currently, the modification is watched in "one-shot" manner. That is, once
37 // a modification is notified, the watch is deactivated for freeing system
38 // resources. As a heuristic to capture the real end of write operations that
39 // might be done by several chunked writes, the notification is fired after
40 // 5 seconds has passed after the last write operation is detected.
42 // TODO(kinaba): investigate the possibility to continuously watch the whole
43 // cache directory. http://crbug.com/269424
44 void StartWatch(const base::FilePath
& path
,
45 const StartWatchCallback
& on_start_callback
,
46 const base::Closure
& on_write_callback
);
48 // For testing purpose, stops inserting delay between the write detection and
49 // notification to the |on_write_callback|.
50 void DisableDelayForTesting();
53 class FileWriteWatcherImpl
;
54 scoped_ptr
<FileWriteWatcherImpl
, util::DestroyHelper
> watcher_impl_
;
56 DISALLOW_COPY_AND_ASSIGN(FileWriteWatcher
);
59 } // namespace internal
62 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_WATCHER_H_