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::GDataSystemService; | 39 using gdata::DriveSystemService; |
40 using gdata::GDataSystemServiceFactory; | 40 using gdata::DriveSystemServiceFactory; |
41 | 41 |
42 namespace { | 42 namespace { |
43 const char kDiskAddedEventType[] = "added"; | 43 const char kDiskAddedEventType[] = "added"; |
44 const char kDiskRemovedEventType[] = "removed"; | 44 const char kDiskRemovedEventType[] = "removed"; |
45 | 45 |
46 const char kPathChanged[] = "changed"; | 46 const char kPathChanged[] = "changed"; |
47 const char kPathWatchError[] = "error"; | 47 const char kPathWatchError[] = "error"; |
48 | 48 |
49 DictionaryValue* DiskToDictionaryValue( | 49 DictionaryValue* DiskToDictionaryValue( |
50 const DiskMountManager::Disk* disk) { | 50 const DiskMountManager::Disk* disk) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
103 | 103 |
104 DCHECK(file_watchers_.empty()); | 104 DCHECK(file_watchers_.empty()); |
105 STLDeleteValues(&file_watchers_); | 105 STLDeleteValues(&file_watchers_); |
106 if (!profile_) { | 106 if (!profile_) { |
107 NOTREACHED(); | 107 NOTREACHED(); |
108 return; | 108 return; |
109 } | 109 } |
110 DiskMountManager::GetInstance()->RemoveObserver(this); | 110 DiskMountManager::GetInstance()->RemoveObserver(this); |
111 | 111 |
112 GDataSystemService* system_service = | 112 DriveSystemService* system_service = |
113 GDataSystemServiceFactory::FindForProfile(profile_); | 113 DriveSystemServiceFactory::FindForProfile(profile_); |
114 if (system_service) { | 114 if (system_service) { |
115 system_service->file_system()->RemoveObserver(this); | 115 system_service->file_system()->RemoveObserver(this); |
116 system_service->drive_service()->operation_registry()->RemoveObserver(this); | 116 system_service->drive_service()->operation_registry()->RemoveObserver(this); |
117 } | 117 } |
118 | 118 |
119 chromeos::NetworkLibrary* network_library = | 119 chromeos::NetworkLibrary* network_library = |
120 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 120 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
121 if (network_library) | 121 if (network_library) |
122 network_library->RemoveNetworkManagerObserver(this); | 122 network_library->RemoveNetworkManagerObserver(this); |
123 | 123 |
124 profile_ = NULL; | 124 profile_ = NULL; |
125 } | 125 } |
126 | 126 |
127 void FileBrowserEventRouter::ObserveFileSystemEvents() { | 127 void FileBrowserEventRouter::ObserveFileSystemEvents() { |
128 if (!profile_) { | 128 if (!profile_) { |
129 NOTREACHED(); | 129 NOTREACHED(); |
130 return; | 130 return; |
131 } | 131 } |
132 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) | 132 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) |
133 return; | 133 return; |
134 | 134 |
135 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 135 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
136 disk_mount_manager->RemoveObserver(this); | 136 disk_mount_manager->RemoveObserver(this); |
137 disk_mount_manager->AddObserver(this); | 137 disk_mount_manager->AddObserver(this); |
138 disk_mount_manager->RequestMountInfoRefresh(); | 138 disk_mount_manager->RequestMountInfoRefresh(); |
139 | 139 |
140 GDataSystemService* system_service = | 140 DriveSystemService* system_service = |
141 GDataSystemServiceFactory::GetForProfile(profile_); | 141 DriveSystemServiceFactory::GetForProfile(profile_); |
142 if (!system_service) { | 142 if (!system_service) { |
143 NOTREACHED(); | 143 NOTREACHED(); |
144 return; | 144 return; |
145 } | 145 } |
146 system_service->drive_service()->operation_registry()->AddObserver(this); | 146 system_service->drive_service()->operation_registry()->AddObserver(this); |
147 system_service->file_system()->AddObserver(this); | 147 system_service->file_system()->AddObserver(this); |
148 | 148 |
149 chromeos::NetworkLibrary* network_library = | 149 chromeos::NetworkLibrary* network_library = |
150 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); | 150 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
151 if (network_library) | 151 if (network_library) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 if (iter->second->GetRefCount() == 0) { | 222 if (iter->second->GetRefCount() == 0) { |
223 delete iter->second; | 223 delete iter->second; |
224 file_watchers_.erase(iter); | 224 file_watchers_.erase(iter); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 void FileBrowserEventRouter::MountDrive( | 228 void FileBrowserEventRouter::MountDrive( |
229 const base::Closure& callback) { | 229 const base::Closure& callback) { |
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
231 | 231 |
232 gdata::GDataSystemService* system_service = | 232 DriveSystemService* system_service = |
233 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 233 DriveSystemServiceFactory::GetForProfile(profile_); |
234 if (system_service) { | 234 if (system_service) { |
235 system_service->drive_service()->Authenticate( | 235 system_service->drive_service()->Authenticate( |
236 base::Bind(&FileBrowserEventRouter::OnAuthenticated, | 236 base::Bind(&FileBrowserEventRouter::OnAuthenticated, |
237 this, | 237 this, |
238 callback)); | 238 callback)); |
239 } | 239 } |
240 } | 240 } |
241 | 241 |
242 void FileBrowserEventRouter::OnAuthenticated( | 242 void FileBrowserEventRouter::OnAuthenticated( |
243 const base::Closure& callback, | 243 const base::Closure& callback, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 notifications_->ManageNotificationsOnMountCompleted( | 347 notifications_->ManageNotificationsOnMountCompleted( |
348 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), | 348 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), |
349 error_code == chromeos::MOUNT_ERROR_NONE, | 349 error_code == chromeos::MOUNT_ERROR_NONE, |
350 error_code == chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM); | 350 error_code == chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM); |
351 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | 351 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { |
352 // Clear the "mounted" state for archive files in gdata cache | 352 // Clear the "mounted" state for archive files in gdata cache |
353 // when mounting failed or unmounting succeeded. | 353 // when mounting failed or unmounting succeeded. |
354 if ((event_type == DiskMountManager::MOUNTING) != | 354 if ((event_type == DiskMountManager::MOUNTING) != |
355 (error_code == chromeos::MOUNT_ERROR_NONE)) { | 355 (error_code == chromeos::MOUNT_ERROR_NONE)) { |
356 FilePath source_path(mount_info.source_path); | 356 FilePath source_path(mount_info.source_path); |
357 gdata::GDataSystemService* system_service = | 357 DriveSystemService* system_service = |
358 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 358 DriveSystemServiceFactory::GetForProfile(profile_); |
359 gdata::DriveCache* cache = | 359 gdata::DriveCache* cache = |
360 system_service ? system_service->cache() : NULL; | 360 system_service ? system_service->cache() : NULL; |
361 if (cache) { | 361 if (cache) { |
362 cache->SetMountedStateOnUIThread( | 362 cache->SetMountedStateOnUIThread( |
363 source_path, false, gdata::ChangeCacheStateCallback()); | 363 source_path, false, gdata::ChangeCacheStateCallback()); |
364 } | 364 } |
365 } | 365 } |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 } | 813 } |
814 | 814 |
815 const FilePath& | 815 const FilePath& |
816 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { | 816 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { |
817 return virtual_path_; | 817 return virtual_path_; |
818 } | 818 } |
819 | 819 |
820 gdata::DriveFileSystemInterface* | 820 gdata::DriveFileSystemInterface* |
821 FileBrowserEventRouter::GetRemoteFileSystem() const { | 821 FileBrowserEventRouter::GetRemoteFileSystem() const { |
822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
823 gdata::GDataSystemService* system_service = | 823 DriveSystemService* system_service = |
824 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 824 DriveSystemServiceFactory::GetForProfile(profile_); |
825 return (system_service ? system_service->file_system() : NULL); | 825 return (system_service ? system_service->file_system() : NULL); |
826 } | 826 } |
827 | 827 |
828 bool FileBrowserEventRouter::FileWatcherExtensions::Watch | 828 bool FileBrowserEventRouter::FileWatcherExtensions::Watch |
829 (const FilePath& path, FileWatcherDelegate* delegate) { | 829 (const FilePath& path, FileWatcherDelegate* delegate) { |
830 if (is_remote_file_system_) | 830 if (is_remote_file_system_) |
831 return true; | 831 return true; |
832 | 832 |
833 return file_watcher_->Watch(path, delegate); | 833 return file_watcher_->Watch(path, delegate); |
834 } | 834 } |
835 | 835 |
836 // static | 836 // static |
837 scoped_refptr<FileBrowserEventRouter> | 837 scoped_refptr<FileBrowserEventRouter> |
838 FileBrowserEventRouterFactory::GetForProfile(Profile* profile) { | 838 FileBrowserEventRouterFactory::GetForProfile(Profile* profile) { |
839 return static_cast<FileBrowserEventRouter*>( | 839 return static_cast<FileBrowserEventRouter*>( |
840 GetInstance()->GetServiceForProfile(profile, true).get()); | 840 GetInstance()->GetServiceForProfile(profile, true).get()); |
841 } | 841 } |
842 | 842 |
843 // static | 843 // static |
844 FileBrowserEventRouterFactory* | 844 FileBrowserEventRouterFactory* |
845 FileBrowserEventRouterFactory::GetInstance() { | 845 FileBrowserEventRouterFactory::GetInstance() { |
846 return Singleton<FileBrowserEventRouterFactory>::get(); | 846 return Singleton<FileBrowserEventRouterFactory>::get(); |
847 } | 847 } |
848 | 848 |
849 FileBrowserEventRouterFactory::FileBrowserEventRouterFactory() | 849 FileBrowserEventRouterFactory::FileBrowserEventRouterFactory() |
850 : RefcountedProfileKeyedServiceFactory("FileBrowserEventRouter", | 850 : RefcountedProfileKeyedServiceFactory("FileBrowserEventRouter", |
851 ProfileDependencyManager::GetInstance()) { | 851 ProfileDependencyManager::GetInstance()) { |
852 DependsOn(GDataSystemServiceFactory::GetInstance()); | 852 DependsOn(DriveSystemServiceFactory::GetInstance()); |
853 } | 853 } |
854 | 854 |
855 FileBrowserEventRouterFactory::~FileBrowserEventRouterFactory() { | 855 FileBrowserEventRouterFactory::~FileBrowserEventRouterFactory() { |
856 } | 856 } |
857 | 857 |
858 scoped_refptr<RefcountedProfileKeyedService> | 858 scoped_refptr<RefcountedProfileKeyedService> |
859 FileBrowserEventRouterFactory::BuildServiceInstanceFor(Profile* profile) const { | 859 FileBrowserEventRouterFactory::BuildServiceInstanceFor(Profile* profile) const { |
860 return scoped_refptr<RefcountedProfileKeyedService>( | 860 return scoped_refptr<RefcountedProfileKeyedService>( |
861 new FileBrowserEventRouter(profile)); | 861 new FileBrowserEventRouter(profile)); |
862 } | 862 } |
863 | 863 |
864 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 864 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
865 // Explicitly and always allow this router in guest login mode. see | 865 // Explicitly and always allow this router in guest login mode. see |
866 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 866 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
867 // for the details. | 867 // for the details. |
868 return true; | 868 return true; |
869 } | 869 } |
OLD | NEW |