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

Side by Side Diff: chrome/browser/file_system/entry_watcher_service.h

Issue 452043003: [ew] Add basic classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Uploaded. Created 6 years, 4 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
OLDNEW
(Empty)
1 // Copyright 2014 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_FILE_SYSTEM_ENTRY_WATCHER_SERVICE_H_
6 #define CHROME_BROWSER_FILE_SYSTEM_ENTRY_WATCHER_SERVICE_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/memory/singleton.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/scoped_observer.h"
15 #include "components/keyed_service/content/browser_context_keyed_service_factory .h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "webkit/browser/fileapi/file_system_url.h"
18 #include "webkit/browser/fileapi/watcher_manager.h"
19
20 namespace content {
21 class BrowserContext;
22 } // namespace content
23
24 namespace extensions {
25 struct Event;
26 class EventRouter;
27 } // namespace extensions
28
29 // Watches entries (files and directories) for changes. Created per profile.
30 // TODO(mtomasz): Add support for watching files.
31 class EntryWatcherService : public KeyedService,
32 public fileapi::WatcherManager::Observer {
33 public:
34 typedef base::Callback<void(const std::string& extension_id,
35 scoped_ptr<extensions::Event> event)>
36 DispatchEventImplCallback;
37
38 typedef base::Callback<fileapi::FileSystemContext*(
39 const std::string& extension_id,
40 content::BrowserContext* context)> GetFileSystemContextImplCallback;
41
42 typedef base::Callback<void(std::vector<fileapi::FileSystemURL>)>
43 GetWatchedEntriesCallback;
44
45 explicit EntryWatcherService(content::BrowserContext* context);
46 virtual ~EntryWatcherService();
47
48 // Watches a directory. Only one watcher can be set per the same |url| and
49 // |extension_id|.
50 void WatchDirectory(const std::string& extension_id,
51 const fileapi::FileSystemURL& url,
52 bool recursive,
53 const fileapi::WatcherManager::StatusCallback& callback);
54
55 // Unwatches an entry (file or directory).
56 void UnwatchEntry(const std::string& extension_id,
57 const fileapi::FileSystemURL& url,
58 const fileapi::WatcherManager::StatusCallback& callback);
59
60 std::vector<fileapi::FileSystemURL> GetWatchedEntries(
61 const std::string& extension_id);
62
63 // fileapi::WatcherManager::Observer overrides.
64 virtual void OnEntryChanged(const fileapi::FileSystemURL& url) OVERRIDE;
65 virtual void OnEntryRemoved(const fileapi::FileSystemURL& url) OVERRIDE;
66
67 // Sets a custom dispatcher for tests in order to be able to verify dispatched
68 // events.
69 void SetDispatchEventImplForTesting(
70 const DispatchEventImplCallback& callback);
71
72 // Sets a custom context getter for tests in order to inject a testing
73 // file system context implementation.
74 void SetGetFileSystemContextImplForTesting(
75 const GetFileSystemContextImplCallback& callback);
76
77 private:
78 // Holds information about an entry watcher.
79 struct EntryWatcher {
80 EntryWatcher();
81 EntryWatcher(const fileapi::FileSystemURL& url,
82 bool directory,
83 bool recursive);
84 ~EntryWatcher();
85
86 fileapi::FileSystemURL url;
87 bool directory;
88 bool recursive;
89 };
90
91 // Map from a file system url to a map from an extension id to an entry
92 // watcher descriptor. Note, that GURL is used instead of fileapi::
93 // FileSystemURL, since the second one doesn't work well with stl containers.
94 typedef std::map<GURL, std::map<std::string, EntryWatcher> > WatcherMap;
95
96 // Called when adding a directory watcher is completed with either a success
97 // or an error.
98 void OnWatchDirectoryCompleted(
99 const std::string& extension_id,
100 const fileapi::FileSystemURL& url,
101 bool recursive,
102 const fileapi::WatcherManager::StatusCallback& callback,
103 base::File::Error result);
104
105 // Called when removing a watcher is completed with either a success or an
106 // error.
107 void OnUnwatchEntryCompleted(
108 const std::string& extension_id,
109 const fileapi::FileSystemURL& url,
110 const fileapi::WatcherManager::StatusCallback& callback,
111 base::File::Error result);
112
113 content::BrowserContext* context_;
114 WatcherMap watchers_;
115 DispatchEventImplCallback dispatch_event_impl_;
116 GetFileSystemContextImplCallback get_file_system_context_impl_;
117 ScopedObserver<fileapi::WatcherManager, fileapi::WatcherManager::Observer>
118 observing_;
119 base::WeakPtrFactory<EntryWatcherService> weak_ptr_factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(EntryWatcherService);
122 };
123
124 #endif // CHROME_BROWSER_FILE_SYSTEM_ENTRY_WATCHER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698