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

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

Issue 13891016: Merge ChromeOS and SyncFS XMPP Notification into one class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 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/drive/drive_system_service.h" 5 #include "chrome/browser/chromeos/drive/drive_system_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/drive/drive_download_handler.h" 11 #include "chrome/browser/chromeos/drive/drive_download_handler.h"
12 #include "chrome/browser/chromeos/drive/drive_file_system.h" 12 #include "chrome/browser/chromeos/drive/drive_file_system.h"
13 #include "chrome/browser/chromeos/drive/drive_file_system_proxy.h" 13 #include "chrome/browser/chromeos/drive/drive_file_system_proxy.h"
14 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 14 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
15 #include "chrome/browser/chromeos/drive/drive_prefetcher.h" 15 #include "chrome/browser/chromeos/drive/drive_prefetcher.h"
16 #include "chrome/browser/chromeos/drive/drive_sync_client.h" 16 #include "chrome/browser/chromeos/drive/drive_sync_client.h"
17 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" 17 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h"
18 #include "chrome/browser/chromeos/drive/event_logger.h" 18 #include "chrome/browser/chromeos/drive/event_logger.h"
19 #include "chrome/browser/chromeos/drive/file_write_helper.h" 19 #include "chrome/browser/chromeos/drive/file_write_helper.h"
20 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h" 20 #include "chrome/browser/chromeos/drive/stale_cache_files_remover.h"
21 #include "chrome/browser/download/download_service.h" 21 #include "chrome/browser/download/download_service.h"
22 #include "chrome/browser/download/download_service_factory.h" 22 #include "chrome/browser/download/download_service_factory.h"
23 #include "chrome/browser/download/download_util.h" 23 #include "chrome/browser/download/download_util.h"
24 #include "chrome/browser/google_apis/auth_service.h" 24 #include "chrome/browser/google_apis/auth_service.h"
25 #include "chrome/browser/google_apis/drive_api_service.h" 25 #include "chrome/browser/google_apis/drive_api_service.h"
26 #include "chrome/browser/google_apis/drive_api_util.h" 26 #include "chrome/browser/google_apis/drive_api_util.h"
27 #include "chrome/browser/google_apis/drive_notification_manager.h"
28 #include "chrome/browser/google_apis/drive_notification_manager_factory.h"
27 #include "chrome/browser/google_apis/gdata_wapi_service.h" 29 #include "chrome/browser/google_apis/gdata_wapi_service.h"
28 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" 30 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
29 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/profiles/profile_dependency_manager.h" 32 #include "chrome/browser/profiles/profile_dependency_manager.h"
31 #include "chrome/browser/sync/profile_sync_service.h"
32 #include "chrome/browser/sync/profile_sync_service_factory.h"
33 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/chrome_version_info.h" 34 #include "chrome/common/chrome_version_info.h"
35 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
36 #include "content/public/browser/browser_context.h" 36 #include "content/public/browser/browser_context.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/storage_partition.h" 38 #include "content/public/browser/storage_partition.h"
39 #include "google/cacheinvalidation/types.pb.h" 39 #include "google/cacheinvalidation/types.pb.h"
40 #include "webkit/fileapi/external_mount_points.h" 40 #include "webkit/fileapi/external_mount_points.h"
41 #include "webkit/user_agent/user_agent_util.h" 41 #include "webkit/user_agent/user_agent_util.h"
42 42
43 using content::BrowserContext; 43 using content::BrowserContext;
44 using content::BrowserThread; 44 using content::BrowserThread;
45 45
46 namespace drive { 46 namespace drive {
47 namespace { 47 namespace {
48 48
49 static const size_t kEventLogHistorySize = 100; 49 static const size_t kEventLogHistorySize = 100;
50 50
51 // The sync invalidation object ID for Google Drive.
52 const char kDriveInvalidationObjectId[] = "CHANGELOG";
53
54 // Returns true if Drive is enabled for the given Profile. 51 // Returns true if Drive is enabled for the given Profile.
55 bool IsDriveEnabledForProfile(Profile* profile) { 52 bool IsDriveEnabledForProfile(Profile* profile) {
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
57 54
58 if (!google_apis::AuthService::CanAuthenticate(profile)) 55 if (!google_apis::AuthService::CanAuthenticate(profile))
59 return false; 56 return false;
60 57
61 // Disable Drive if preference is set. This can happen with commandline flag 58 // Disable Drive if preference is set. This can happen with commandline flag
62 // --disable-gdata or enterprise policy, or probably with user settings too 59 // --disable-gdata or enterprise policy, or probably with user settings too
63 // in the future. 60 // in the future.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 95
99 } // namespace 96 } // namespace
100 97
101 DriveSystemService::DriveSystemService( 98 DriveSystemService::DriveSystemService(
102 Profile* profile, 99 Profile* profile,
103 google_apis::DriveServiceInterface* test_drive_service, 100 google_apis::DriveServiceInterface* test_drive_service,
104 const base::FilePath& test_cache_root, 101 const base::FilePath& test_cache_root,
105 DriveFileSystemInterface* test_file_system) 102 DriveFileSystemInterface* test_file_system)
106 : profile_(profile), 103 : profile_(profile),
107 drive_disabled_(false), 104 drive_disabled_(false),
108 push_notification_registered_(false),
109 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 105 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); 107 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool();
112 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( 108 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner(
113 blocking_pool->GetSequenceToken()); 109 blocking_pool->GetSequenceToken());
114 110
115 event_logger_.reset(new EventLogger(kEventLogHistorySize)); 111 event_logger_.reset(new EventLogger(kEventLogHistorySize));
116 if (test_drive_service) { 112 if (test_drive_service) {
117 drive_service_.reset(test_drive_service); 113 drive_service_.reset(test_drive_service);
118 } else if (google_apis::util::IsDriveV2ApiEnabled()) { 114 } else if (google_apis::util::IsDriveV2ApiEnabled()) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 drive_service_->Initialize(profile_); 165 drive_service_->Initialize(profile_);
170 file_system_->Initialize(); 166 file_system_->Initialize();
171 cache_->RequestInitialize( 167 cache_->RequestInitialize(
172 base::Bind(&DriveSystemService::InitializeAfterCacheInitialized, 168 base::Bind(&DriveSystemService::InitializeAfterCacheInitialized,
173 weak_ptr_factory_.GetWeakPtr())); 169 weak_ptr_factory_.GetWeakPtr()));
174 } 170 }
175 171
176 void DriveSystemService::Shutdown() { 172 void DriveSystemService::Shutdown() {
177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
178 174
179 ProfileSyncService* profile_sync_service = 175 google_apis::DriveNotificationManager* drive_notification_manager =
180 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 176 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
181 if (profile_sync_service && push_notification_registered_) { 177 DCHECK(drive_notification_manager);
182 // TODO(kochi): Once DriveSystemService gets started / stopped at runtime, 178 drive_notification_manager->RemoveObserver(this);
183 // this ID needs to be unregistered *before* the handler is unregistered
184 // as ID persists across browser restarts.
185 if (!IsDriveEnabledForProfile(profile_)) {
186 profile_sync_service->UpdateRegisteredInvalidationIds(
187 this, syncer::ObjectIdSet());
188 }
189 profile_sync_service->UnregisterInvalidationHandler(this);
190 push_notification_registered_ = false;
191 }
192 179
193 RemoveDriveMountPoint(); 180 RemoveDriveMountPoint();
194 } 181 }
195 182
196 void DriveSystemService::AddObserver(DriveSystemServiceObserver* observer) { 183 void DriveSystemService::AddObserver(DriveSystemServiceObserver* observer) {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
198 observers_.AddObserver(observer); 185 observers_.AddObserver(observer);
199 } 186 }
200 187
201 void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) { 188 void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) {
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
203 observers_.RemoveObserver(observer); 190 observers_.RemoveObserver(observer);
191
192 void DriveSystemService::CheckForUpdates() {
193 file_system_->CheckForUpdates();
204 } 194 }
205 195
206 bool DriveSystemService::IsDriveEnabled() { 196 bool DriveSystemService::IsDriveEnabled() {
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
208 198
209 if (!IsDriveEnabledForProfile(profile_)) 199 if (!IsDriveEnabledForProfile(profile_))
210 return false; 200 return false;
211 201
212 // Drive may be disabled for cache initialization failure, etc. 202 // Drive may be disabled for cache initialization failure, etc.
213 if (drive_disabled_) 203 if (drive_disabled_)
214 return false; 204 return false;
215 205
216 return true; 206 return true;
217 } 207 }
218 208
219 void DriveSystemService::OnInvalidatorStateChange(
220 syncer::InvalidatorState state) {
221 DVLOG(1) << "InvalidatorState changed to " << state;
222 }
223
224 void DriveSystemService::OnIncomingInvalidation(
225 const syncer::ObjectIdInvalidationMap& invalidation_map) {
satorux1 2013/04/19 04:12:13 Wanted to insert EventLogger logging here, but now
226 DCHECK_EQ(1U, invalidation_map.size());
227 const invalidation::ObjectId object_id(
228 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
229 kDriveInvalidationObjectId);
230 DCHECK_EQ(1U, invalidation_map.count(object_id));
231
232 file_system_->CheckForUpdates();
233 }
234
235 void DriveSystemService::ClearCacheAndRemountFileSystem( 209 void DriveSystemService::ClearCacheAndRemountFileSystem(
236 const base::Callback<void(bool)>& callback) { 210 const base::Callback<void(bool)>& callback) {
237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
238 DCHECK(!callback.is_null()); 212 DCHECK(!callback.is_null());
239 213
240 RemoveDriveMountPoint(); 214 RemoveDriveMountPoint();
241 drive_service()->CancelAll(); 215 drive_service()->CancelAll();
242 cache_->ClearAll(base::Bind( 216 cache_->ClearAll(base::Bind(
243 &DriveSystemService::ReinitializeResourceMetadataAfterClearCache, 217 &DriveSystemService::ReinitializeResourceMetadataAfterClearCache,
244 weak_ptr_factory_.GetWeakPtr(), 218 weak_ptr_factory_.GetWeakPtr(),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 256
283 RemoveDriveMountPoint(); 257 RemoveDriveMountPoint();
284 drive_service()->CancelAll(); 258 drive_service()->CancelAll();
285 file_system_->Reload(); 259 file_system_->Reload();
286 260
287 // Reload() is asynchronous. But we can add back the mount point right away 261 // Reload() is asynchronous. But we can add back the mount point right away
288 // because every operation waits until loading is complete. 262 // because every operation waits until loading is complete.
289 AddDriveMountPoint(); 263 AddDriveMountPoint();
290 } 264 }
291 265
292 bool DriveSystemService::PushNotificationEnabled() {
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
294 DCHECK(profile_);
295
296 ProfileSyncService* profile_sync_service =
297 ProfileSyncServiceFactory::GetForProfile(profile_);
298 if (!profile_sync_service)
299 return false;
300
301 return (profile_sync_service->GetInvalidatorState() ==
302 syncer::INVALIDATIONS_ENABLED);
303 }
304
305 void DriveSystemService::AddDriveMountPoint() { 266 void DriveSystemService::AddDriveMountPoint() {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
307 DCHECK(!file_system_proxy_.get()); 268 DCHECK(!file_system_proxy_.get());
308 269
309 const base::FilePath drive_mount_point = util::GetDriveMountPointPath(); 270 const base::FilePath drive_mount_point = util::GetDriveMountPointPath();
310 fileapi::ExternalMountPoints* mount_points = 271 fileapi::ExternalMountPoints* mount_points =
311 BrowserContext::GetMountPoints(profile_); 272 BrowserContext::GetMountPoints(profile_);
312 DCHECK(mount_points); 273 DCHECK(mount_points);
313 274
314 file_system_proxy_ = new DriveFileSystemProxy(file_system_.get()); 275 file_system_proxy_ = new DriveFileSystemProxy(file_system_.get());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 } 333 }
373 334
374 content::DownloadManager* download_manager = 335 content::DownloadManager* download_manager =
375 g_browser_process->download_status_updater() ? 336 g_browser_process->download_status_updater() ?
376 BrowserContext::GetDownloadManager(profile_) : NULL; 337 BrowserContext::GetDownloadManager(profile_) : NULL;
377 download_handler_->Initialize( 338 download_handler_->Initialize(
378 download_manager, 339 download_manager,
379 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); 340 cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS));
380 341
381 // Register for Google Drive invalidation notifications. 342 // Register for Google Drive invalidation notifications.
382 ProfileSyncService* profile_sync_service = 343 google_apis::DriveNotificationManager* drive_notification_manager =
383 profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; 344 google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
384 if (profile_sync_service) { 345 DCHECK(drive_notification_manager);
385 DCHECK(!push_notification_registered_); 346 drive_notification_manager->AddObserver(this);
386 profile_sync_service->RegisterInvalidationHandler(this);
387 syncer::ObjectIdSet ids;
388 ids.insert(invalidation::ObjectId(
389 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
390 kDriveInvalidationObjectId));
391 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids);
392 push_notification_registered_ = true;
393 }
394 347
395 AddDriveMountPoint(); 348 AddDriveMountPoint();
396 } 349 }
397 350
398 void DriveSystemService::DisableDrive() { 351 void DriveSystemService::DisableDrive() {
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
400 353
401 drive_disabled_ = true; 354 drive_disabled_ = true;
402 // Change the download directory to the default value if the download 355 // Change the download directory to the default value if the download
403 // destination is set to under Drive mount point. 356 // destination is set to under Drive mount point.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 405
453 // static 406 // static
454 void DriveSystemServiceFactory::SetFactoryForTest( 407 void DriveSystemServiceFactory::SetFactoryForTest(
455 const FactoryCallback& factory_for_test) { 408 const FactoryCallback& factory_for_test) {
456 GetInstance()->factory_for_test_ = factory_for_test; 409 GetInstance()->factory_for_test_ = factory_for_test;
457 } 410 }
458 411
459 DriveSystemServiceFactory::DriveSystemServiceFactory() 412 DriveSystemServiceFactory::DriveSystemServiceFactory()
460 : ProfileKeyedServiceFactory("DriveSystemService", 413 : ProfileKeyedServiceFactory("DriveSystemService",
461 ProfileDependencyManager::GetInstance()) { 414 ProfileDependencyManager::GetInstance()) {
462 DependsOn(ProfileSyncServiceFactory::GetInstance()); 415 DependsOn(google_apis::DriveNotificationManagerFactory::GetInstance());
463 DependsOn(DownloadServiceFactory::GetInstance()); 416 DependsOn(DownloadServiceFactory::GetInstance());
464 } 417 }
465 418
466 DriveSystemServiceFactory::~DriveSystemServiceFactory() { 419 DriveSystemServiceFactory::~DriveSystemServiceFactory() {
467 } 420 }
468 421
469 ProfileKeyedService* DriveSystemServiceFactory::BuildServiceInstanceFor( 422 ProfileKeyedService* DriveSystemServiceFactory::BuildServiceInstanceFor(
470 Profile* profile) const { 423 Profile* profile) const {
471 DriveSystemService* service = NULL; 424 DriveSystemService* service = NULL;
472 if (factory_for_test_.is_null()) 425 if (factory_for_test_.is_null())
473 service = new DriveSystemService(profile, NULL, base::FilePath(), NULL); 426 service = new DriveSystemService(profile, NULL, base::FilePath(), NULL);
474 else 427 else
475 service = factory_for_test_.Run(profile); 428 service = factory_for_test_.Run(profile);
476 429
477 service->Initialize(); 430 service->Initialize();
478 return service; 431 return service;
479 } 432 }
480 433
481 } // namespace drive 434 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698