Chromium Code Reviews| 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/gdata_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_webapps_registry.h" | 10 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "webkit/fileapi/file_system_context.h" | 24 #include "webkit/fileapi/file_system_context.h" |
| 25 #include "webkit/fileapi/file_system_mount_point_provider.h" | 25 #include "webkit/fileapi/file_system_mount_point_provider.h" |
| 26 | 26 |
| 27 using content::BrowserContext; | 27 using content::BrowserContext; |
| 28 using content::BrowserThread; | 28 using content::BrowserThread; |
| 29 | 29 |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 // Used in test to setup system service. | |
| 33 gdata::DocumentsServiceInterface* g_test_documents_service = NULL; | |
| 34 const std::string* g_test_cache_root = NULL; | |
| 35 | |
| 32 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner( | 36 scoped_refptr<base::SequencedTaskRunner> GetTaskRunner( |
| 33 const base::SequencedWorkerPool::SequenceToken& sequence_token) { | 37 const base::SequencedWorkerPool::SequenceToken& sequence_token) { |
| 34 return BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 38 return BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 35 sequence_token); | 39 sequence_token); |
| 36 } | 40 } |
| 37 | 41 |
| 38 } // nemaspace | 42 } // nemaspace |
| 39 | 43 |
| 40 namespace gdata { | 44 namespace gdata { |
| 41 | 45 |
| 42 //===================== GDataSystemService ==================================== | 46 //===================== GDataSystemService ==================================== |
| 43 GDataSystemService::GDataSystemService(Profile* profile) | 47 GDataSystemService::GDataSystemService(Profile* profile) |
| 44 : profile_(profile), | 48 : profile_(profile), |
| 45 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()), | 49 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()), |
| 46 cache_(NULL) { | 50 cache_(NULL) { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 48 } | 52 } |
| 49 | 53 |
| 50 GDataSystemService::~GDataSystemService() { | 54 GDataSystemService::~GDataSystemService() { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 52 cache_->DestroyOnUIThread(); | 56 cache_->DestroyOnUIThread(); |
| 53 } | 57 } |
| 54 | 58 |
| 55 void GDataSystemService::Initialize( | 59 void GDataSystemService::Initialize( |
| 56 DocumentsServiceInterface* documents_service) { | 60 DocumentsServiceInterface* documents_service, |
| 61 const FilePath& cache_root) { | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 | 63 |
| 59 documents_service_.reset(documents_service); | 64 documents_service_.reset(documents_service); |
| 60 cache_ = GDataCache::CreateGDataCacheOnUIThread( | 65 cache_ = GDataCache::CreateGDataCacheOnUIThread( |
| 61 GDataCache::GetCacheRootPath(profile_), | 66 cache_root, |
| 62 GetTaskRunner(sequence_token_)); | 67 GetTaskRunner(sequence_token_)); |
| 63 uploader_.reset(new GDataUploader(docs_service())); | 68 uploader_.reset(new GDataUploader(docs_service())); |
| 64 webapps_registry_.reset(new DriveWebAppsRegistry); | 69 webapps_registry_.reset(new DriveWebAppsRegistry); |
| 65 file_system_.reset(new GDataFileSystem(profile_, | 70 file_system_.reset(new GDataFileSystem(profile_, |
| 66 cache(), | 71 cache(), |
| 67 docs_service(), | 72 docs_service(), |
| 68 uploader(), | 73 uploader(), |
| 69 webapps_registry(), | 74 webapps_registry(), |
| 70 GetTaskRunner(sequence_token_))); | 75 GetTaskRunner(sequence_token_))); |
| 71 download_observer_.reset(new GDataDownloadObserver(uploader(), | 76 download_observer_.reset(new GDataDownloadObserver(uploader(), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 GDataSystemServiceFactory::GDataSystemServiceFactory() | 151 GDataSystemServiceFactory::GDataSystemServiceFactory() |
| 147 : ProfileKeyedServiceFactory("GDataSystemService", | 152 : ProfileKeyedServiceFactory("GDataSystemService", |
| 148 ProfileDependencyManager::GetInstance()) { | 153 ProfileDependencyManager::GetInstance()) { |
| 149 DependsOn(DownloadServiceFactory::GetInstance()); | 154 DependsOn(DownloadServiceFactory::GetInstance()); |
| 150 } | 155 } |
| 151 | 156 |
| 152 GDataSystemServiceFactory::~GDataSystemServiceFactory() { | 157 GDataSystemServiceFactory::~GDataSystemServiceFactory() { |
| 153 } | 158 } |
| 154 | 159 |
| 155 // static | 160 // static |
| 156 ProfileKeyedService* GDataSystemServiceFactory::CreateInstance( | 161 void GDataSystemServiceFactory::set_documents_service_for_test( |
| 157 Profile* profile) { | 162 DocumentsServiceInterface* documents_service) { |
| 158 return new GDataSystemService(profile); | 163 if (g_test_documents_service) |
| 164 delete g_test_documents_service; | |
| 165 g_test_documents_service = documents_service; | |
| 159 } | 166 } |
| 160 | 167 |
| 161 GDataSystemService* | 168 // static |
| 162 GDataSystemServiceFactory::GetWithCustomDocumentsServiceForTesting( | 169 void GDataSystemServiceFactory::set_cache_root_for_test( |
| 163 Profile* profile, | 170 const std::string& cache_root) { |
| 164 DocumentsServiceInterface* documents_service) { | 171 g_test_cache_root = &cache_root; |
|
satorux1
2012/07/21 06:49:13
this looks unsafe... It assumes that the caller ho
tbarzic
2012/07/23 19:38:20
yeah, Friday is the day for unsafe code :)
Done.
| |
| 165 GDataSystemService* service = | |
| 166 static_cast<GDataSystemService*>(GetInstance()->SetTestingFactoryAndUse( | |
| 167 profile, | |
| 168 &GDataSystemServiceFactory::CreateInstance)); | |
| 169 service->Initialize(documents_service); | |
| 170 return service; | |
| 171 } | 172 } |
| 172 | 173 |
| 173 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( | 174 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( |
| 174 Profile* profile) const { | 175 Profile* profile) const { |
| 175 GDataSystemService* service = new GDataSystemService(profile); | 176 GDataSystemService* service = new GDataSystemService(profile); |
| 176 service->Initialize(new DocumentsService); | 177 |
| 178 DocumentsServiceInterface* documents_service = | |
| 179 g_test_documents_service ? g_test_documents_service : | |
| 180 new DocumentsService(); | |
| 181 g_test_documents_service = NULL; | |
| 182 FilePath cache_root = | |
| 183 g_test_cache_root ? FilePath(*g_test_cache_root) : | |
| 184 GDataCache::GetCacheRootPath(profile); | |
| 185 | |
| 186 service->Initialize(documents_service, cache_root); | |
| 177 return service; | 187 return service; |
| 178 } | 188 } |
| 179 | 189 |
| 180 } // namespace gdata | 190 } // namespace gdata |
| OLD | NEW |