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

Side by Side Diff: chrome/browser/google_apis/drive_notification_manager.cc

Issue 13891016: Merge ChromeOS and SyncFS XMPP Notification into one class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ChromeOS SigFault fix 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/google_apis/drive_notification_manager.h" 5 #include "chrome/browser/google_apis/drive_notification_manager.h"
6 6
7 #include "chrome/browser/google_apis/drive_notification_observer.h" 7 #include "chrome/browser/google_apis/drive_notification_observer.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/profile_sync_service.h" 9 #include "chrome/browser/sync/profile_sync_service.h"
10 #include "chrome/browser/sync/profile_sync_service_factory.h" 10 #include "chrome/browser/sync/profile_sync_service_factory.h"
11 #include "google/cacheinvalidation/types.pb.h" 11 #include "google/cacheinvalidation/types.pb.h"
12 12
13 namespace google_apis { 13 namespace google_apis {
14 14
15 // The sync invalidation object ID for Google Drive. 15 // The sync invalidation object ID for Google Drive.
16 const char kDriveInvalidationObjectId[] = "CHANGELOG"; 16 const char kDriveInvalidationObjectId[] = "CHANGELOG";
17 17
18 // TODO(calvinlo): Constants for polling to go here.
19
20 DriveNotificationManager::DriveNotificationManager(Profile* profile) 18 DriveNotificationManager::DriveNotificationManager(Profile* profile)
21 : profile_(profile), 19 : profile_(profile),
22 push_notification_registered_(false), 20 push_notification_registered_(false),
23 push_notification_enabled_(false) { 21 push_notification_enabled_(false) {
24 // TODO(calvinlo): Initialize member variables for polling here.
25 RegisterDriveNotifications(); 22 RegisterDriveNotifications();
26 } 23 }
27 24
28 DriveNotificationManager::~DriveNotificationManager() {} 25 DriveNotificationManager::~DriveNotificationManager() {}
29 26
30 void DriveNotificationManager::Shutdown() { 27 void DriveNotificationManager::Shutdown() {
31 // Unregister for Drive notifications. 28 // Unregister for Drive notifications.
32 ProfileSyncService* profile_sync_service = 29 ProfileSyncService* profile_sync_service =
33 ProfileSyncServiceFactory::GetForProfile(profile_); 30 ProfileSyncServiceFactory::GetForProfile(profile_);
34 if (!profile_sync_service || !push_notification_registered_) { 31 if (!profile_sync_service || !push_notification_registered_) {
35 return; 32 return;
36 } 33 }
37 34
38 profile_sync_service->UpdateRegisteredInvalidationIds( 35 profile_sync_service->UpdateRegisteredInvalidationIds(
39 this, syncer::ObjectIdSet()); 36 this, syncer::ObjectIdSet());
40 profile_sync_service->UnregisterInvalidationHandler(this); 37 profile_sync_service->UnregisterInvalidationHandler(this);
41 } 38 }
42 39
43 void DriveNotificationManager::OnInvalidatorStateChange( 40 void DriveNotificationManager::OnInvalidatorStateChange(
44 syncer::InvalidatorState state) { 41 syncer::InvalidatorState state) {
45 SetPushNotificationEnabled(state); 42 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED);
43 if (push_notification_enabled_) {
44 DVLOG(1) << "XMPP Notifications enabled";
45 } else {
46 DVLOG(1) << "XMPP Notifications disabled (state=" << state << ")";
47 }
46 } 48 }
47 49
48 void DriveNotificationManager::OnIncomingInvalidation( 50 void DriveNotificationManager::OnIncomingInvalidation(
49 const syncer::ObjectIdInvalidationMap& invalidation_map) { 51 const syncer::ObjectIdInvalidationMap& invalidation_map) {
50 DVLOG(2) << "XMPP Drive Notification Received"; 52 DVLOG(2) << "XMPP Drive Notification Received";
51 DCHECK_EQ(1U, invalidation_map.size()); 53 DCHECK_EQ(1U, invalidation_map.size());
52 const invalidation::ObjectId object_id( 54 const invalidation::ObjectId object_id(
53 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, 55 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
54 kDriveInvalidationObjectId); 56 kDriveInvalidationObjectId);
55 DCHECK_EQ(1U, invalidation_map.count(object_id)); 57 DCHECK_EQ(1U, invalidation_map.count(object_id));
56 58
57 // TODO(dcheng): Only acknowledge the invalidation once the fetch has 59 // TODO(dcheng): Only acknowledge the invalidation once the fetch has
58 // completed. http://crbug.com/156843 60 // completed. http://crbug.com/156843
59 ProfileSyncService* profile_sync_service = 61 ProfileSyncService* profile_sync_service =
60 ProfileSyncServiceFactory::GetForProfile(profile_); 62 ProfileSyncServiceFactory::GetForProfile(profile_);
61 CHECK(profile_sync_service);
62 profile_sync_service->AcknowledgeInvalidation( 63 profile_sync_service->AcknowledgeInvalidation(
63 invalidation_map.begin()->first, 64 invalidation_map.begin()->first,
64 invalidation_map.begin()->second.ack_handle); 65 invalidation_map.begin()->second.ack_handle);
65 66
66 NotifyObserversToUpdate(); 67 NotifyObserversToUpdate();
67 } 68 }
68 69
69 void DriveNotificationManager::AddObserver( 70 void DriveNotificationManager::AddObserver(
70 DriveNotificationObserver* observer) { 71 DriveNotificationObserver* observer) {
71 observers_.AddObserver(observer); 72 observers_.AddObserver(observer);
72 } 73 }
73 74
74 void DriveNotificationManager::RemoveObserver( 75 void DriveNotificationManager::RemoveObserver(
75 DriveNotificationObserver* observer) { 76 DriveNotificationObserver* observer) {
76 observers_.RemoveObserver(observer); 77 observers_.RemoveObserver(observer);
77 } 78 }
78 79
80 bool DriveNotificationManager::IsPushNotificationEnabled() {
81 return push_notification_enabled_;
82 }
83
79 void DriveNotificationManager::NotifyObserversToUpdate() { 84 void DriveNotificationManager::NotifyObserversToUpdate() {
80 FOR_EACH_OBSERVER(DriveNotificationObserver, observers_, CheckForUpdates()); 85 FOR_EACH_OBSERVER(DriveNotificationObserver, observers_,
86 OnNotificationReceived());
81 } 87 }
82 88
83 // Register for Google Drive invalidation notifications through XMPP. 89 // Register for Google Drive invalidation notifications through XMPP.
84 void DriveNotificationManager::RegisterDriveNotifications() { 90 void DriveNotificationManager::RegisterDriveNotifications() {
85 // Push notification registration might have already occurred if called from 91 // Push notification registration might have already occurred if called from
86 // a different extension. 92 // a different extension.
87 if (!IsDriveNotificationSupported() || push_notification_registered_) 93 if (push_notification_registered_)
88 return; 94 return;
89 95
90 ProfileSyncService* profile_sync_service = 96 ProfileSyncService* profile_sync_service =
91 ProfileSyncServiceFactory::GetForProfile(profile_); 97 ProfileSyncServiceFactory::GetForProfile(profile_);
92 if (!profile_sync_service) 98 if (!profile_sync_service)
93 return; 99 return;
94 100
95 profile_sync_service->RegisterInvalidationHandler(this); 101 profile_sync_service->RegisterInvalidationHandler(this);
96 syncer::ObjectIdSet ids; 102 syncer::ObjectIdSet ids;
97 ids.insert(invalidation::ObjectId( 103 ids.insert(invalidation::ObjectId(
98 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, 104 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
99 kDriveInvalidationObjectId)); 105 kDriveInvalidationObjectId));
100 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); 106 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids);
101 push_notification_registered_ = true; 107 push_notification_registered_ = true;
102 SetPushNotificationEnabled(profile_sync_service->GetInvalidatorState()); 108 OnInvalidatorStateChange(profile_sync_service->GetInvalidatorState());
103 }
104
105 // TODO(calvinlo): Remove when all patches for http://crbug.com/173339 done.
106 bool DriveNotificationManager::IsDriveNotificationSupported() {
107 // TODO(calvinlo): A invalidation ID can only be registered to one handler.
108 // Therefore ChromeOS and SyncFS cannot both use XMPP notifications until
109 // (http://crbug.com/173339) is completed.
110 // For now, disable XMPP notifications for SyncFC on ChromeOS to guarantee
111 // that ChromeOS's file manager can register itself to the invalidationID.
112
113 #if defined(OS_CHROMEOS)
114 return false;
115 #else
116 return true;
117 #endif
118 }
119
120 void DriveNotificationManager::SetPushNotificationEnabled(
121 syncer::InvalidatorState state) {
122 DVLOG(1) << "SetPushNotificationEnabled() with state=" << state;
123 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED);
124 if (!push_notification_enabled_)
125 return;
126
127 // Push notifications are enabled so reset polling timer.
128 //UpdatePollingDelay(kPollingDelaySecondsWithNotification);
129 } 109 }
130 110
131 } // namespace google_apis 111 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698