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/download/download_service.h" | 10 #include "chrome/browser/download/download_service.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 | 22 |
23 using content::BrowserContext; | 23 using content::BrowserContext; |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 | 25 |
26 namespace gdata { | 26 namespace gdata { |
27 | 27 |
28 //===================== GDataSystemService ==================================== | 28 //===================== GDataSystemService ==================================== |
29 GDataSystemService::GDataSystemService(Profile* profile) | 29 GDataSystemService::GDataSystemService(Profile* profile) |
30 : profile_(profile), | 30 : profile_(profile), |
| 31 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()), |
| 32 // TODO(hashimoto): Create cache_ on the blocking pool. crbug.com/131756 |
| 33 cache_( |
| 34 GDataCache::CreateGDataCache(GDataCache::GetCacheRootPath(profile_), |
| 35 BrowserThread::GetBlockingPool(), |
| 36 sequence_token_)), |
31 documents_service_(new DocumentsService), | 37 documents_service_(new DocumentsService), |
32 file_system_(new GDataFileSystem(profile, docs_service())), | 38 file_system_(new GDataFileSystem(profile, |
| 39 cache(), |
| 40 docs_service(), |
| 41 sequence_token_)), |
33 uploader_(new GDataUploader(file_system(), docs_service())), | 42 uploader_(new GDataUploader(file_system(), docs_service())), |
34 download_observer_(new GDataDownloadObserver), | 43 download_observer_(new GDataDownloadObserver), |
35 sync_client_(new GDataSyncClient(profile, file_system())), | 44 sync_client_(new GDataSyncClient(profile, file_system(), cache())), |
36 webapps_registry_(new DriveWebAppsRegistry) { | 45 webapps_registry_(new DriveWebAppsRegistry) { |
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
38 } | 47 } |
39 | 48 |
40 GDataSystemService::~GDataSystemService() { | 49 GDataSystemService::~GDataSystemService() { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(sequence_token_) |
| 52 ->PostTask( |
| 53 FROM_HERE, |
| 54 base::Bind(&base::DeletePointer<GDataCache>, cache_.release())); |
42 } | 55 } |
43 | 56 |
44 void GDataSystemService::Initialize() { | 57 void GDataSystemService::Initialize() { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
46 | 59 |
47 // This order is necessary so the sync_client_ doesn't miss | 60 // This order is necessary so the sync_client_ doesn't miss |
48 // OnCacheInitialized() notification. | 61 // OnCacheInitialized() notification. |
49 sync_client_->Initialize(); | 62 sync_client_->Initialize(); |
50 file_system_->Initialize(); | 63 file_system_->Initialize(); |
51 | 64 |
52 content::DownloadManager* download_manager = | 65 content::DownloadManager* download_manager = |
53 g_browser_process->download_status_updater() ? | 66 g_browser_process->download_status_updater() ? |
54 BrowserContext::GetDownloadManager(profile_) : NULL; | 67 BrowserContext::GetDownloadManager(profile_) : NULL; |
55 download_observer_->Initialize( | 68 download_observer_->Initialize( |
56 uploader_.get(), | 69 uploader_.get(), |
57 download_manager, | 70 download_manager, |
58 file_system_->GetCacheDirectoryPath( | 71 cache_->GetCacheDirectoryPath( |
59 GDataCache::CACHE_TYPE_TMP_DOWNLOADS)); | 72 GDataCache::CACHE_TYPE_TMP_DOWNLOADS)); |
60 } | 73 } |
61 | 74 |
62 void GDataSystemService::Shutdown() { | 75 void GDataSystemService::Shutdown() { |
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
64 | 77 |
65 // Shut down the member objects in the reverse order of creation. | 78 // Shut down the member objects in the reverse order of creation. |
66 webapps_registry_.reset(); | 79 webapps_registry_.reset(); |
67 sync_client_.reset(); | 80 sync_client_.reset(); |
68 download_observer_.reset(); | 81 download_observer_.reset(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 115 } |
103 | 116 |
104 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( | 117 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor( |
105 Profile* profile) const { | 118 Profile* profile) const { |
106 GDataSystemService* service = new GDataSystemService(profile); | 119 GDataSystemService* service = new GDataSystemService(profile); |
107 service->Initialize(); | 120 service->Initialize(); |
108 return service; | 121 return service; |
109 } | 122 } |
110 | 123 |
111 } // namespace gdata | 124 } // namespace gdata |
OLD | NEW |