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

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

Issue 13976019: Reland of https://codereview.chromium.org/13891016/. This includes the fix for the Segfault on Chro… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Final rebase before dcommit attempt 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: 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 84efafaa149047b03700919df63ec2cbe60926b8..fc83aca145d6dd56ce265e8dd82d37e71eaa53c4 100644
--- a/chrome/browser/chromeos/drive/drive_system_service.cc
+++ b/chrome/browser/chromeos/drive/drive_system_service.cc
@@ -25,11 +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"
@@ -47,8 +48,7 @@ using content::BrowserThread;
namespace drive {
namespace {
-// The sync invalidation object ID for Google Drive.
-const char kDriveInvalidationObjectId[] = "CHANGELOG";
+static const size_t kEventLogHistorySize = 100;
// Returns true if Drive is enabled for the given Profile.
bool IsDriveEnabledForProfile(Profile* profile) {
@@ -104,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();
@@ -172,19 +171,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();
}
@@ -199,6 +189,10 @@ void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) {
observers_.RemoveObserver(observer);
}
+void DriveSystemService::OnNotificationReceived() {
+ file_system_->CheckForUpdates();
+}
+
bool DriveSystemService::IsDriveEnabled() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -212,22 +206,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));
@@ -283,19 +261,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());
@@ -375,18 +340,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();
}
@@ -455,7 +412,7 @@ void DriveSystemServiceFactory::SetFactoryForTest(
DriveSystemServiceFactory::DriveSystemServiceFactory()
: ProfileKeyedServiceFactory("DriveSystemService",
ProfileDependencyManager::GetInstance()) {
- DependsOn(ProfileSyncServiceFactory::GetInstance());
+ DependsOn(google_apis::DriveNotificationManagerFactory::GetInstance());
DependsOn(DownloadServiceFactory::GetInstance());
}
« no previous file with comments | « chrome/browser/chromeos/drive/drive_system_service.h ('k') | chrome/browser/google_apis/drive_notification_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698