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

Unified Diff: trunk/src/chrome/browser/chromeos/drive/drive_system_service.cc

Issue 14401006: Revert 195482 "Make DriveSystemService an observer of DriveNotif..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: trunk/src/chrome/browser/chromeos/drive/drive_system_service.cc
===================================================================
--- trunk/src/chrome/browser/chromeos/drive/drive_system_service.cc (revision 195487)
+++ trunk/src/chrome/browser/chromeos/drive/drive_system_service.cc (working copy)
@@ -25,12 +25,12 @@
#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/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"
#include "chrome/common/pref_names.h"
@@ -49,6 +49,9 @@
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));
@@ -103,6 +106,7 @@
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();
@@ -172,10 +176,19 @@
void DriveSystemService::Shutdown() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- google_apis::DriveNotificationManager* drive_notification_manager =
- google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
- DCHECK(drive_notification_manager);
- drive_notification_manager->RemoveObserver(this);
+ 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;
+ }
RemoveDriveMountPoint();
}
@@ -190,10 +203,6 @@
observers_.RemoveObserver(observer);
}
-void DriveSystemService::OnNotificationReceived() {
- file_system_->CheckForUpdates();
-}
-
bool DriveSystemService::IsDriveEnabled() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -207,6 +216,22 @@
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));
@@ -264,6 +289,19 @@
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());
@@ -341,10 +379,18 @@
cache_->GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS));
// Register for Google Drive invalidation notifications.
- google_apis::DriveNotificationManager* drive_notification_manager =
- google_apis::DriveNotificationManagerFactory::GetForProfile(profile_);
- DCHECK(drive_notification_manager);
- drive_notification_manager->AddObserver(this);
+ 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;
+ }
AddDriveMountPoint();
}
@@ -413,7 +459,7 @@
DriveSystemServiceFactory::DriveSystemServiceFactory()
: ProfileKeyedServiceFactory("DriveSystemService",
ProfileDependencyManager::GetInstance()) {
- DependsOn(google_apis::DriveNotificationManagerFactory::GetInstance());
+ DependsOn(ProfileSyncServiceFactory::GetInstance());
DependsOn(DownloadServiceFactory::GetInstance());
}

Powered by Google App Engine
This is Rietveld 408576698