| 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" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/api/prefs/pref_change_registrar.h" | 12 #include "chrome/browser/api/prefs/pref_change_registrar.h" |
| 13 #include "chrome/browser/chromeos/cros/cros_library.h" | 13 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 14 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" | 14 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" |
| 15 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 15 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
| 16 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 16 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
| 17 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 17 #include "chrome/browser/chromeos/gdata/drive_system_service.h" |
| 18 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 18 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 19 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 19 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
| 20 #include "chrome/browser/chromeos/login/screen_locker.h" | 20 #include "chrome/browser/chromeos/login/screen_locker.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 22 #include "chrome/browser/extensions/event_names.h" | 22 #include "chrome/browser/extensions/event_names.h" |
| 23 #include "chrome/browser/extensions/event_router.h" | 23 #include "chrome/browser/extensions/event_router.h" |
| 24 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/profiles/profile_dependency_manager.h" | 27 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "webkit/fileapi/file_system_types.h" | 33 #include "webkit/fileapi/file_system_types.h" |
| 34 #include "webkit/fileapi/file_system_util.h" | 34 #include "webkit/fileapi/file_system_util.h" |
| 35 | 35 |
| 36 using chromeos::disks::DiskMountManager; | 36 using chromeos::disks::DiskMountManager; |
| 37 using chromeos::disks::DiskMountManagerEventType; | 37 using chromeos::disks::DiskMountManagerEventType; |
| 38 using content::BrowserThread; | 38 using content::BrowserThread; |
| 39 using gdata::DriveFileSystemInterface; | 39 using gdata::DriveFileSystemInterface; |
| 40 using gdata::GDataSystemService; | 40 using gdata::DriveSystemService; |
| 41 using gdata::GDataSystemServiceFactory; | 41 using gdata::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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 104 | 104 |
| 105 DCHECK(file_watchers_.empty()); | 105 DCHECK(file_watchers_.empty()); |
| 106 STLDeleteValues(&file_watchers_); | 106 STLDeleteValues(&file_watchers_); |
| 107 if (!profile_) { | 107 if (!profile_) { |
| 108 NOTREACHED(); | 108 NOTREACHED(); |
| 109 return; | 109 return; |
| 110 } | 110 } |
| 111 DiskMountManager::GetInstance()->RemoveObserver(this); | 111 DiskMountManager::GetInstance()->RemoveObserver(this); |
| 112 | 112 |
| 113 GDataSystemService* system_service = | 113 DriveSystemService* system_service = |
| 114 GDataSystemServiceFactory::FindForProfile(profile_); | 114 DriveSystemServiceFactory::FindForProfile(profile_); |
| 115 if (system_service) { | 115 if (system_service) { |
| 116 system_service->file_system()->RemoveObserver(this); | 116 system_service->file_system()->RemoveObserver(this); |
| 117 system_service->drive_service()->operation_registry()->RemoveObserver(this); | 117 system_service->drive_service()->operation_registry()->RemoveObserver(this); |
| 118 } | 118 } |
| 119 | 119 |
| 120 chromeos::NetworkLibrary* network_library = | 120 chromeos::NetworkLibrary* network_library = |
| 121 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 121 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 122 if (network_library) | 122 if (network_library) |
| 123 network_library->RemoveNetworkManagerObserver(this); | 123 network_library->RemoveNetworkManagerObserver(this); |
| 124 | 124 |
| 125 profile_ = NULL; | 125 profile_ = NULL; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void FileBrowserEventRouter::ObserveFileSystemEvents() { | 128 void FileBrowserEventRouter::ObserveFileSystemEvents() { |
| 129 if (!profile_) { | 129 if (!profile_) { |
| 130 NOTREACHED(); | 130 NOTREACHED(); |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) | 133 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) |
| 134 return; | 134 return; |
| 135 | 135 |
| 136 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 136 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
| 137 disk_mount_manager->RemoveObserver(this); | 137 disk_mount_manager->RemoveObserver(this); |
| 138 disk_mount_manager->AddObserver(this); | 138 disk_mount_manager->AddObserver(this); |
| 139 disk_mount_manager->RequestMountInfoRefresh(); | 139 disk_mount_manager->RequestMountInfoRefresh(); |
| 140 | 140 |
| 141 GDataSystemService* system_service = | 141 DriveSystemService* system_service = |
| 142 GDataSystemServiceFactory::GetForProfile(profile_); | 142 DriveSystemServiceFactory::GetForProfile(profile_); |
| 143 if (!system_service) { | 143 if (!system_service) { |
| 144 NOTREACHED(); | 144 NOTREACHED(); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 system_service->drive_service()->operation_registry()->AddObserver(this); | 147 system_service->drive_service()->operation_registry()->AddObserver(this); |
| 148 system_service->file_system()->AddObserver(this); | 148 system_service->file_system()->AddObserver(this); |
| 149 | 149 |
| 150 chromeos::NetworkLibrary* network_library = | 150 chromeos::NetworkLibrary* network_library = |
| 151 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 151 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 152 if (network_library) | 152 if (network_library) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 if (iter->second->GetRefCount() == 0) { | 223 if (iter->second->GetRefCount() == 0) { |
| 224 delete iter->second; | 224 delete iter->second; |
| 225 file_watchers_.erase(iter); | 225 file_watchers_.erase(iter); |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 void FileBrowserEventRouter::MountDrive( | 229 void FileBrowserEventRouter::MountDrive( |
| 230 const base::Closure& callback) { | 230 const base::Closure& callback) { |
| 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 232 | 232 |
| 233 gdata::GDataSystemService* system_service = | 233 gdata::DriveSystemService* system_service = |
| 234 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 234 gdata::DriveSystemServiceFactory::GetForProfile(profile_); |
| 235 if (system_service) { | 235 if (system_service) { |
| 236 system_service->drive_service()->Authenticate( | 236 system_service->drive_service()->Authenticate( |
| 237 base::Bind(&FileBrowserEventRouter::OnAuthenticated, | 237 base::Bind(&FileBrowserEventRouter::OnAuthenticated, |
| 238 this, | 238 this, |
| 239 callback)); | 239 callback)); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 void FileBrowserEventRouter::OnAuthenticated( | 243 void FileBrowserEventRouter::OnAuthenticated( |
| 244 const base::Closure& callback, | 244 const base::Closure& callback, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 notifications_->ManageNotificationsOnMountCompleted( | 348 notifications_->ManageNotificationsOnMountCompleted( |
| 349 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), | 349 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), |
| 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 gdata::GDataSystemService* system_service = | 358 gdata::DriveSystemService* system_service = |
| 359 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 359 gdata::DriveSystemServiceFactory::GetForProfile(profile_); |
| 360 gdata::DriveCache* cache = | 360 gdata::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, gdata::ChangeCacheStateCallback()); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 } | 814 } |
| 815 | 815 |
| 816 const FilePath& | 816 const FilePath& |
| 817 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { | 817 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { |
| 818 return virtual_path_; | 818 return virtual_path_; |
| 819 } | 819 } |
| 820 | 820 |
| 821 gdata::DriveFileSystemInterface* | 821 gdata::DriveFileSystemInterface* |
| 822 FileBrowserEventRouter::GetRemoteFileSystem() const { | 822 FileBrowserEventRouter::GetRemoteFileSystem() const { |
| 823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 824 gdata::GDataSystemService* system_service = | 824 gdata::DriveSystemService* system_service = |
| 825 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 825 gdata::DriveSystemServiceFactory::GetForProfile(profile_); |
| 826 return (system_service ? system_service->file_system() : NULL); | 826 return (system_service ? system_service->file_system() : NULL); |
| 827 } | 827 } |
| 828 | 828 |
| 829 bool FileBrowserEventRouter::FileWatcherExtensions::Watch | 829 bool FileBrowserEventRouter::FileWatcherExtensions::Watch |
| 830 (const FilePath& path, FileWatcherDelegate* delegate) { | 830 (const FilePath& path, FileWatcherDelegate* delegate) { |
| 831 if (is_remote_file_system_) | 831 if (is_remote_file_system_) |
| 832 return true; | 832 return true; |
| 833 | 833 |
| 834 return file_watcher_->Watch(path, delegate); | 834 return file_watcher_->Watch(path, delegate); |
| 835 } | 835 } |
| 836 | 836 |
| 837 // static | 837 // static |
| 838 scoped_refptr<FileBrowserEventRouter> | 838 scoped_refptr<FileBrowserEventRouter> |
| 839 FileBrowserEventRouterFactory::GetForProfile(Profile* profile) { | 839 FileBrowserEventRouterFactory::GetForProfile(Profile* profile) { |
| 840 return static_cast<FileBrowserEventRouter*>( | 840 return static_cast<FileBrowserEventRouter*>( |
| 841 GetInstance()->GetServiceForProfile(profile, true).get()); | 841 GetInstance()->GetServiceForProfile(profile, true).get()); |
| 842 } | 842 } |
| 843 | 843 |
| 844 // static | 844 // static |
| 845 FileBrowserEventRouterFactory* | 845 FileBrowserEventRouterFactory* |
| 846 FileBrowserEventRouterFactory::GetInstance() { | 846 FileBrowserEventRouterFactory::GetInstance() { |
| 847 return Singleton<FileBrowserEventRouterFactory>::get(); | 847 return Singleton<FileBrowserEventRouterFactory>::get(); |
| 848 } | 848 } |
| 849 | 849 |
| 850 FileBrowserEventRouterFactory::FileBrowserEventRouterFactory() | 850 FileBrowserEventRouterFactory::FileBrowserEventRouterFactory() |
| 851 : RefcountedProfileKeyedServiceFactory("FileBrowserEventRouter", | 851 : RefcountedProfileKeyedServiceFactory("FileBrowserEventRouter", |
| 852 ProfileDependencyManager::GetInstance()) { | 852 ProfileDependencyManager::GetInstance()) { |
| 853 DependsOn(GDataSystemServiceFactory::GetInstance()); | 853 DependsOn(DriveSystemServiceFactory::GetInstance()); |
| 854 } | 854 } |
| 855 | 855 |
| 856 FileBrowserEventRouterFactory::~FileBrowserEventRouterFactory() { | 856 FileBrowserEventRouterFactory::~FileBrowserEventRouterFactory() { |
| 857 } | 857 } |
| 858 | 858 |
| 859 scoped_refptr<RefcountedProfileKeyedService> | 859 scoped_refptr<RefcountedProfileKeyedService> |
| 860 FileBrowserEventRouterFactory::BuildServiceInstanceFor(Profile* profile) const { | 860 FileBrowserEventRouterFactory::BuildServiceInstanceFor(Profile* profile) const { |
| 861 return scoped_refptr<RefcountedProfileKeyedService>( | 861 return scoped_refptr<RefcountedProfileKeyedService>( |
| 862 new FileBrowserEventRouter(profile)); | 862 new FileBrowserEventRouter(profile)); |
| 863 } | 863 } |
| 864 | 864 |
| 865 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 865 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
| 866 // Explicitly and always allow this router in guest login mode. see | 866 // Explicitly and always allow this router in guest login mode. see |
| 867 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 867 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
| 868 // for the details. | 868 // for the details. |
| 869 return true; | 869 return true; |
| 870 } | 870 } |
| OLD | NEW |