OLD | NEW |
| (Empty) |
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_EXTENSIONS_FILE_MANAGER_FILE_WATCHER_EXTENSIONS_
H_ | |
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_WATCHER_EXTENSIONS_
H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/callback_forward.h" | |
12 #include "base/files/file_path.h" | |
13 #include "base/files/file_path_watcher.h" | |
14 #include "base/memory/weak_ptr.h" | |
15 | |
16 namespace file_manager { | |
17 | |
18 // This class is used to remember what extensions are watching |virtual_path|. | |
19 class FileWatcherExtensions { | |
20 public: | |
21 typedef std::map<std::string, int> ExtensionUsageRegistry; | |
22 typedef base::Callback<void(bool success)> BoolCallback; | |
23 | |
24 FileWatcherExtensions(const base::FilePath& virtual_path, | |
25 const std::string& extension_id, | |
26 bool is_remote_file_system); | |
27 | |
28 ~FileWatcherExtensions(); | |
29 | |
30 void AddExtension(const std::string& extension_id); | |
31 | |
32 void RemoveExtension(const std::string& extension_id); | |
33 | |
34 const ExtensionUsageRegistry& extensions() const { return extensions_; } | |
35 | |
36 int ref_count() const { return ref_count_; } | |
37 | |
38 const base::FilePath& virtual_path() const { return virtual_path_; } | |
39 | |
40 // Starts a file watch at |local_path|. |file_watcher_callback| will be | |
41 // called when changes are notified. | |
42 // | |
43 // |callback| will be called with true, if the file watch is started | |
44 // successfully, or false if failed. |callback| must not be null. | |
45 void Watch(const base::FilePath& local_path, | |
46 const base::FilePathWatcher::Callback& file_watcher_callback, | |
47 const BoolCallback& callback); | |
48 | |
49 private: | |
50 // Called when a FilePathWatcher is created and started. | |
51 // |file_path_watcher| is NULL, if the watcher wasn't started successfully. | |
52 void OnWatcherStarted(const BoolCallback& callback, | |
53 base::FilePathWatcher* file_path_watcher); | |
54 | |
55 base::FilePathWatcher* file_watcher_; | |
56 base::FilePath local_path_; | |
57 base::FilePath virtual_path_; | |
58 ExtensionUsageRegistry extensions_; | |
59 int ref_count_; | |
60 bool is_remote_file_system_; | |
61 | |
62 // Note: This should remain the last member so it'll be destroyed and | |
63 // invalidate the weak pointers before any other members are destroyed. | |
64 base::WeakPtrFactory<FileWatcherExtensions> weak_ptr_factory_; | |
65 }; | |
66 | |
67 } // namespace file_manager | |
68 | |
69 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_WATCHER_EXTENSIO
NS_H_ | |
OLD | NEW |