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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 cache_(NULL) { | 46 cache_(NULL) { |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
48 } | 48 } |
49 | 49 |
50 GDataSystemService::~GDataSystemService() { | 50 GDataSystemService::~GDataSystemService() { |
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
52 cache_->DestroyOnUIThread(); | 52 cache_->DestroyOnUIThread(); |
53 } | 53 } |
54 | 54 |
55 void GDataSystemService::Initialize( | 55 void GDataSystemService::Initialize( |
56 DocumentsServiceInterface* documents_service) { | 56 DocumentsServiceInterface* documents_service, |
| 57 const FilePath& cache_root) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 59 |
59 documents_service_.reset(documents_service); | 60 documents_service_.reset(documents_service); |
60 cache_ = GDataCache::CreateGDataCacheOnUIThread( | 61 cache_ = GDataCache::CreateGDataCacheOnUIThread( |
61 GDataCache::GetCacheRootPath(profile_), | 62 cache_root, |
62 GetTaskRunner(sequence_token_)); | 63 GetTaskRunner(sequence_token_)); |
63 uploader_.reset(new GDataUploader(docs_service())); | 64 uploader_.reset(new GDataUploader(docs_service())); |
64 webapps_registry_.reset(new DriveWebAppsRegistry); | 65 webapps_registry_.reset(new DriveWebAppsRegistry); |
65 file_system_.reset(new GDataFileSystem(profile_, | 66 file_system_.reset(new GDataFileSystem(profile_, |
66 cache(), | 67 cache(), |
67 docs_service(), | 68 docs_service(), |
68 uploader(), | 69 uploader(), |
69 webapps_registry(), | 70 webapps_registry(), |
70 GetTaskRunner(sequence_token_))); | 71 GetTaskRunner(sequence_token_))); |
71 download_observer_.reset(new GDataDownloadObserver(uploader(), | 72 download_observer_.reset(new GDataDownloadObserver(uploader(), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 GDataSystemServiceFactory::GDataSystemServiceFactory() | 147 GDataSystemServiceFactory::GDataSystemServiceFactory() |
147 : ProfileKeyedServiceFactory("GDataSystemService", | 148 : ProfileKeyedServiceFactory("GDataSystemService", |
148 ProfileDependencyManager::GetInstance()) { | 149 ProfileDependencyManager::GetInstance()) { |
149 DependsOn(DownloadServiceFactory::GetInstance()); | 150 DependsOn(DownloadServiceFactory::GetInstance()); |
150 } | 151 } |
151 | 152 |
152 GDataSystemServiceFactory::~GDataSystemServiceFactory() { | 153 GDataSystemServiceFactory::~GDataSystemServiceFactory() { |
153 } | 154 } |
154 | 155 |
155 // static | 156 // static |
156 ProfileKeyedService* GDataSystemServiceFactory::CreateInstance( | 157 void GDataSystemServiceFactory::set_documents_service_for_test( |
157 Profile* profile) { | 158 DocumentsServiceInterface* documents_service) { |
158 return new GDataSystemService(profile); | 159 if (test_documents_service_) |
| 160 delete test_documents_service_; |
| 161 test_documents_service_ = documents_service; |
159 } | 162 } |
160 | 163 |
161 GDataSystemService* | 164 // static |
162 GDataSystemServiceFactory::GetWithCustomDocumentsServiceForTesting( | 165 void GDataSystemServiceFactory::set_cache_root_for_test( |
163 Profile* profile, | 166 const char* cache_root) { |
164 DocumentsServiceInterface* documents_service) { | 167 test_cache_root_ = cache_root; |
165 GDataSystemService* service = | |
166 static_cast<GDataSystemService*>(GetInstance()->SetTestingFactoryAndUse( | |
167 profile, | |
168 &GDataSystemServiceFactory::CreateInstance)); | |
169 service->Initialize(documents_service); | |
170 return service; | |
171 } | 168 } |
172 | 169 |
173 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( | 170 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( |
174 Profile* profile) const { | 171 Profile* profile) const { |
175 GDataSystemService* service = new GDataSystemService(profile); | 172 GDataSystemService* service = new GDataSystemService(profile); |
176 service->Initialize(new DocumentsService); | 173 |
| 174 DocumentsServiceInterface* documents_service = |
| 175 test_documents_service_ ? test_documents_service_ : |
| 176 new DocumentsService(); |
| 177 test_documents_service_ = NULL; |
| 178 FilePath cache_root = |
| 179 test_cache_root_ ? FilePath(test_cache_root_) : |
| 180 GDataCache::GetCacheRootPath(profile); |
| 181 |
| 182 service->Initialize(documents_service, cache_root); |
177 return service; | 183 return service; |
178 } | 184 } |
179 | 185 |
| 186 // static |
| 187 DocumentsServiceInterface* GDataSystemServiceFactory::test_documents_service_ = |
| 188 NULL; |
| 189 |
| 190 // static |
| 191 const char* GDataSystemServiceFactory::test_cache_root_ = NULL; |
| 192 |
180 } // namespace gdata | 193 } // namespace gdata |
OLD | NEW |