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_api_service.h" | 10 #include "chrome/browser/chromeos/gdata/drive_api_service.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "webkit/fileapi/file_system_context.h" | 27 #include "webkit/fileapi/file_system_context.h" |
28 #include "webkit/fileapi/file_system_mount_point_provider.h" | 28 #include "webkit/fileapi/file_system_mount_point_provider.h" |
29 | 29 |
30 using content::BrowserContext; | 30 using content::BrowserContext; |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
32 | 32 |
33 namespace gdata { | 33 namespace gdata { |
34 namespace { | 34 namespace { |
35 | 35 |
36 // Used in test to setup system service. | 36 // Used in test to setup system service. |
37 DocumentsServiceInterface* g_test_documents_service = NULL; | 37 DriveServiceInterface* g_test_drive_service = NULL; |
38 const std::string* g_test_cache_root = NULL; | 38 const std::string* g_test_cache_root = NULL; |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 GDataSystemService::GDataSystemService(Profile* profile) | 42 GDataSystemService::GDataSystemService(Profile* profile) |
43 : profile_(profile), | 43 : profile_(profile), |
44 cache_(NULL), | 44 cache_(NULL), |
45 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 45 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
47 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 47 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
48 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( | 48 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( |
49 blocking_pool->GetSequenceToken()); | 49 blocking_pool->GetSequenceToken()); |
50 } | 50 } |
51 | 51 |
52 GDataSystemService::~GDataSystemService() { | 52 GDataSystemService::~GDataSystemService() { |
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
54 cache_->DestroyOnUIThread(); | 54 cache_->DestroyOnUIThread(); |
55 } | 55 } |
56 | 56 |
57 void GDataSystemService::Initialize( | 57 void GDataSystemService::Initialize( |
58 DocumentsServiceInterface* documents_service, | 58 DriveServiceInterface* drive_service, |
59 const FilePath& cache_root) { | 59 const FilePath& cache_root) { |
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
61 | 61 |
62 documents_service_.reset(documents_service); | 62 drive_service_.reset(drive_service); |
63 cache_ = GDataCache::CreateGDataCacheOnUIThread( | 63 cache_ = GDataCache::CreateGDataCacheOnUIThread( |
64 cache_root, | 64 cache_root, |
65 blocking_task_runner_); | 65 blocking_task_runner_); |
66 uploader_.reset(new GDataUploader(docs_service())); | 66 uploader_.reset(new GDataUploader(drive_service_.get())); |
67 webapps_registry_.reset(new DriveWebAppsRegistry); | 67 webapps_registry_.reset(new DriveWebAppsRegistry); |
68 file_system_.reset(new GDataFileSystem(profile_, | 68 file_system_.reset(new GDataFileSystem(profile_, |
69 cache(), | 69 cache(), |
70 docs_service(), | 70 drive_service_.get(), |
71 uploader(), | 71 uploader(), |
72 webapps_registry(), | 72 webapps_registry(), |
73 blocking_task_runner_)); | 73 blocking_task_runner_)); |
74 file_write_helper_.reset(new FileWriteHelper(file_system())); | 74 file_write_helper_.reset(new FileWriteHelper(file_system())); |
75 download_observer_.reset(new GDataDownloadObserver(uploader(), | 75 download_observer_.reset(new GDataDownloadObserver(uploader(), |
76 file_system())); | 76 file_system())); |
77 sync_client_.reset(new GDataSyncClient(profile_, file_system(), cache())); | 77 sync_client_.reset(new GDataSyncClient(profile_, file_system(), cache())); |
78 contacts_service_.reset(new GDataContactsService(profile_)); | 78 contacts_service_.reset(new GDataContactsService(profile_)); |
79 | 79 |
80 sync_client_->Initialize(); | 80 sync_client_->Initialize(); |
(...skipping 17 matching lines...) Expand all Loading... |
98 RemoveDriveMountPoint(); | 98 RemoveDriveMountPoint(); |
99 | 99 |
100 // Shut down the member objects in the reverse order of creation. | 100 // Shut down the member objects in the reverse order of creation. |
101 contacts_service_.reset(); | 101 contacts_service_.reset(); |
102 sync_client_.reset(); | 102 sync_client_.reset(); |
103 download_observer_.reset(); | 103 download_observer_.reset(); |
104 file_write_helper_.reset(); | 104 file_write_helper_.reset(); |
105 file_system_.reset(); | 105 file_system_.reset(); |
106 webapps_registry_.reset(); | 106 webapps_registry_.reset(); |
107 uploader_.reset(); | 107 uploader_.reset(); |
108 documents_service_.reset(); | 108 drive_service_.reset(); |
109 } | 109 } |
110 | 110 |
111 void GDataSystemService::ClearCacheAndRemountFileSystem( | 111 void GDataSystemService::ClearCacheAndRemountFileSystem( |
112 const base::Callback<void(bool)>& callback) { | 112 const base::Callback<void(bool)>& callback) { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
114 | 114 |
115 RemoveDriveMountPoint(); | 115 RemoveDriveMountPoint(); |
116 docs_service()->CancelAll(); | 116 drive_service()->CancelAll(); |
117 cache_->ClearAllOnUIThread( | 117 cache_->ClearAllOnUIThread( |
118 base::Bind(&GDataSystemService::AddBackDriveMountPoint, | 118 base::Bind(&GDataSystemService::AddBackDriveMountPoint, |
119 weak_ptr_factory_.GetWeakPtr(), | 119 weak_ptr_factory_.GetWeakPtr(), |
120 callback)); | 120 callback)); |
121 } | 121 } |
122 | 122 |
123 void GDataSystemService::AddBackDriveMountPoint( | 123 void GDataSystemService::AddBackDriveMountPoint( |
124 const base::Callback<void(bool)>& callback, | 124 const base::Callback<void(bool)>& callback, |
125 GDataFileError error, | 125 GDataFileError error, |
126 const FilePath& file_path) { | 126 const FilePath& file_path) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 GDataSystemServiceFactory::GDataSystemServiceFactory() | 184 GDataSystemServiceFactory::GDataSystemServiceFactory() |
185 : ProfileKeyedServiceFactory("GDataSystemService", | 185 : ProfileKeyedServiceFactory("GDataSystemService", |
186 ProfileDependencyManager::GetInstance()) { | 186 ProfileDependencyManager::GetInstance()) { |
187 DependsOn(DownloadServiceFactory::GetInstance()); | 187 DependsOn(DownloadServiceFactory::GetInstance()); |
188 } | 188 } |
189 | 189 |
190 GDataSystemServiceFactory::~GDataSystemServiceFactory() { | 190 GDataSystemServiceFactory::~GDataSystemServiceFactory() { |
191 } | 191 } |
192 | 192 |
193 // static | 193 // static |
194 void GDataSystemServiceFactory::set_documents_service_for_test( | 194 void GDataSystemServiceFactory::set_drive_service_for_test( |
195 DocumentsServiceInterface* documents_service) { | 195 DriveServiceInterface* drive_service) { |
196 if (g_test_documents_service) | 196 if (g_test_drive_service) |
197 delete g_test_documents_service; | 197 delete g_test_drive_service; |
198 g_test_documents_service = documents_service; | 198 g_test_drive_service = drive_service; |
199 } | 199 } |
200 | 200 |
201 // static | 201 // static |
202 void GDataSystemServiceFactory::set_cache_root_for_test( | 202 void GDataSystemServiceFactory::set_cache_root_for_test( |
203 const std::string& cache_root) { | 203 const std::string& cache_root) { |
204 if (g_test_cache_root) | 204 if (g_test_cache_root) |
205 delete g_test_cache_root; | 205 delete g_test_cache_root; |
206 g_test_cache_root = !cache_root.empty() ? new std::string(cache_root) : NULL; | 206 g_test_cache_root = !cache_root.empty() ? new std::string(cache_root) : NULL; |
207 } | 207 } |
208 | 208 |
209 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( | 209 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( |
210 Profile* profile) const { | 210 Profile* profile) const { |
211 GDataSystemService* service = new GDataSystemService(profile); | 211 GDataSystemService* service = new GDataSystemService(profile); |
212 | 212 |
213 DocumentsServiceInterface* documents_service = g_test_documents_service; | 213 DriveServiceInterface* drive_service = g_test_drive_service; |
214 g_test_documents_service = NULL; | 214 g_test_drive_service = NULL; |
215 if (!documents_service) { | 215 if (!drive_service) { |
216 if (util::IsDriveV2ApiEnabled()) | 216 if (util::IsDriveV2ApiEnabled()) |
217 documents_service = new DriveAPIService(); | 217 drive_service = new DriveAPIService(); |
218 else | 218 else |
219 documents_service = new GDataWapiService(); | 219 drive_service = new GDataWapiService(); |
220 } | 220 } |
221 | 221 |
222 FilePath cache_root = | 222 FilePath cache_root = |
223 g_test_cache_root ? FilePath(*g_test_cache_root) : | 223 g_test_cache_root ? FilePath(*g_test_cache_root) : |
224 GDataCache::GetCacheRootPath(profile); | 224 GDataCache::GetCacheRootPath(profile); |
225 delete g_test_cache_root; | 225 delete g_test_cache_root; |
226 g_test_cache_root = NULL; | 226 g_test_cache_root = NULL; |
227 | 227 |
228 service->Initialize(documents_service, cache_root); | 228 service->Initialize(drive_service, cache_root); |
229 return service; | 229 return service; |
230 } | 230 } |
231 | 231 |
232 } // namespace gdata | 232 } // namespace gdata |
OLD | NEW |