| 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/gdata/gdata_system_service.h" | 5 #include "chrome/browser/chromeos/gdata/drive_system_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chromeos/gdata/drive_api_service.h" | 10 #include "chrome/browser/chromeos/gdata/drive_api_service.h" |
| 11 #include "chrome/browser/chromeos/gdata/drive_file_system.h" | 11 #include "chrome/browser/chromeos/gdata/drive_file_system.h" |
| 12 #include "chrome/browser/chromeos/gdata/drive_file_system_proxy.h" | 12 #include "chrome/browser/chromeos/gdata/drive_file_system_proxy.h" |
| 13 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 13 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| 14 #include "chrome/browser/chromeos/gdata/file_write_helper.h" | 14 #include "chrome/browser/chromeos/gdata/file_write_helper.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace gdata { | 32 namespace gdata { |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Used in test to setup system service. | 35 // Used in test to setup system service. |
| 36 DriveServiceInterface* g_test_drive_service = NULL; | 36 DriveServiceInterface* g_test_drive_service = NULL; |
| 37 const std::string* g_test_cache_root = NULL; | 37 const std::string* g_test_cache_root = NULL; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 GDataSystemService::GDataSystemService(Profile* profile) | 41 DriveSystemService::DriveSystemService(Profile* profile) |
| 42 : profile_(profile), | 42 : profile_(profile), |
| 43 cache_(NULL), | 43 cache_(NULL), |
| 44 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 44 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 46 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 46 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
| 47 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( | 47 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( |
| 48 blocking_pool->GetSequenceToken()); | 48 blocking_pool->GetSequenceToken()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 GDataSystemService::~GDataSystemService() { | 51 DriveSystemService::~DriveSystemService() { |
| 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 53 cache_->DestroyOnUIThread(); | 53 cache_->DestroyOnUIThread(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void GDataSystemService::Initialize( | 56 void DriveSystemService::Initialize( |
| 57 DriveServiceInterface* drive_service, | 57 DriveServiceInterface* drive_service, |
| 58 const FilePath& cache_root) { | 58 const FilePath& cache_root) { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 60 | 60 |
| 61 drive_service_.reset(drive_service); | 61 drive_service_.reset(drive_service); |
| 62 cache_ = DriveCache::CreateDriveCacheOnUIThread( | 62 cache_ = DriveCache::CreateDriveCacheOnUIThread( |
| 63 cache_root, | 63 cache_root, |
| 64 blocking_task_runner_); | 64 blocking_task_runner_); |
| 65 uploader_.reset(new GDataUploader(drive_service_.get())); | 65 uploader_.reset(new GDataUploader(drive_service_.get())); |
| 66 webapps_registry_.reset(new DriveWebAppsRegistry); | 66 webapps_registry_.reset(new DriveWebAppsRegistry); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 83 g_browser_process->download_status_updater() ? | 83 g_browser_process->download_status_updater() ? |
| 84 BrowserContext::GetDownloadManager(profile_) : NULL; | 84 BrowserContext::GetDownloadManager(profile_) : NULL; |
| 85 download_observer_->Initialize( | 85 download_observer_->Initialize( |
| 86 download_manager, | 86 download_manager, |
| 87 cache_->GetCacheDirectoryPath( | 87 cache_->GetCacheDirectoryPath( |
| 88 DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); | 88 DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); |
| 89 | 89 |
| 90 AddDriveMountPoint(); | 90 AddDriveMountPoint(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void GDataSystemService::Shutdown() { | 93 void DriveSystemService::Shutdown() { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 95 RemoveDriveMountPoint(); | 95 RemoveDriveMountPoint(); |
| 96 | 96 |
| 97 // Shut down the member objects in the reverse order of creation. | 97 // Shut down the member objects in the reverse order of creation. |
| 98 sync_client_.reset(); | 98 sync_client_.reset(); |
| 99 download_observer_.reset(); | 99 download_observer_.reset(); |
| 100 file_write_helper_.reset(); | 100 file_write_helper_.reset(); |
| 101 file_system_.reset(); | 101 file_system_.reset(); |
| 102 webapps_registry_.reset(); | 102 webapps_registry_.reset(); |
| 103 uploader_.reset(); | 103 uploader_.reset(); |
| 104 drive_service_.reset(); | 104 drive_service_.reset(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void GDataSystemService::ClearCacheAndRemountFileSystem( | 107 void DriveSystemService::ClearCacheAndRemountFileSystem( |
| 108 const base::Callback<void(bool)>& callback) { | 108 const base::Callback<void(bool)>& callback) { |
| 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 110 | 110 |
| 111 RemoveDriveMountPoint(); | 111 RemoveDriveMountPoint(); |
| 112 drive_service()->CancelAll(); | 112 drive_service()->CancelAll(); |
| 113 cache_->ClearAllOnUIThread( | 113 cache_->ClearAllOnUIThread( |
| 114 base::Bind(&GDataSystemService::AddBackDriveMountPoint, | 114 base::Bind(&DriveSystemService::AddBackDriveMountPoint, |
| 115 weak_ptr_factory_.GetWeakPtr(), | 115 weak_ptr_factory_.GetWeakPtr(), |
| 116 callback)); | 116 callback)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void GDataSystemService::AddBackDriveMountPoint( | 119 void DriveSystemService::AddBackDriveMountPoint( |
| 120 const base::Callback<void(bool)>& callback, | 120 const base::Callback<void(bool)>& callback, |
| 121 DriveFileError error, | 121 DriveFileError error, |
| 122 const FilePath& file_path) { | 122 const FilePath& file_path) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 | 124 |
| 125 AddDriveMountPoint(); | 125 AddDriveMountPoint(); |
| 126 | 126 |
| 127 if (!callback.is_null()) | 127 if (!callback.is_null()) |
| 128 callback.Run(error == DRIVE_FILE_OK); | 128 callback.Run(error == DRIVE_FILE_OK); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void GDataSystemService::AddDriveMountPoint() { | 131 void DriveSystemService::AddDriveMountPoint() { |
| 132 if (!gdata::util::IsGDataAvailable(profile_)) | 132 if (!gdata::util::IsGDataAvailable(profile_)) |
| 133 return; | 133 return; |
| 134 | 134 |
| 135 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); | 135 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); |
| 136 fileapi::ExternalFileSystemMountPointProvider* provider = | 136 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 137 BrowserContext::GetFileSystemContext(profile_)->external_provider(); | 137 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
| 138 if (provider && !provider->HasMountPoint(mount_point)) { | 138 if (provider && !provider->HasMountPoint(mount_point)) { |
| 139 provider->AddRemoteMountPoint( | 139 provider->AddRemoteMountPoint( |
| 140 mount_point, | 140 mount_point, |
| 141 new DriveFileSystemProxy(file_system_.get())); | 141 new DriveFileSystemProxy(file_system_.get())); |
| 142 } | 142 } |
| 143 | 143 |
| 144 file_system_->Initialize(); | 144 file_system_->Initialize(); |
| 145 file_system_->NotifyFileSystemMounted(); | 145 file_system_->NotifyFileSystemMounted(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 void GDataSystemService::RemoveDriveMountPoint() { | 148 void DriveSystemService::RemoveDriveMountPoint() { |
| 149 file_system_->NotifyFileSystemToBeUnmounted(); | 149 file_system_->NotifyFileSystemToBeUnmounted(); |
| 150 file_system_->StopUpdates(); | 150 file_system_->StopUpdates(); |
| 151 | 151 |
| 152 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); | 152 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); |
| 153 fileapi::ExternalFileSystemMountPointProvider* provider = | 153 fileapi::ExternalFileSystemMountPointProvider* provider = |
| 154 BrowserContext::GetFileSystemContext(profile_)->external_provider(); | 154 BrowserContext::GetFileSystemContext(profile_)->external_provider(); |
| 155 if (provider && provider->HasMountPoint(mount_point)) | 155 if (provider && provider->HasMountPoint(mount_point)) |
| 156 provider->RemoveMountPoint(mount_point); | 156 provider->RemoveMountPoint(mount_point); |
| 157 } | 157 } |
| 158 | 158 |
| 159 //===================== GDataSystemServiceFactory ============================= | 159 //===================== DriveSystemServiceFactory ============================= |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 GDataSystemService* GDataSystemServiceFactory::GetForProfile( | 162 DriveSystemService* DriveSystemServiceFactory::GetForProfile( |
| 163 Profile* profile) { | 163 Profile* profile) { |
| 164 return static_cast<GDataSystemService*>( | 164 return static_cast<DriveSystemService*>( |
| 165 GetInstance()->GetServiceForProfile(profile, true)); | 165 GetInstance()->GetServiceForProfile(profile, true)); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // static | 168 // static |
| 169 GDataSystemService* GDataSystemServiceFactory::FindForProfile( | 169 DriveSystemService* DriveSystemServiceFactory::FindForProfile( |
| 170 Profile* profile) { | 170 Profile* profile) { |
| 171 return static_cast<GDataSystemService*>( | 171 return static_cast<DriveSystemService*>( |
| 172 GetInstance()->GetServiceForProfile(profile, false)); | 172 GetInstance()->GetServiceForProfile(profile, false)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 // static | 175 // static |
| 176 GDataSystemServiceFactory* GDataSystemServiceFactory::GetInstance() { | 176 DriveSystemServiceFactory* DriveSystemServiceFactory::GetInstance() { |
| 177 return Singleton<GDataSystemServiceFactory>::get(); | 177 return Singleton<DriveSystemServiceFactory>::get(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 GDataSystemServiceFactory::GDataSystemServiceFactory() | 180 DriveSystemServiceFactory::DriveSystemServiceFactory() |
| 181 : ProfileKeyedServiceFactory("GDataSystemService", | 181 : ProfileKeyedServiceFactory("DriveSystemService", |
| 182 ProfileDependencyManager::GetInstance()) { | 182 ProfileDependencyManager::GetInstance()) { |
| 183 DependsOn(DownloadServiceFactory::GetInstance()); | 183 DependsOn(DownloadServiceFactory::GetInstance()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 GDataSystemServiceFactory::~GDataSystemServiceFactory() { | 186 DriveSystemServiceFactory::~DriveSystemServiceFactory() { |
| 187 } | 187 } |
| 188 | 188 |
| 189 // static | 189 // static |
| 190 void GDataSystemServiceFactory::set_drive_service_for_test( | 190 void DriveSystemServiceFactory::set_drive_service_for_test( |
| 191 DriveServiceInterface* drive_service) { | 191 DriveServiceInterface* drive_service) { |
| 192 if (g_test_drive_service) | 192 if (g_test_drive_service) |
| 193 delete g_test_drive_service; | 193 delete g_test_drive_service; |
| 194 g_test_drive_service = drive_service; | 194 g_test_drive_service = drive_service; |
| 195 } | 195 } |
| 196 | 196 |
| 197 // static | 197 // static |
| 198 void GDataSystemServiceFactory::set_cache_root_for_test( | 198 void DriveSystemServiceFactory::set_cache_root_for_test( |
| 199 const std::string& cache_root) { | 199 const std::string& cache_root) { |
| 200 if (g_test_cache_root) | 200 if (g_test_cache_root) |
| 201 delete g_test_cache_root; | 201 delete g_test_cache_root; |
| 202 g_test_cache_root = !cache_root.empty() ? new std::string(cache_root) : NULL; | 202 g_test_cache_root = !cache_root.empty() ? new std::string(cache_root) : NULL; |
| 203 } | 203 } |
| 204 | 204 |
| 205 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( | 205 ProfileKeyedService* DriveSystemServiceFactory::BuildServiceInstanceFor( |
| 206 Profile* profile) const { | 206 Profile* profile) const { |
| 207 GDataSystemService* service = new GDataSystemService(profile); | 207 DriveSystemService* service = new DriveSystemService(profile); |
| 208 | 208 |
| 209 DriveServiceInterface* drive_service = g_test_drive_service; | 209 DriveServiceInterface* drive_service = g_test_drive_service; |
| 210 g_test_drive_service = NULL; | 210 g_test_drive_service = NULL; |
| 211 if (!drive_service) { | 211 if (!drive_service) { |
| 212 if (util::IsDriveV2ApiEnabled()) | 212 if (util::IsDriveV2ApiEnabled()) |
| 213 drive_service = new DriveAPIService(); | 213 drive_service = new DriveAPIService(); |
| 214 else | 214 else |
| 215 drive_service = new GDataWapiService(); | 215 drive_service = new GDataWapiService(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 FilePath cache_root = | 218 FilePath cache_root = |
| 219 g_test_cache_root ? FilePath(*g_test_cache_root) : | 219 g_test_cache_root ? FilePath(*g_test_cache_root) : |
| 220 DriveCache::GetCacheRootPath(profile); | 220 DriveCache::GetCacheRootPath(profile); |
| 221 delete g_test_cache_root; | 221 delete g_test_cache_root; |
| 222 g_test_cache_root = NULL; | 222 g_test_cache_root = NULL; |
| 223 | 223 |
| 224 service->Initialize(drive_service, cache_root); | 224 service->Initialize(drive_service, cache_root); |
| 225 return service; | 225 return service; |
| 226 } | 226 } |
| 227 | 227 |
| 228 } // namespace gdata | 228 } // namespace gdata |
| OLD | NEW |