OLD | NEW |
---|---|
1 // Copyright (c) 2012 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 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 default: | 80 default: |
81 NOTREACHED(); | 81 NOTREACHED(); |
82 } | 82 } |
83 return ""; | 83 return ""; |
84 } | 84 } |
85 | 85 |
86 FileBrowserEventRouter::FileBrowserEventRouter( | 86 FileBrowserEventRouter::FileBrowserEventRouter( |
87 Profile* profile) | 87 Profile* profile) |
88 : delegate_(new FileBrowserEventRouter::FileWatcherDelegate(this)), | 88 : delegate_(new FileBrowserEventRouter::FileWatcherDelegate(this)), |
89 notifications_(new FileBrowserNotifications(profile)), | 89 notifications_(new FileBrowserNotifications(profile)), |
90 profile_(profile) { | 90 profile_(profile), |
91 num_remote_update_requests_(0) { | |
91 } | 92 } |
92 | 93 |
93 FileBrowserEventRouter::~FileBrowserEventRouter() { | 94 FileBrowserEventRouter::~FileBrowserEventRouter() { |
94 } | 95 } |
95 | 96 |
96 void FileBrowserEventRouter::ShutdownOnUIThread() { | 97 void FileBrowserEventRouter::ShutdownOnUIThread() { |
97 DCHECK(file_watchers_.empty()); | 98 DCHECK(file_watchers_.empty()); |
98 STLDeleteValues(&file_watchers_); | 99 STLDeleteValues(&file_watchers_); |
99 if (!profile_) { | 100 if (!profile_) { |
100 NOTREACHED(); | 101 NOTREACHED(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 return; | 134 return; |
134 } | 135 } |
135 system_service->file_system()->GetOperationRegistry()->AddObserver(this); | 136 system_service->file_system()->GetOperationRegistry()->AddObserver(this); |
136 system_service->file_system()->AddObserver(this); | 137 system_service->file_system()->AddObserver(this); |
137 } | 138 } |
138 | 139 |
139 // File watch setup routines. | 140 // File watch setup routines. |
140 bool FileBrowserEventRouter::AddFileWatch( | 141 bool FileBrowserEventRouter::AddFileWatch( |
141 const FilePath& local_path, | 142 const FilePath& local_path, |
142 const FilePath& virtual_path, | 143 const FilePath& virtual_path, |
143 const std::string& extension_id) { | 144 const std::string& extension_id) { |
satorux1
2012/05/04 00:42:20
I thought we wanted to have
DCHECK(BrowserThread:
hshi
2012/05/04 00:44:34
Sorry, the CL is already committed. I'll try to sq
| |
144 base::AutoLock lock(lock_); | 145 base::AutoLock lock(lock_); |
145 FilePath watch_path = local_path; | 146 FilePath watch_path = local_path; |
146 bool is_remote_watch = false; | 147 bool is_remote_watch = false; |
147 // Tweak watch path for remote sources - we need to drop leading /special | 148 // Tweak watch path for remote sources - we need to drop leading /special |
148 // directory from there in order to be able to pair these events with | 149 // directory from there in order to be able to pair these events with |
149 // their change notifications. | 150 // their change notifications. |
150 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { | 151 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { |
151 watch_path = gdata::util::ExtractGDataPath(watch_path); | 152 watch_path = gdata::util::ExtractGDataPath(watch_path); |
152 is_remote_watch = true; | 153 is_remote_watch = true; |
154 BrowserThread::PostTask( | |
155 BrowserThread::UI, FROM_HERE, | |
156 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, | |
157 this, true)); | |
153 } | 158 } |
154 | 159 |
155 WatcherMap::iterator iter = file_watchers_.find(watch_path); | 160 WatcherMap::iterator iter = file_watchers_.find(watch_path); |
156 if (iter == file_watchers_.end()) { | 161 if (iter == file_watchers_.end()) { |
157 scoped_ptr<FileWatcherExtensions> | 162 scoped_ptr<FileWatcherExtensions> |
158 watch(new FileWatcherExtensions(virtual_path, | 163 watch(new FileWatcherExtensions(virtual_path, |
159 extension_id, | 164 extension_id, |
160 is_remote_watch)); | 165 is_remote_watch)); |
161 | 166 |
162 if (watch->Watch(watch_path, delegate_.get())) | 167 if (watch->Watch(watch_path, delegate_.get())) |
163 file_watchers_[watch_path] = watch.release(); | 168 file_watchers_[watch_path] = watch.release(); |
164 else | 169 else |
165 return false; | 170 return false; |
166 } else { | 171 } else { |
167 iter->second->AddExtension(extension_id); | 172 iter->second->AddExtension(extension_id); |
168 } | 173 } |
169 return true; | 174 return true; |
170 } | 175 } |
171 | 176 |
172 void FileBrowserEventRouter::RemoveFileWatch( | 177 void FileBrowserEventRouter::RemoveFileWatch( |
173 const FilePath& local_path, | 178 const FilePath& local_path, |
174 const std::string& extension_id) { | 179 const std::string& extension_id) { |
satorux1
2012/05/04 00:42:20
ditto.
| |
175 base::AutoLock lock(lock_); | 180 base::AutoLock lock(lock_); |
176 FilePath watch_path = local_path; | 181 FilePath watch_path = local_path; |
177 // Tweak watch path for remote sources - we need to drop leading /special | 182 // Tweak watch path for remote sources - we need to drop leading /special |
178 // directory from there in order to be able to pair these events with | 183 // directory from there in order to be able to pair these events with |
179 // their change notifications. | 184 // their change notifications. |
180 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { | 185 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { |
181 watch_path = gdata::util::ExtractGDataPath(watch_path); | 186 watch_path = gdata::util::ExtractGDataPath(watch_path); |
187 BrowserThread::PostTask( | |
188 BrowserThread::UI, FROM_HERE, | |
189 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, | |
190 this, false)); | |
182 } | 191 } |
183 WatcherMap::iterator iter = file_watchers_.find(watch_path); | 192 WatcherMap::iterator iter = file_watchers_.find(watch_path); |
184 if (iter == file_watchers_.end()) | 193 if (iter == file_watchers_.end()) |
185 return; | 194 return; |
186 // Remove the renderer process for this watch. | 195 // Remove the renderer process for this watch. |
187 iter->second->RemoveExtension(extension_id); | 196 iter->second->RemoveExtension(extension_id); |
188 if (iter->second->GetRefCount() == 0) { | 197 if (iter->second->GetRefCount() == 0) { |
189 delete iter->second; | 198 delete iter->second; |
190 file_watchers_.erase(iter); | 199 file_watchers_.erase(iter); |
191 } | 200 } |
192 } | 201 } |
193 | 202 |
203 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { | |
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
205 | |
206 gdata::GDataFileSystem* file_system = GetRemoteFileSystem(); | |
207 DCHECK(file_system); | |
208 | |
209 if (start) { | |
210 file_system->CheckForUpdates(); | |
211 if (num_remote_update_requests_ == 0) | |
212 file_system->StartUpdates(); | |
213 ++num_remote_update_requests_; | |
214 } else { | |
215 DCHECK_LE(0, num_remote_update_requests_); | |
216 --num_remote_update_requests_; | |
217 if (num_remote_update_requests_ == 0) | |
218 file_system->StopUpdates(); | |
219 } | |
220 } | |
221 | |
194 void FileBrowserEventRouter::DiskChanged( | 222 void FileBrowserEventRouter::DiskChanged( |
195 DiskMountManagerEventType event, | 223 DiskMountManagerEventType event, |
196 const DiskMountManager::Disk* disk) { | 224 const DiskMountManager::Disk* disk) { |
197 // Disregard hidden devices. | 225 // Disregard hidden devices. |
198 if (disk->is_hidden()) | 226 if (disk->is_hidden()) |
199 return; | 227 return; |
200 if (event == chromeos::disks::MOUNT_DISK_ADDED) { | 228 if (event == chromeos::disks::MOUNT_DISK_ADDED) { |
201 OnDiskAdded(disk); | 229 OnDiskAdded(disk); |
202 } else if (event == chromeos::disks::MOUNT_DISK_REMOVED) { | 230 } else if (event == chromeos::disks::MOUNT_DISK_REMOVED) { |
203 OnDiskRemoved(disk); | 231 OnDiskRemoved(disk); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 notifications_->ManageNotificationsOnMountCompleted( | 276 notifications_->ManageNotificationsOnMountCompleted( |
249 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), | 277 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), |
250 error_code == chromeos::MOUNT_ERROR_NONE, | 278 error_code == chromeos::MOUNT_ERROR_NONE, |
251 error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM); | 279 error_code == chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM); |
252 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 280 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
253 // Clear the "mounted" state for archive files in gdata cache | 281 // Clear the "mounted" state for archive files in gdata cache |
254 // when mounting failed or unmounting succeeded. | 282 // when mounting failed or unmounting succeeded. |
255 if ((event_type == DiskMountManager::MOUNTING) != | 283 if ((event_type == DiskMountManager::MOUNTING) != |
256 (error_code == chromeos::MOUNT_ERROR_NONE)) { | 284 (error_code == chromeos::MOUNT_ERROR_NONE)) { |
257 FilePath source_path(mount_info.source_path); | 285 FilePath source_path(mount_info.source_path); |
258 gdata::GDataSystemService* system_service = | 286 gdata::GDataFileSystem* file_system = GetRemoteFileSystem(); |
259 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | |
260 gdata::GDataFileSystem* file_system = | |
261 system_service ? system_service->file_system() : NULL; | |
262 if (file_system && file_system->IsUnderGDataCacheDirectory(source_path)) | 287 if (file_system && file_system->IsUnderGDataCacheDirectory(source_path)) |
263 file_system->SetMountedState(source_path, false, | 288 file_system->SetMountedState(source_path, false, |
264 gdata::SetMountedStateCallback()); | 289 gdata::SetMountedStateCallback()); |
265 } | 290 } |
266 } | 291 } |
267 } | 292 } |
268 | 293 |
269 void FileBrowserEventRouter::OnProgressUpdate( | 294 void FileBrowserEventRouter::OnProgressUpdate( |
270 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { | 295 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { |
271 scoped_ptr<ListValue> event_list( | 296 scoped_ptr<ListValue> event_list( |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 unsigned int | 619 unsigned int |
595 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const { | 620 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const { |
596 return ref_count_; | 621 return ref_count_; |
597 } | 622 } |
598 | 623 |
599 const FilePath& | 624 const FilePath& |
600 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { | 625 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { |
601 return virtual_path_; | 626 return virtual_path_; |
602 } | 627 } |
603 | 628 |
629 gdata::GDataFileSystem* FileBrowserEventRouter::GetRemoteFileSystem() const { | |
630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
631 gdata::GDataSystemService* system_service = | |
632 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | |
633 return (system_service ? system_service->file_system() : NULL); | |
634 } | |
635 | |
604 bool FileBrowserEventRouter::FileWatcherExtensions::Watch | 636 bool FileBrowserEventRouter::FileWatcherExtensions::Watch |
605 (const FilePath& path, FileWatcherDelegate* delegate) { | 637 (const FilePath& path, FileWatcherDelegate* delegate) { |
606 if (is_remote_file_system_) | 638 if (is_remote_file_system_) |
607 return true; | 639 return true; |
608 | 640 |
609 return file_watcher_->Watch(path, delegate); | 641 return file_watcher_->Watch(path, delegate); |
610 } | 642 } |
611 | 643 |
612 // static | 644 // static |
613 scoped_refptr<FileBrowserEventRouter> | 645 scoped_refptr<FileBrowserEventRouter> |
(...skipping 22 matching lines...) Expand all Loading... | |
636 return scoped_refptr<RefcountedProfileKeyedService>( | 668 return scoped_refptr<RefcountedProfileKeyedService>( |
637 new FileBrowserEventRouter(profile)); | 669 new FileBrowserEventRouter(profile)); |
638 } | 670 } |
639 | 671 |
640 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 672 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
641 // Explicitly and always allow this router in guest login mode. see | 673 // Explicitly and always allow this router in guest login mode. see |
642 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 674 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
643 // for the details. | 675 // for the details. |
644 return true; | 676 return true; |
645 } | 677 } |
OLD | NEW |