| 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 19 matching lines...) Expand all Loading... |
| 30 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 31 #include "content/public/browser/notification_source.h" | 31 #include "content/public/browser/notification_source.h" |
| 32 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "webkit/fileapi/file_system_types.h" | 34 #include "webkit/fileapi/file_system_types.h" |
| 35 #include "webkit/fileapi/file_system_util.h" | 35 #include "webkit/fileapi/file_system_util.h" |
| 36 | 36 |
| 37 using chromeos::disks::DiskMountManager; | 37 using chromeos::disks::DiskMountManager; |
| 38 using chromeos::disks::DiskMountManagerEventType; | 38 using chromeos::disks::DiskMountManagerEventType; |
| 39 using content::BrowserThread; | 39 using content::BrowserThread; |
| 40 using gdata::DriveSystemService; | 40 using drive::DriveSystemService; |
| 41 using gdata::DriveSystemServiceFactory; | 41 using drive::DriveSystemServiceFactory; |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 const char kDiskAddedEventType[] = "added"; | 44 const char kDiskAddedEventType[] = "added"; |
| 45 const char kDiskRemovedEventType[] = "removed"; | 45 const char kDiskRemovedEventType[] = "removed"; |
| 46 | 46 |
| 47 const char kPathChanged[] = "changed"; | 47 const char kPathChanged[] = "changed"; |
| 48 const char kPathWatchError[] = "error"; | 48 const char kPathWatchError[] = "error"; |
| 49 | 49 |
| 50 DictionaryValue* DiskToDictionaryValue( | 50 DictionaryValue* DiskToDictionaryValue( |
| 51 const DiskMountManager::Disk* disk) { | 51 const DiskMountManager::Disk* disk) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 const FilePath& virtual_path, | 165 const FilePath& virtual_path, |
| 166 const std::string& extension_id) { | 166 const std::string& extension_id) { |
| 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 168 | 168 |
| 169 base::AutoLock lock(lock_); | 169 base::AutoLock lock(lock_); |
| 170 FilePath watch_path = local_path; | 170 FilePath watch_path = local_path; |
| 171 bool is_remote_watch = false; | 171 bool is_remote_watch = false; |
| 172 // Tweak watch path for remote sources - we need to drop leading /special | 172 // Tweak watch path for remote sources - we need to drop leading /special |
| 173 // directory from there in order to be able to pair these events with | 173 // directory from there in order to be able to pair these events with |
| 174 // their change notifications. | 174 // their change notifications. |
| 175 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { | 175 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { |
| 176 watch_path = gdata::util::ExtractDrivePath(watch_path); | 176 watch_path = drive::util::ExtractDrivePath(watch_path); |
| 177 is_remote_watch = true; | 177 is_remote_watch = true; |
| 178 BrowserThread::PostTask( | 178 BrowserThread::PostTask( |
| 179 BrowserThread::UI, FROM_HERE, | 179 BrowserThread::UI, FROM_HERE, |
| 180 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, | 180 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, |
| 181 this, true)); | 181 this, true)); |
| 182 } | 182 } |
| 183 | 183 |
| 184 WatcherMap::iterator iter = file_watchers_.find(watch_path); | 184 WatcherMap::iterator iter = file_watchers_.find(watch_path); |
| 185 if (iter == file_watchers_.end()) { | 185 if (iter == file_watchers_.end()) { |
| 186 scoped_ptr<FileWatcherExtensions> | 186 scoped_ptr<FileWatcherExtensions> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 201 void FileBrowserEventRouter::RemoveFileWatch( | 201 void FileBrowserEventRouter::RemoveFileWatch( |
| 202 const FilePath& local_path, | 202 const FilePath& local_path, |
| 203 const std::string& extension_id) { | 203 const std::string& extension_id) { |
| 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 205 | 205 |
| 206 base::AutoLock lock(lock_); | 206 base::AutoLock lock(lock_); |
| 207 FilePath watch_path = local_path; | 207 FilePath watch_path = local_path; |
| 208 // Tweak watch path for remote sources - we need to drop leading /special | 208 // Tweak watch path for remote sources - we need to drop leading /special |
| 209 // directory from there in order to be able to pair these events with | 209 // directory from there in order to be able to pair these events with |
| 210 // their change notifications. | 210 // their change notifications. |
| 211 if (gdata::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { | 211 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { |
| 212 watch_path = gdata::util::ExtractDrivePath(watch_path); | 212 watch_path = drive::util::ExtractDrivePath(watch_path); |
| 213 BrowserThread::PostTask( | 213 BrowserThread::PostTask( |
| 214 BrowserThread::UI, FROM_HERE, | 214 BrowserThread::UI, FROM_HERE, |
| 215 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, | 215 base::Bind(&FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread, |
| 216 this, false)); | 216 this, false)); |
| 217 } | 217 } |
| 218 WatcherMap::iterator iter = file_watchers_.find(watch_path); | 218 WatcherMap::iterator iter = file_watchers_.find(watch_path); |
| 219 if (iter == file_watchers_.end()) | 219 if (iter == file_watchers_.end()) |
| 220 return; | 220 return; |
| 221 // Remove the renderer process for this watch. | 221 // Remove the renderer process for this watch. |
| 222 iter->second->RemoveExtension(extension_id); | 222 iter->second->RemoveExtension(extension_id); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 248 | 248 |
| 249 chromeos::MountError error_code; | 249 chromeos::MountError error_code; |
| 250 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed. | 250 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed. |
| 251 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) | 251 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) |
| 252 error_code = chromeos::MOUNT_ERROR_NONE; | 252 error_code = chromeos::MOUNT_ERROR_NONE; |
| 253 else | 253 else |
| 254 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | 254 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; |
| 255 | 255 |
| 256 // Pass back the gdata mount point path as source path. | 256 // Pass back the gdata mount point path as source path. |
| 257 const std::string& gdata_path = gdata::util::GetDriveMountPointPathAsString(); | 257 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); |
| 258 DiskMountManager::MountPointInfo mount_info( | 258 DiskMountManager::MountPointInfo mount_info( |
| 259 gdata_path, | 259 gdata_path, |
| 260 gdata_path, | 260 gdata_path, |
| 261 chromeos::MOUNT_TYPE_GDATA, | 261 chromeos::MOUNT_TYPE_GDATA, |
| 262 chromeos::disks::MOUNT_CONDITION_NONE); | 262 chromeos::disks::MOUNT_CONDITION_NONE); |
| 263 | 263 |
| 264 // Raise mount event. | 264 // Raise mount event. |
| 265 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); | 265 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); |
| 266 | 266 |
| 267 if (!callback.is_null()) | 267 if (!callback.is_null()) |
| 268 callback.Run(); | 268 callback.Run(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { | 271 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 273 | 273 |
| 274 gdata::DriveFileSystemInterface* file_system = GetRemoteFileSystem(); | 274 drive::DriveFileSystemInterface* file_system = GetRemoteFileSystem(); |
| 275 DCHECK(file_system); | 275 DCHECK(file_system); |
| 276 | 276 |
| 277 if (start) { | 277 if (start) { |
| 278 file_system->CheckForUpdates(); | 278 file_system->CheckForUpdates(); |
| 279 if (num_remote_update_requests_ == 0) | 279 if (num_remote_update_requests_ == 0) |
| 280 file_system->StartUpdates(); | 280 file_system->StartUpdates(); |
| 281 ++num_remote_update_requests_; | 281 ++num_remote_update_requests_; |
| 282 } else { | 282 } else { |
| 283 DCHECK_LE(1, num_remote_update_requests_); | 283 DCHECK_LE(1, num_remote_update_requests_); |
| 284 --num_remote_update_requests_; | 284 --num_remote_update_requests_; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 error_code == chromeos::MOUNT_ERROR_NONE, | 350 error_code == chromeos::MOUNT_ERROR_NONE, |
| 351 error_code == chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM); | 351 error_code == chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM); |
| 352 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 352 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
| 353 // Clear the "mounted" state for archive files in gdata cache | 353 // Clear the "mounted" state for archive files in gdata cache |
| 354 // when mounting failed or unmounting succeeded. | 354 // when mounting failed or unmounting succeeded. |
| 355 if ((event_type == DiskMountManager::MOUNTING) != | 355 if ((event_type == DiskMountManager::MOUNTING) != |
| 356 (error_code == chromeos::MOUNT_ERROR_NONE)) { | 356 (error_code == chromeos::MOUNT_ERROR_NONE)) { |
| 357 FilePath source_path(mount_info.source_path); | 357 FilePath source_path(mount_info.source_path); |
| 358 DriveSystemService* system_service = | 358 DriveSystemService* system_service = |
| 359 DriveSystemServiceFactory::GetForProfile(profile_); | 359 DriveSystemServiceFactory::GetForProfile(profile_); |
| 360 gdata::DriveCache* cache = | 360 drive::DriveCache* cache = |
| 361 system_service ? system_service->cache() : NULL; | 361 system_service ? system_service->cache() : NULL; |
| 362 if (cache) { | 362 if (cache) { |
| 363 cache->SetMountedStateOnUIThread( | 363 cache->SetMountedStateOnUIThread( |
| 364 source_path, false, gdata::ChangeCacheStateCallback()); | 364 source_path, false, drive::ChangeCacheStateCallback()); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 void FileBrowserEventRouter::OnNetworkManagerChanged( | 370 void FileBrowserEventRouter::OnNetworkManagerChanged( |
| 371 chromeos::NetworkLibrary* network_library) { | 371 chromeos::NetworkLibrary* network_library) { |
| 372 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 372 if (!profile_ || !profile_->GetExtensionEventRouter()) { |
| 373 NOTREACHED(); | 373 NOTREACHED(); |
| 374 return; | 374 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 void FileBrowserEventRouter::OnFileSystemMounted() { | 454 void FileBrowserEventRouter::OnFileSystemMounted() { |
| 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 456 | 456 |
| 457 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. | 457 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. |
| 458 } | 458 } |
| 459 | 459 |
| 460 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { | 460 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { |
| 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 462 | 462 |
| 463 // Raise a MountCompleted event to notify the File Manager. | 463 // Raise a MountCompleted event to notify the File Manager. |
| 464 const std::string& gdata_path = gdata::util::GetDriveMountPointPathAsString(); | 464 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); |
| 465 DiskMountManager::MountPointInfo mount_info( | 465 DiskMountManager::MountPointInfo mount_info( |
| 466 gdata_path, | 466 gdata_path, |
| 467 gdata_path, | 467 gdata_path, |
| 468 chromeos::MOUNT_TYPE_GDATA, | 468 chromeos::MOUNT_TYPE_GDATA, |
| 469 chromeos::disks::MOUNT_CONDITION_NONE); | 469 chromeos::disks::MOUNT_CONDITION_NONE); |
| 470 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, | 470 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, |
| 471 mount_info); | 471 mount_info); |
| 472 } | 472 } |
| 473 | 473 |
| 474 void FileBrowserEventRouter::OnAuthenticationFailed( | 474 void FileBrowserEventRouter::OnAuthenticationFailed( |
| 475 gdata::GDataErrorCode error) { | 475 gdata::GDataErrorCode error) { |
| 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 477 | 477 |
| 478 if (error == gdata::GDATA_NO_CONNECTION) | 478 if (error == gdata::GDATA_NO_CONNECTION) |
| 479 return; | 479 return; |
| 480 | 480 |
| 481 // Raise a MountCompleted event to notify the File Manager. | 481 // Raise a MountCompleted event to notify the File Manager. |
| 482 const std::string& gdata_path = gdata::util::GetDriveMountPointPathAsString(); | 482 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); |
| 483 DiskMountManager::MountPointInfo mount_info( | 483 DiskMountManager::MountPointInfo mount_info( |
| 484 gdata_path, | 484 gdata_path, |
| 485 gdata_path, | 485 gdata_path, |
| 486 chromeos::MOUNT_TYPE_GDATA, | 486 chromeos::MOUNT_TYPE_GDATA, |
| 487 chromeos::disks::MOUNT_CONDITION_NONE); | 487 chromeos::disks::MOUNT_CONDITION_NONE); |
| 488 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, | 488 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, |
| 489 mount_info); | 489 mount_info); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void FileBrowserEventRouter::HandleFileWatchNotification( | 492 void FileBrowserEventRouter::HandleFileWatchNotification( |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 unsigned int | 818 unsigned int |
| 819 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const { | 819 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const { |
| 820 return ref_count_; | 820 return ref_count_; |
| 821 } | 821 } |
| 822 | 822 |
| 823 const FilePath& | 823 const FilePath& |
| 824 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { | 824 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { |
| 825 return virtual_path_; | 825 return virtual_path_; |
| 826 } | 826 } |
| 827 | 827 |
| 828 gdata::DriveFileSystemInterface* | 828 drive::DriveFileSystemInterface* |
| 829 FileBrowserEventRouter::GetRemoteFileSystem() const { | 829 FileBrowserEventRouter::GetRemoteFileSystem() const { |
| 830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 830 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 831 DriveSystemService* system_service = | 831 DriveSystemService* system_service = |
| 832 DriveSystemServiceFactory::GetForProfile(profile_); | 832 DriveSystemServiceFactory::GetForProfile(profile_); |
| 833 return (system_service ? system_service->file_system() : NULL); | 833 return (system_service ? system_service->file_system() : NULL); |
| 834 } | 834 } |
| 835 | 835 |
| 836 bool FileBrowserEventRouter::FileWatcherExtensions::Watch | 836 bool FileBrowserEventRouter::FileWatcherExtensions::Watch |
| 837 (const FilePath& path, FileWatcherDelegate* delegate) { | 837 (const FilePath& path, FileWatcherDelegate* delegate) { |
| 838 if (is_remote_file_system_) | 838 if (is_remote_file_system_) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 868 return scoped_refptr<RefcountedProfileKeyedService>( | 868 return scoped_refptr<RefcountedProfileKeyedService>( |
| 869 new FileBrowserEventRouter(profile)); | 869 new FileBrowserEventRouter(profile)); |
| 870 } | 870 } |
| 871 | 871 |
| 872 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const { | 872 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const { |
| 873 // Explicitly and always allow this router in guest login mode. see | 873 // Explicitly and always allow this router in guest login mode. see |
| 874 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 874 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
| 875 // for the details. | 875 // for the details. |
| 876 return true; | 876 return true; |
| 877 } | 877 } |
| OLD | NEW |