Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / drive / file_write_watcher.h
blob719a8b95c858f8cb371518b336836b99613d48e4
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 COMPONENTS_DRIVE_FILE_WRITE_WATCHER_H_
6 #define COMPONENTS_DRIVE_FILE_WRITE_WATCHER_H_
8 #include "base/callback_forward.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread_checker.h"
11 #include "components/drive/file_system_core_util.h"
13 namespace base {
14 class FilePath;
15 class SingleThreadTaskRunner;
16 } // namespace base
18 namespace drive {
20 namespace internal {
22 typedef base::Callback<void(bool)> StartWatchCallback;
24 // The class watches modification to Drive files in the cache directory.
25 // This is used for returning a local writable snapshot of Drive files from the
26 // Save-As file dialog, so that the callers of the dialog can save to Drive
27 // without any special handling about Drive.
28 class FileWriteWatcher {
29 public:
30 explicit FileWriteWatcher(base::SingleThreadTaskRunner* file_task_runner);
31 ~FileWriteWatcher();
33 // Starts watching the modification to |path|. When it successfully started
34 // watching, it runs |on_start_callback| by passing true as the argument.
35 // Or if it failed, the callback is run with false.
36 // Detected modification is notified by calling |on_write_callback|.
38 // Currently, the modification is watched in "one-shot" manner. That is, once
39 // a modification is notified, the watch is deactivated for freeing system
40 // resources. As a heuristic to capture the real end of write operations that
41 // might be done by several chunked writes, the notification is fired after
42 // 5 seconds has passed after the last write operation is detected.
44 // TODO(kinaba): investigate the possibility to continuously watch the whole
45 // cache directory. http://crbug.com/269424
46 void StartWatch(const base::FilePath& path,
47 const StartWatchCallback& on_start_callback,
48 const base::Closure& on_write_callback);
50 // For testing purpose, stops inserting delay between the write detection and
51 // notification to the |on_write_callback|.
52 void DisableDelayForTesting();
54 private:
55 class FileWriteWatcherImpl;
56 scoped_ptr<FileWriteWatcherImpl, util::DestroyHelper> watcher_impl_;
58 base::ThreadChecker thread_checker_;
60 DISALLOW_COPY_AND_ASSIGN(FileWriteWatcher);
63 } // namespace internal
64 } // namespace drive
66 #endif // COMPONENTS_DRIVE_FILE_WRITE_WATCHER_H_