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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.h

Issue 22150005: file_manager: Rename file_manager_event_router.h to event_router.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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 (c) 2012 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_MANAGER_EVENT_ROUTE R_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_EVENT_ROUTE R_H_
7
8 #include <map>
9 #include <string>
10
11 #include "base/files/file_path_watcher.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
14 #include "chrome/browser/chromeos/drive/file_system_observer.h"
15 #include "chrome/browser/chromeos/drive/job_list.h"
16 #include "chrome/browser/chromeos/extensions/file_manager/file_watcher_extension s.h"
17 #include "chrome/browser/chromeos/net/connectivity_state_helper_observer.h"
18 #include "chrome/browser/drive/drive_service_interface.h"
19 #include "chromeos/disks/disk_mount_manager.h"
20
21 class PrefChangeRegistrar;
22 class Profile;
23
24 namespace file_manager {
25
26 class DesktopNotifications;
27 class MountedDiskMonitor;
28
29 // Monitors changes in disk mounts, network connection state and preferences
30 // affecting File Manager. Dispatches appropriate File Browser events.
31 class FileManagerEventRouter
32 : public chromeos::disks::DiskMountManager::Observer,
33 public chromeos::ConnectivityStateHelperObserver,
34 public drive::DriveIntegrationServiceObserver,
35 public drive::FileSystemObserver,
36 public drive::JobListObserver,
37 public drive::DriveServiceObserver {
38 public:
39 explicit FileManagerEventRouter(Profile* profile);
40 virtual ~FileManagerEventRouter();
41
42 void Shutdown();
43
44 // Starts observing file system change events.
45 void ObserveFileSystemEvents();
46
47 typedef base::Callback<void(bool success)> BoolCallback;
48
49 // Adds a file watch at |local_path|, associated with |virtual_path|, for
50 // an extension with |extension_id|.
51 //
52 // |callback| will be called with true on success, or false on failure.
53 // |callback| must not be null.
54 void AddFileWatch(const base::FilePath& local_path,
55 const base::FilePath& virtual_path,
56 const std::string& extension_id,
57 const BoolCallback& callback);
58
59 // Removes a file watch at |local_path| for an extension with |extension_id|.
60 void RemoveFileWatch(const base::FilePath& local_path,
61 const std::string& extension_id);
62
63 // CrosDisksClient::Observer overrides.
64 virtual void OnDiskEvent(
65 chromeos::disks::DiskMountManager::DiskEvent event,
66 const chromeos::disks::DiskMountManager::Disk* disk) OVERRIDE;
67 virtual void OnDeviceEvent(
68 chromeos::disks::DiskMountManager::DeviceEvent event,
69 const std::string& device_path) OVERRIDE;
70 virtual void OnMountEvent(
71 chromeos::disks::DiskMountManager::MountEvent event,
72 chromeos::MountError error_code,
73 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info)
74 OVERRIDE;
75 virtual void OnFormatEvent(
76 chromeos::disks::DiskMountManager::FormatEvent event,
77 chromeos::FormatError error_code,
78 const std::string& device_path) OVERRIDE;
79
80 // chromeos::ConnectivityStateHelperObserver override.
81 virtual void NetworkManagerChanged() OVERRIDE;
82 virtual void DefaultNetworkChanged() OVERRIDE;
83
84 // drive::JobListObserver overrides.
85 virtual void OnJobAdded(const drive::JobInfo& job_info) OVERRIDE;
86 virtual void OnJobUpdated(const drive::JobInfo& job_info) OVERRIDE;
87 virtual void OnJobDone(const drive::JobInfo& job_info,
88 drive::FileError error) OVERRIDE;
89
90 // drive::DriveServiceObserver overrides.
91 virtual void OnRefreshTokenInvalid() OVERRIDE;
92
93 // drive::FileSystemObserver overrides.
94 virtual void OnDirectoryChanged(
95 const base::FilePath& directory_path) OVERRIDE;
96
97 // drive::DriveIntegrationServiceObserver overrides.
98 virtual void OnFileSystemMounted() OVERRIDE;
99 virtual void OnFileSystemBeingUnmounted() OVERRIDE;
100
101 private:
102 typedef std::map<base::FilePath, FileWatcherExtensions*> WatcherMap;
103
104 // USB mount event handlers.
105 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk);
106 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk);
107 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk);
108 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk);
109 void OnDeviceAdded(const std::string& device_path);
110 void OnDeviceRemoved(const std::string& device_path);
111 void OnDeviceScanned(const std::string& device_path);
112 void OnFormatStarted(const std::string& device_path, bool success);
113 void OnFormatCompleted(const std::string& device_path, bool success);
114
115 // Called on change to kExternalStorageDisabled pref.
116 void OnExternalStorageDisabledChanged();
117
118 // Called when prefs related to file manager change.
119 void OnFileManagerPrefsChanged();
120
121 // Process file watch notifications.
122 void HandleFileWatchNotification(const base::FilePath& path,
123 bool got_error);
124
125 // Sends directory change event.
126 void DispatchDirectoryChangeEvent(
127 const base::FilePath& path,
128 bool error,
129 const FileWatcherExtensions::ExtensionUsageRegistry& extensions);
130
131 void DispatchMountEvent(
132 chromeos::disks::DiskMountManager::MountEvent event,
133 chromeos::MountError error_code,
134 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info);
135
136 // If needed, opens a file manager window for the removable device mounted at
137 // |mount_path|. Disk.mount_path() is empty, since it is being filled out
138 // after calling notifying observers by DiskMountManager.
139 void ShowRemovableDeviceInFileManager(
140 const chromeos::disks::DiskMountManager::Disk& disk,
141 const base::FilePath& mount_path);
142
143 // Sends onFileTranferUpdated to extensions if needed. If |always| is true,
144 // it sends the event always. Otherwise, it sends the event if enough time has
145 // passed from the previous event so as not to make extension busy.
146 void SendDriveFileTransferEvent(bool always);
147
148 // Manages the list of currently active Drive file transfer jobs.
149 struct DriveJobInfoWithStatus {
150 DriveJobInfoWithStatus();
151 DriveJobInfoWithStatus(const drive::JobInfo& info,
152 const std::string& status);
153 drive::JobInfo job_info;
154 std::string status;
155 };
156 std::map<drive::JobID, DriveJobInfoWithStatus> drive_jobs_;
157 base::Time last_file_transfer_event_;
158
159 base::FilePathWatcher::Callback file_watcher_callback_;
160 WatcherMap file_watchers_;
161 scoped_ptr<DesktopNotifications> notifications_;
162 scoped_ptr<PrefChangeRegistrar> pref_change_registrar_;
163 scoped_ptr<MountedDiskMonitor> mounted_disk_monitor_;
164 Profile* profile_;
165
166 // Note: This should remain the last member so it'll be destroyed and
167 // invalidate the weak pointers before any other members are destroyed.
168 base::WeakPtrFactory<FileManagerEventRouter> weak_factory_;
169 DISALLOW_COPY_AND_ASSIGN(FileManagerEventRouter);
170 };
171
172 } // namespace file_manager
173
174 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_FILE_MANAGER_EVENT_RO UTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698