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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.h

Issue 9720020: [COPY] - Implemented API for tracking ongoing file transfers from file manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_event_router.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/files/file_path_watcher.h" 13 #include "base/files/file_path_watcher.h"
14 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "chrome/browser/chromeos/disks/disk_mount_manager.h" 18 #include "chrome/browser/chromeos/disks/disk_mount_manager.h"
19 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
20 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h"
21 #include "chrome/browser/profiles/profile_keyed_service.h"
22 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
19 23
20 class FileBrowserNotifications; 24 class FileBrowserNotifications;
21 class Profile; 25 class Profile;
22 26
23 // Used to monitor disk mount changes and signal when new mounted usb device is 27 // Used to monitor disk mount changes and signal when new mounted usb device is
24 // found. 28 // found.
25 class ExtensionFileBrowserEventRouter 29 class FileBrowserEventRouter
26 : public chromeos::disks::DiskMountManager::Observer { 30 : public ProfileKeyedService,
31 public chromeos::disks::DiskMountManager::Observer,
32 public gdata::GDataOperationRegistry::Observer {
27 public: 33 public:
28 explicit ExtensionFileBrowserEventRouter(Profile* profile); 34 // ProfileKeyedService overrides.
29 virtual ~ExtensionFileBrowserEventRouter(); 35 virtual void Shutdown() OVERRIDE;
36
30 // Starts observing file system change events. Currently only 37 // Starts observing file system change events. Currently only
31 // CrosDisksClient events are being observed. 38 // CrosDisksClient events are being observed.
32 void ObserveFileSystemEvents(); 39 void ObserveFileSystemEvents();
33 40
34 // File watch setup routines. 41 // File watch setup routines.
35 bool AddFileWatch(const FilePath& file_path, 42 bool AddFileWatch(const FilePath& file_path,
36 const FilePath& virtual_path, 43 const FilePath& virtual_path,
37 const std::string& extension_id); 44 const std::string& extension_id);
38 void RemoveFileWatch(const FilePath& file_path, 45 void RemoveFileWatch(const FilePath& file_path,
39 const std::string& extension_id); 46 const std::string& extension_id);
40 47
41 // CrosDisksClient::Observer overrides. 48 // CrosDisksClient::Observer overrides.
42 virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event, 49 virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event,
43 const chromeos::disks::DiskMountManager::Disk* disk) 50 const chromeos::disks::DiskMountManager::Disk* disk)
44 OVERRIDE; 51 OVERRIDE;
45 virtual void DeviceChanged(chromeos::disks::DiskMountManagerEventType event, 52 virtual void DeviceChanged(chromeos::disks::DiskMountManagerEventType event,
46 const std::string& device_path) OVERRIDE; 53 const std::string& device_path) OVERRIDE;
47 virtual void MountCompleted( 54 virtual void MountCompleted(
48 chromeos::disks::DiskMountManager::MountEvent event_type, 55 chromeos::disks::DiskMountManager::MountEvent event_type,
49 chromeos::MountError error_code, 56 chromeos::MountError error_code,
50 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info) 57 const chromeos::disks::DiskMountManager::MountPointInfo& mount_info)
51 OVERRIDE; 58 OVERRIDE;
52 59
60 // GDataOperationRegistry::Observer overrides.
61 virtual void OnProgressUpdate(
62 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list)
63 OVERRIDE;
64
53 private: 65 private:
66 friend class FileBrowserEventRouterFactory;
67
54 // Helper class for passing through file watch notification events. 68 // Helper class for passing through file watch notification events.
55 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate { 69 class FileWatcherDelegate : public base::files::FilePathWatcher::Delegate {
56 public: 70 public:
57 explicit FileWatcherDelegate(ExtensionFileBrowserEventRouter* router); 71 explicit FileWatcherDelegate(FileBrowserEventRouter* router);
58 72
59 private: 73 private:
60 // base::files::FilePathWatcher::Delegate overrides. 74 // base::files::FilePathWatcher::Delegate overrides.
61 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE; 75 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE;
62 virtual void OnFilePathError(const FilePath& path) OVERRIDE; 76 virtual void OnFilePathError(const FilePath& path) OVERRIDE;
63 77
64 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error); 78 void HandleFileWatchOnUIThread(const FilePath& local_path, bool got_error);
65 79
66 ExtensionFileBrowserEventRouter* router_; 80 FileBrowserEventRouter* router_;
67 }; 81 };
68 82
69 typedef std::map<std::string, int> ExtensionUsageRegistry; 83 typedef std::map<std::string, int> ExtensionUsageRegistry;
70 84
71 class FileWatcherExtensions { 85 class FileWatcherExtensions {
72 public: 86 public:
73 FileWatcherExtensions(const FilePath& path, 87 FileWatcherExtensions(const FilePath& path,
74 const std::string& extension_id); 88 const std::string& extension_id);
75 89
76 ~FileWatcherExtensions() {} 90 ~FileWatcherExtensions() {}
(...skipping 13 matching lines...) Expand all
90 private: 104 private:
91 linked_ptr<base::files::FilePathWatcher> file_watcher; 105 linked_ptr<base::files::FilePathWatcher> file_watcher;
92 FilePath local_path; 106 FilePath local_path;
93 FilePath virtual_path; 107 FilePath virtual_path;
94 ExtensionUsageRegistry extensions; 108 ExtensionUsageRegistry extensions;
95 unsigned int ref_count; 109 unsigned int ref_count;
96 }; 110 };
97 111
98 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap; 112 typedef std::map<FilePath, FileWatcherExtensions*> WatcherMap;
99 113
114 explicit FileBrowserEventRouter(Profile* profile);
115 virtual ~FileBrowserEventRouter();
116
100 // USB mount event handlers. 117 // USB mount event handlers.
101 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk); 118 void OnDiskAdded(const chromeos::disks::DiskMountManager::Disk* disk);
102 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk); 119 void OnDiskRemoved(const chromeos::disks::DiskMountManager::Disk* disk);
103 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk); 120 void OnDiskMounted(const chromeos::disks::DiskMountManager::Disk* disk);
104 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk); 121 void OnDiskUnmounted(const chromeos::disks::DiskMountManager::Disk* disk);
105 void OnDeviceAdded(const std::string& device_path); 122 void OnDeviceAdded(const std::string& device_path);
106 void OnDeviceRemoved(const std::string& device_path); 123 void OnDeviceRemoved(const std::string& device_path);
107 void OnDeviceScanned(const std::string& device_path); 124 void OnDeviceScanned(const std::string& device_path);
108 void OnFormattingStarted(const std::string& device_path, bool success); 125 void OnFormattingStarted(const std::string& device_path, bool success);
109 void OnFormattingFinished(const std::string& device_path, bool success); 126 void OnFormattingFinished(const std::string& device_path, bool success);
(...skipping 22 matching lines...) Expand all
132 void OpenFileBrowse(const std::string& url, 149 void OpenFileBrowse(const std::string& url,
133 const std::string& device_path, 150 const std::string& device_path,
134 bool small); 151 bool small);
135 152
136 scoped_refptr<FileWatcherDelegate> delegate_; 153 scoped_refptr<FileWatcherDelegate> delegate_;
137 WatcherMap file_watchers_; 154 WatcherMap file_watchers_;
138 scoped_ptr<FileBrowserNotifications> notifications_; 155 scoped_ptr<FileBrowserNotifications> notifications_;
139 Profile* profile_; 156 Profile* profile_;
140 base::Lock lock_; 157 base::Lock lock_;
141 158
142 DISALLOW_COPY_AND_ASSIGN(ExtensionFileBrowserEventRouter); 159 DISALLOW_COPY_AND_ASSIGN(FileBrowserEventRouter);
160 };
161
162 // Singleton that owns all FileBrowserEventRouter and associates
163 // them with Profiles.
164 class FileBrowserEventRouterFactory
165 : public ProfileKeyedServiceFactory {
166 public:
167 // Returns the FileBrowserEventRouter for |profile|, creating it if
168 // it is not yet created.
169 static FileBrowserEventRouter* GetForProfile(Profile* profile);
170
171 // Returns the FileBrowserEventRouterFactory instance.
172 static FileBrowserEventRouterFactory* GetInstance();
173
174 private:
175 friend struct DefaultSingletonTraits<FileBrowserEventRouterFactory>;
176
177 FileBrowserEventRouterFactory();
178 virtual ~FileBrowserEventRouterFactory();
179
180 // ProfileKeyedServiceFactory:
181 virtual ProfileKeyedService* BuildServiceInstanceFor(
182 Profile* profile) const OVERRIDE;
143 }; 183 };
144 184
145 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_ 185 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_BROWSER_EVENT_ROUTER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/file_browser_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698