Index: chrome/browser/chromeos/drive/drive_system_service.cc |
diff --git a/chrome/browser/chromeos/drive/drive_system_service.cc b/chrome/browser/chromeos/drive/drive_system_service.cc |
index 46dbf9c240cf7b9ee9028f177140e9b891039ee8..2926381bee175863a1e96fd5ab3576edf50e5ccb 100644 |
--- a/chrome/browser/chromeos/drive/drive_system_service.cc |
+++ b/chrome/browser/chromeos/drive/drive_system_service.cc |
@@ -24,12 +24,13 @@ |
#include "chrome/browser/google_apis/auth_service.h" |
#include "chrome/browser/google_apis/drive_api_service.h" |
#include "chrome/browser/google_apis/drive_api_util.h" |
+#include "chrome/browser/google_apis/drive_notification_manager.h" |
+#include "chrome/browser/google_apis/drive_notification_manager_factory.h" |
#include "chrome/browser/google_apis/event_logger.h" |
#include "chrome/browser/google_apis/gdata_wapi_service.h" |
#include "chrome/browser/google_apis/gdata_wapi_url_generator.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_dependency_manager.h" |
-#include "chrome/browser/sync/profile_sync_service.h" |
#include "chrome/browser/sync/profile_sync_service_factory.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/chrome_version_info.h" |
@@ -49,9 +50,6 @@ namespace { |
static const size_t kEventLogHistorySize = 100; |
-// The sync invalidation object ID for Google Drive. |
-const char kDriveInvalidationObjectId[] = "CHANGELOG"; |
- |
// Returns true if Drive is enabled for the given Profile. |
bool IsDriveEnabledForProfile(Profile* profile) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -106,7 +104,6 @@ DriveSystemService::DriveSystemService( |
DriveFileSystemInterface* test_file_system) |
: profile_(profile), |
drive_disabled_(false), |
- push_notification_registered_(false), |
ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
@@ -176,19 +173,10 @@ void DriveSystemService::Initialize() { |
void DriveSystemService::Shutdown() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- ProfileSyncService* profile_sync_service = |
- profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; |
- if (profile_sync_service && push_notification_registered_) { |
- // TODO(kochi): Once DriveSystemService gets started / stopped at runtime, |
- // this ID needs to be unregistered *before* the handler is unregistered |
- // as ID persists across browser restarts. |
- if (!IsDriveEnabledForProfile(profile_)) { |
- profile_sync_service->UpdateRegisteredInvalidationIds( |
- this, syncer::ObjectIdSet()); |
- } |
- profile_sync_service->UnregisterInvalidationHandler(this); |
- push_notification_registered_ = false; |
- } |
+ google_apis::DriveNotificationManager* drive_notification_manager = |
+ google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); |
+ if (drive_notification_manager) |
+ drive_notification_manager->RemoveObserver(this); |
RemoveDriveMountPoint(); |
} |
@@ -203,6 +191,10 @@ void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) { |
observers_.RemoveObserver(observer); |
} |
+void DriveSystemService::OnNotificationReceived() { |
+ file_system_->CheckForUpdates(); |
+} |
+ |
bool DriveSystemService::IsDriveEnabled() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -216,22 +208,6 @@ bool DriveSystemService::IsDriveEnabled() { |
return true; |
} |
-void DriveSystemService::OnInvalidatorStateChange( |
- syncer::InvalidatorState state) { |
- DVLOG(1) << "InvalidatorState changed to " << state; |
-} |
- |
-void DriveSystemService::OnIncomingInvalidation( |
- const syncer::ObjectIdInvalidationMap& invalidation_map) { |
- DCHECK_EQ(1U, invalidation_map.size()); |
- const invalidation::ObjectId object_id( |
- ipc::invalidation::ObjectSource::COSMO_CHANGELOG, |
- kDriveInvalidationObjectId); |
- DCHECK_EQ(1U, invalidation_map.count(object_id)); |
- |
- file_system_->CheckForUpdates(); |
-} |
- |
void DriveSystemService::ClearCacheAndRemountFileSystem( |
const base::Callback<void(bool)>& callback) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -287,19 +263,6 @@ void DriveSystemService::ReloadAndRemountFileSystem() { |
AddDriveMountPoint(); |
} |
-bool DriveSystemService::PushNotificationEnabled() { |
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- DCHECK(profile_); |
- |
- ProfileSyncService* profile_sync_service = |
- ProfileSyncServiceFactory::GetForProfile(profile_); |
- if (!profile_sync_service) |
- return false; |
- |
- return (profile_sync_service->GetInvalidatorState() == |
- syncer::INVALIDATIONS_ENABLED); |
-} |
- |
void DriveSystemService::AddDriveMountPoint() { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK(!file_system_proxy_.get()); |
@@ -379,18 +342,10 @@ void DriveSystemService::InitializeAfterResourceMetadataInitialized( |
cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS)); |
// Register for Google Drive invalidation notifications. |
- ProfileSyncService* profile_sync_service = |
- profile_ ? ProfileSyncServiceFactory::GetForProfile(profile_) : NULL; |
- if (profile_sync_service) { |
- DCHECK(!push_notification_registered_); |
- profile_sync_service->RegisterInvalidationHandler(this); |
- syncer::ObjectIdSet ids; |
- ids.insert(invalidation::ObjectId( |
- ipc::invalidation::ObjectSource::COSMO_CHANGELOG, |
- kDriveInvalidationObjectId)); |
- profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); |
- push_notification_registered_ = true; |
- } |
+ google_apis::DriveNotificationManager* drive_notification_manager = |
+ google_apis::DriveNotificationManagerFactory::GetForProfile(profile_); |
+ if (drive_notification_manager) |
+ drive_notification_manager->AddObserver(this); |
AddDriveMountPoint(); |
} |
@@ -459,7 +414,7 @@ void DriveSystemServiceFactory::SetFactoryForTest( |
DriveSystemServiceFactory::DriveSystemServiceFactory() |
: ProfileKeyedServiceFactory("DriveSystemService", |
ProfileDependencyManager::GetInstance()) { |
- DependsOn(ProfileSyncServiceFactory::GetInstance()); |
+ DependsOn(google_apis::DriveNotificationManagerFactory::GetInstance()); |
DependsOn(DownloadServiceFactory::GetInstance()); |
} |