Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: chrome/browser/chromeos/gdata/drive_system_service.cc

Issue 10873026: Rename GDataSystemService to DriveSystemService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_contacts_service.h" 15 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h"
(...skipping 16 matching lines...) Expand all
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 DriveServiceInterface* g_test_drive_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 DriveSystemService::DriveSystemService(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 DriveSystemService::~DriveSystemService() {
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 DriveSystemService::Initialize(
58 DriveServiceInterface* drive_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 drive_service_.reset(drive_service); 62 drive_service_.reset(drive_service);
63 cache_ = DriveCache::CreateDriveCacheOnUIThread( 63 cache_ = DriveCache::CreateDriveCacheOnUIThread(
64 cache_root, 64 cache_root,
65 blocking_task_runner_); 65 blocking_task_runner_);
66 uploader_.reset(new GDataUploader(drive_service_.get())); 66 uploader_.reset(new GDataUploader(drive_service_.get()));
67 webapps_registry_.reset(new DriveWebAppsRegistry); 67 webapps_registry_.reset(new DriveWebAppsRegistry);
(...skipping 18 matching lines...) Expand all
86 BrowserContext::GetDownloadManager(profile_) : NULL; 86 BrowserContext::GetDownloadManager(profile_) : NULL;
87 download_observer_->Initialize( 87 download_observer_->Initialize(
88 download_manager, 88 download_manager,
89 cache_->GetCacheDirectoryPath( 89 cache_->GetCacheDirectoryPath(
90 DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); 90 DriveCache::CACHE_TYPE_TMP_DOWNLOADS));
91 91
92 AddDriveMountPoint(); 92 AddDriveMountPoint();
93 contacts_service_->Initialize(); 93 contacts_service_->Initialize();
94 } 94 }
95 95
96 void GDataSystemService::Shutdown() { 96 void DriveSystemService::Shutdown() {
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
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 drive_service_.reset(); 108 drive_service_.reset();
109 } 109 }
110 110
111 void GDataSystemService::ClearCacheAndRemountFileSystem( 111 void DriveSystemService::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 drive_service()->CancelAll(); 116 drive_service()->CancelAll();
117 cache_->ClearAllOnUIThread( 117 cache_->ClearAllOnUIThread(
118 base::Bind(&GDataSystemService::AddBackDriveMountPoint, 118 base::Bind(&DriveSystemService::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 DriveSystemService::AddBackDriveMountPoint(
124 const base::Callback<void(bool)>& callback, 124 const base::Callback<void(bool)>& callback,
125 DriveFileError error, 125 DriveFileError error,
126 const FilePath& file_path) { 126 const FilePath& file_path) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 128
129 AddDriveMountPoint(); 129 AddDriveMountPoint();
130 130
131 if (!callback.is_null()) 131 if (!callback.is_null())
132 callback.Run(error == DRIVE_FILE_OK); 132 callback.Run(error == DRIVE_FILE_OK);
133 } 133 }
134 134
135 void GDataSystemService::AddDriveMountPoint() { 135 void DriveSystemService::AddDriveMountPoint() {
136 if (!gdata::util::IsGDataAvailable(profile_)) 136 if (!gdata::util::IsGDataAvailable(profile_))
137 return; 137 return;
138 138
139 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); 139 const FilePath mount_point = gdata::util::GetGDataMountPointPath();
140 fileapi::ExternalFileSystemMountPointProvider* provider = 140 fileapi::ExternalFileSystemMountPointProvider* provider =
141 BrowserContext::GetFileSystemContext(profile_)->external_provider(); 141 BrowserContext::GetFileSystemContext(profile_)->external_provider();
142 if (provider && !provider->HasMountPoint(mount_point)) { 142 if (provider && !provider->HasMountPoint(mount_point)) {
143 provider->AddRemoteMountPoint( 143 provider->AddRemoteMountPoint(
144 mount_point, 144 mount_point,
145 new DriveFileSystemProxy(file_system_.get())); 145 new DriveFileSystemProxy(file_system_.get()));
146 } 146 }
147 147
148 file_system_->Initialize(); 148 file_system_->Initialize();
149 file_system_->NotifyFileSystemMounted(); 149 file_system_->NotifyFileSystemMounted();
150 } 150 }
151 151
152 void GDataSystemService::RemoveDriveMountPoint() { 152 void DriveSystemService::RemoveDriveMountPoint() {
153 file_system_->NotifyFileSystemToBeUnmounted(); 153 file_system_->NotifyFileSystemToBeUnmounted();
154 file_system_->StopUpdates(); 154 file_system_->StopUpdates();
155 155
156 const FilePath mount_point = gdata::util::GetGDataMountPointPath(); 156 const FilePath mount_point = gdata::util::GetGDataMountPointPath();
157 fileapi::ExternalFileSystemMountPointProvider* provider = 157 fileapi::ExternalFileSystemMountPointProvider* provider =
158 BrowserContext::GetFileSystemContext(profile_)->external_provider(); 158 BrowserContext::GetFileSystemContext(profile_)->external_provider();
159 if (provider && provider->HasMountPoint(mount_point)) 159 if (provider && provider->HasMountPoint(mount_point))
160 provider->RemoveMountPoint(mount_point); 160 provider->RemoveMountPoint(mount_point);
161 } 161 }
162 162
163 //===================== GDataSystemServiceFactory ============================= 163 //===================== DriveSystemServiceFactory =============================
164 164
165 // static 165 // static
166 GDataSystemService* GDataSystemServiceFactory::GetForProfile( 166 DriveSystemService* DriveSystemServiceFactory::GetForProfile(
167 Profile* profile) { 167 Profile* profile) {
168 return static_cast<GDataSystemService*>( 168 return static_cast<DriveSystemService*>(
169 GetInstance()->GetServiceForProfile(profile, true)); 169 GetInstance()->GetServiceForProfile(profile, true));
170 } 170 }
171 171
172 // static 172 // static
173 GDataSystemService* GDataSystemServiceFactory::FindForProfile( 173 DriveSystemService* DriveSystemServiceFactory::FindForProfile(
174 Profile* profile) { 174 Profile* profile) {
175 return static_cast<GDataSystemService*>( 175 return static_cast<DriveSystemService*>(
176 GetInstance()->GetServiceForProfile(profile, false)); 176 GetInstance()->GetServiceForProfile(profile, false));
177 } 177 }
178 178
179 // static 179 // static
180 GDataSystemServiceFactory* GDataSystemServiceFactory::GetInstance() { 180 DriveSystemServiceFactory* DriveSystemServiceFactory::GetInstance() {
181 return Singleton<GDataSystemServiceFactory>::get(); 181 return Singleton<DriveSystemServiceFactory>::get();
182 } 182 }
183 183
184 GDataSystemServiceFactory::GDataSystemServiceFactory() 184 DriveSystemServiceFactory::DriveSystemServiceFactory()
185 : ProfileKeyedServiceFactory("GDataSystemService", 185 : ProfileKeyedServiceFactory("DriveSystemService",
186 ProfileDependencyManager::GetInstance()) { 186 ProfileDependencyManager::GetInstance()) {
187 DependsOn(DownloadServiceFactory::GetInstance()); 187 DependsOn(DownloadServiceFactory::GetInstance());
188 } 188 }
189 189
190 GDataSystemServiceFactory::~GDataSystemServiceFactory() { 190 DriveSystemServiceFactory::~DriveSystemServiceFactory() {
191 } 191 }
192 192
193 // static 193 // static
194 void GDataSystemServiceFactory::set_drive_service_for_test( 194 void DriveSystemServiceFactory::set_drive_service_for_test(
195 DriveServiceInterface* drive_service) { 195 DriveServiceInterface* drive_service) {
196 if (g_test_drive_service) 196 if (g_test_drive_service)
197 delete g_test_drive_service; 197 delete g_test_drive_service;
198 g_test_drive_service = drive_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 DriveSystemServiceFactory::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* DriveSystemServiceFactory::BuildServiceInstanceFor(
210 Profile* profile) const { 210 Profile* profile) const {
211 GDataSystemService* service = new GDataSystemService(profile); 211 DriveSystemService* service = new DriveSystemService(profile);
212 212
213 DriveServiceInterface* drive_service = g_test_drive_service; 213 DriveServiceInterface* drive_service = g_test_drive_service;
214 g_test_drive_service = NULL; 214 g_test_drive_service = NULL;
215 if (!drive_service) { 215 if (!drive_service) {
216 if (util::IsDriveV2ApiEnabled()) 216 if (util::IsDriveV2ApiEnabled())
217 drive_service = new DriveAPIService(); 217 drive_service = new DriveAPIService();
218 else 218 else
219 drive_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 DriveCache::GetCacheRootPath(profile); 224 DriveCache::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(drive_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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698