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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/gdata/gdata_system_service.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/gdata/drive_api_service.h"
11 #include "chrome/browser/chromeos/gdata/drive_file_system.h"
12 #include "chrome/browser/chromeos/gdata/drive_file_system_proxy.h"
13 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
14 #include "chrome/browser/chromeos/gdata/file_write_helper.h"
15 #include "chrome/browser/chromeos/gdata/gdata_contacts_service.h"
16 #include "chrome/browser/chromeos/gdata/gdata_download_observer.h"
17 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h"
18 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
19 #include "chrome/browser/chromeos/gdata/gdata_util.h"
20 #include "chrome/browser/chromeos/gdata/gdata_wapi_service.h"
21 #include "chrome/browser/download/download_service.h"
22 #include "chrome/browser/download/download_service_factory.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/profiles/profile_dependency_manager.h"
25 #include "content/public/browser/browser_context.h"
26 #include "content/public/browser/browser_thread.h"
27 #include "webkit/fileapi/file_system_context.h"
28 #include "webkit/fileapi/file_system_mount_point_provider.h"
29
30 using content::BrowserContext;
31 using content::BrowserThread;
32
33 namespace gdata {
34 namespace {
35
36 // Used in test to setup system service.
37 DriveServiceInterface* g_test_drive_service = NULL;
38 const std::string* g_test_cache_root = NULL;
39
40 } // namespace
41
42 GDataSystemService::GDataSystemService(Profile* profile)
43 : profile_(profile),
44 cache_(NULL),
45 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
47 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
48 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
49 blocking_pool->GetSequenceToken());
50 }
51
52 GDataSystemService::~GDataSystemService() {
53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
54 cache_->DestroyOnUIThread();
55 }
56
57 void GDataSystemService::Initialize(
58 DriveServiceInterface* drive_service,
59 const FilePath& cache_root) {
60 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
61
62 drive_service_.reset(drive_service);
63 cache_ = DriveCache::CreateDriveCacheOnUIThread(
64 cache_root,
65 blocking_task_runner_);
66 uploader_.reset(new GDataUploader(drive_service_.get()));
67 webapps_registry_.reset(new DriveWebAppsRegistry);
68 file_system_.reset(new DriveFileSystem(profile_,
69 cache(),
70 drive_service_.get(),
71 uploader(),
72 webapps_registry(),
73 blocking_task_runner_));
74 file_write_helper_.reset(new FileWriteHelper(file_system()));
75 download_observer_.reset(new GDataDownloadObserver(uploader(),
76 file_system()));
77 sync_client_.reset(new GDataSyncClient(profile_, file_system(), cache()));
78 contacts_service_.reset(new GDataContactsService(profile_));
79
80 sync_client_->Initialize();
81 file_system_->Initialize();
82 cache_->RequestInitializeOnUIThread();
83
84 content::DownloadManager* download_manager =
85 g_browser_process->download_status_updater() ?
86 BrowserContext::GetDownloadManager(profile_) : NULL;
87 download_observer_->Initialize(
88 download_manager,
89 cache_->GetCacheDirectoryPath(
90 DriveCache::CACHE_TYPE_TMP_DOWNLOADS));
91
92 AddDriveMountPoint();
93 contacts_service_->Initialize();
94 }
95
96 void GDataSystemService::Shutdown() {
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
98 RemoveDriveMountPoint();
99
100 // Shut down the member objects in the reverse order of creation.
101 contacts_service_.reset();
102 sync_client_.reset();
103 download_observer_.reset();
104 file_write_helper_.reset();
105 file_system_.reset();
106 webapps_registry_.reset();
107 uploader_.reset();
108 drive_service_.reset();
109 }
110
111 void GDataSystemService::ClearCacheAndRemountFileSystem(
112 const base::Callback<void(bool)>& callback) {
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
114
115 RemoveDriveMountPoint();
116 drive_service()->CancelAll();
117 cache_->ClearAllOnUIThread(
118 base::Bind(&GDataSystemService::AddBackDriveMountPoint,
119 weak_ptr_factory_.GetWeakPtr(),
120 callback));
121 }
122
123 void GDataSystemService::AddBackDriveMountPoint(
124 const base::Callback<void(bool)>& callback,
125 DriveFileError error,
126 const FilePath& file_path) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128
129 AddDriveMountPoint();
130
131 if (!callback.is_null())
132 callback.Run(error == DRIVE_FILE_OK);
133 }
134
135 void GDataSystemService::AddDriveMountPoint() {
136 if (!gdata::util::IsGDataAvailable(profile_))
137 return;
138
139 const FilePath mount_point = gdata::util::GetGDataMountPointPath();
140 fileapi::ExternalFileSystemMountPointProvider* provider =
141 BrowserContext::GetFileSystemContext(profile_)->external_provider();
142 if (provider && !provider->HasMountPoint(mount_point)) {
143 provider->AddRemoteMountPoint(
144 mount_point,
145 new DriveFileSystemProxy(file_system_.get()));
146 }
147
148 file_system_->Initialize();
149 file_system_->NotifyFileSystemMounted();
150 }
151
152 void GDataSystemService::RemoveDriveMountPoint() {
153 file_system_->NotifyFileSystemToBeUnmounted();
154 file_system_->StopUpdates();
155
156 const FilePath mount_point = gdata::util::GetGDataMountPointPath();
157 fileapi::ExternalFileSystemMountPointProvider* provider =
158 BrowserContext::GetFileSystemContext(profile_)->external_provider();
159 if (provider && provider->HasMountPoint(mount_point))
160 provider->RemoveMountPoint(mount_point);
161 }
162
163 //===================== GDataSystemServiceFactory =============================
164
165 // static
166 GDataSystemService* GDataSystemServiceFactory::GetForProfile(
167 Profile* profile) {
168 return static_cast<GDataSystemService*>(
169 GetInstance()->GetServiceForProfile(profile, true));
170 }
171
172 // static
173 GDataSystemService* GDataSystemServiceFactory::FindForProfile(
174 Profile* profile) {
175 return static_cast<GDataSystemService*>(
176 GetInstance()->GetServiceForProfile(profile, false));
177 }
178
179 // static
180 GDataSystemServiceFactory* GDataSystemServiceFactory::GetInstance() {
181 return Singleton<GDataSystemServiceFactory>::get();
182 }
183
184 GDataSystemServiceFactory::GDataSystemServiceFactory()
185 : ProfileKeyedServiceFactory("GDataSystemService",
186 ProfileDependencyManager::GetInstance()) {
187 DependsOn(DownloadServiceFactory::GetInstance());
188 }
189
190 GDataSystemServiceFactory::~GDataSystemServiceFactory() {
191 }
192
193 // static
194 void GDataSystemServiceFactory::set_drive_service_for_test(
195 DriveServiceInterface* drive_service) {
196 if (g_test_drive_service)
197 delete g_test_drive_service;
198 g_test_drive_service = drive_service;
199 }
200
201 // static
202 void GDataSystemServiceFactory::set_cache_root_for_test(
203 const std::string& cache_root) {
204 if (g_test_cache_root)
205 delete g_test_cache_root;
206 g_test_cache_root = !cache_root.empty() ? new std::string(cache_root) : NULL;
207 }
208
209 ProfileKeyedService* GDataSystemServiceFactory::BuildServiceInstanceFor(
210 Profile* profile) const {
211 GDataSystemService* service = new GDataSystemService(profile);
212
213 DriveServiceInterface* drive_service = g_test_drive_service;
214 g_test_drive_service = NULL;
215 if (!drive_service) {
216 if (util::IsDriveV2ApiEnabled())
217 drive_service = new DriveAPIService();
218 else
219 drive_service = new GDataWapiService();
220 }
221
222 FilePath cache_root =
223 g_test_cache_root ? FilePath(*g_test_cache_root) :
224 DriveCache::GetCacheRootPath(profile);
225 delete g_test_cache_root;
226 g_test_cache_root = NULL;
227
228 service->Initialize(drive_service, cache_root);
229 return service;
230 }
231
232 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698