- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / drive / file_write_watcher.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_WATCHER_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_WATCHER_H_
7
8 #include "base/callback_forward.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h"
11
12 namespace base {
13 class FilePath;
14 }  // namespace base
15
16 namespace drive {
17
18 namespace internal {
19
20 typedef base::Callback<void(bool)> StartWatchCallback;
21
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 {
27  public:
28   FileWriteWatcher();
29   ~FileWriteWatcher();
30
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|.
35   //
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.
41   //
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);
47
48   // For testing purpose, stops inserting delay between the write detection and
49   // notification to the |on_write_callback|.
50   void DisableDelayForTesting();
51
52  private:
53   class FileWriteWatcherImpl;
54   scoped_ptr<FileWriteWatcherImpl, util::DestroyHelper> watcher_impl_;
55
56   DISALLOW_COPY_AND_ASSIGN(FileWriteWatcher);
57 };
58
59 }  // namespace internal
60 }  // namespace drive
61
62 #endif  // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_WRITE_WATCHER_H_