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

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

Issue 15580002: Make use of InvalidationService (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re-add old API documentation Created 7 years, 7 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
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 "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/google_apis/drive_notification_observer.h" 8 #include "chrome/browser/google_apis/drive_notification_observer.h"
9 #include "chrome/browser/invalidation/invalidation_service.h"
10 #include "chrome/browser/invalidation/invalidation_service_factory.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/profile_sync_service.h"
11 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "google/cacheinvalidation/types.pb.h" 12 #include "google/cacheinvalidation/types.pb.h"
13 13
14 namespace google_apis { 14 namespace google_apis {
15 15
16 namespace { 16 namespace {
17 17
18 // The polling interval time is used when XMPP is disabled. 18 // The polling interval time is used when XMPP is disabled.
19 const int kFastPollingIntervalInSecs = 60; 19 const int kFastPollingIntervalInSecs = 60;
20 20
21 // The polling interval time is used when XMPP is enabled. Theoretically 21 // The polling interval time is used when XMPP is enabled. Theoretically
(...skipping 13 matching lines...) Expand all
35 polling_timer_(true /* retain_user_task */, false /* is_repeating */), 35 polling_timer_(true /* retain_user_task */, false /* is_repeating */),
36 weak_ptr_factory_(this) { 36 weak_ptr_factory_(this) {
37 RegisterDriveNotifications(); 37 RegisterDriveNotifications();
38 RestartPollingTimer(); 38 RestartPollingTimer();
39 } 39 }
40 40
41 DriveNotificationManager::~DriveNotificationManager() {} 41 DriveNotificationManager::~DriveNotificationManager() {}
42 42
43 void DriveNotificationManager::Shutdown() { 43 void DriveNotificationManager::Shutdown() {
44 // Unregister for Drive notifications. 44 // Unregister for Drive notifications.
45 ProfileSyncService* profile_sync_service = 45 invalidation::InvalidationService* invalidation_service =
46 ProfileSyncServiceFactory::GetForProfile(profile_); 46 invalidation::InvalidationServiceFactory::GetForProfile(profile_);
47 if (!profile_sync_service || !push_notification_registered_) { 47 if (!invalidation_service || !push_notification_registered_) {
48 return; 48 return;
49 } 49 }
50 50
51 profile_sync_service->UpdateRegisteredInvalidationIds( 51 invalidation_service->UnregisterInvalidationHandler(this);
rlarocque 2013/05/21 20:51:36 The API expects that clients will not unregister t
satorux1 2013/05/22 02:24:11 I'm a bit confused. Call to UpdateRegisteredInvali
rlarocque 2013/05/22 23:46:51 I agree, it does look strange. There's a valid re
satorux1 2013/05/23 00:54:21 Thank you for the explanation. Could you leave a s
rlarocque 2013/05/23 21:43:27 Done.
52 this, syncer::ObjectIdSet());
53 profile_sync_service->UnregisterInvalidationHandler(this);
54 } 52 }
55 53
56 void DriveNotificationManager::OnInvalidatorStateChange( 54 void DriveNotificationManager::OnInvalidatorStateChange(
57 syncer::InvalidatorState state) { 55 syncer::InvalidatorState state) {
58 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED); 56 push_notification_enabled_ = (state == syncer::INVALIDATIONS_ENABLED);
59 if (push_notification_enabled_) { 57 if (push_notification_enabled_) {
60 DVLOG(1) << "XMPP Notifications enabled"; 58 DVLOG(1) << "XMPP Notifications enabled";
61 } else { 59 } else {
62 DVLOG(1) << "XMPP Notifications disabled (state=" << state << ")"; 60 DVLOG(1) << "XMPP Notifications disabled (state=" << state << ")";
63 } 61 }
64 FOR_EACH_OBSERVER(DriveNotificationObserver, observers_, 62 FOR_EACH_OBSERVER(DriveNotificationObserver, observers_,
65 OnPushNotificationEnabled(push_notification_enabled_)); 63 OnPushNotificationEnabled(push_notification_enabled_));
66 } 64 }
67 65
68 void DriveNotificationManager::OnIncomingInvalidation( 66 void DriveNotificationManager::OnIncomingInvalidation(
69 const syncer::ObjectIdInvalidationMap& invalidation_map) { 67 const syncer::ObjectIdInvalidationMap& invalidation_map) {
70 DVLOG(2) << "XMPP Drive Notification Received"; 68 DVLOG(2) << "XMPP Drive Notification Received";
71 DCHECK_EQ(1U, invalidation_map.size()); 69 DCHECK_EQ(1U, invalidation_map.size());
72 const invalidation::ObjectId object_id( 70 const invalidation::ObjectId object_id(
73 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, 71 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
74 kDriveInvalidationObjectId); 72 kDriveInvalidationObjectId);
75 DCHECK_EQ(1U, invalidation_map.count(object_id)); 73 DCHECK_EQ(1U, invalidation_map.count(object_id));
76 74
77 // TODO(dcheng): Only acknowledge the invalidation once the fetch has 75 // TODO(dcheng): Only acknowledge the invalidation once the fetch has
78 // completed. http://crbug.com/156843 76 // completed. http://crbug.com/156843
79 ProfileSyncService* profile_sync_service = 77 invalidation::InvalidationService* invalidation_service =
80 ProfileSyncServiceFactory::GetForProfile(profile_); 78 invalidation::InvalidationServiceFactory::GetForProfile(profile_);
81 profile_sync_service->AcknowledgeInvalidation( 79 CHECK(invalidation_service);
satorux1 2013/05/22 02:24:11 DCHECK? I think we rarely use CHECK. http://www.c
rlarocque 2013/05/22 23:46:51 Done.
80 invalidation_service->AcknowledgeInvalidation(
82 invalidation_map.begin()->first, 81 invalidation_map.begin()->first,
83 invalidation_map.begin()->second.ack_handle); 82 invalidation_map.begin()->second.ack_handle);
84 83
85 NotifyObserversToUpdate(NOTIFICATION_XMPP); 84 NotifyObserversToUpdate(NOTIFICATION_XMPP);
86 } 85 }
87 86
88 void DriveNotificationManager::AddObserver( 87 void DriveNotificationManager::AddObserver(
89 DriveNotificationObserver* observer) { 88 DriveNotificationObserver* observer) {
90 observers_.AddObserver(observer); 89 observers_.AddObserver(observer);
91 } 90 }
(...skipping 29 matching lines...) Expand all
121 120
122 // Note that polling_timer_ is not a repeating timer. Restarting manually 121 // Note that polling_timer_ is not a repeating timer. Restarting manually
123 // here is better as XMPP may be received right before the polling timer is 122 // here is better as XMPP may be received right before the polling timer is
124 // fired (i.e. we don't notify observers twice in a row). 123 // fired (i.e. we don't notify observers twice in a row).
125 RestartPollingTimer(); 124 RestartPollingTimer();
126 } 125 }
127 126
128 void DriveNotificationManager::RegisterDriveNotifications() { 127 void DriveNotificationManager::RegisterDriveNotifications() {
129 DCHECK(!push_notification_enabled_); 128 DCHECK(!push_notification_enabled_);
130 129
131 ProfileSyncService* profile_sync_service = 130 invalidation::InvalidationService* invalidation_service =
132 ProfileSyncServiceFactory::GetForProfile(profile_); 131 invalidation::InvalidationServiceFactory::GetForProfile(profile_);
133 if (!profile_sync_service) 132 if (!invalidation_service)
134 return; 133 return;
135 134
136 profile_sync_service->RegisterInvalidationHandler(this); 135 invalidation_service->RegisterInvalidationHandler(this);
137 syncer::ObjectIdSet ids; 136 syncer::ObjectIdSet ids;
138 ids.insert(invalidation::ObjectId( 137 ids.insert(invalidation::ObjectId(
139 ipc::invalidation::ObjectSource::COSMO_CHANGELOG, 138 ipc::invalidation::ObjectSource::COSMO_CHANGELOG,
140 kDriveInvalidationObjectId)); 139 kDriveInvalidationObjectId));
141 profile_sync_service->UpdateRegisteredInvalidationIds(this, ids); 140 invalidation_service->UpdateRegisteredInvalidationIds(this, ids);
142 push_notification_registered_ = true; 141 push_notification_registered_ = true;
143 OnInvalidatorStateChange(profile_sync_service->GetInvalidatorState()); 142 OnInvalidatorStateChange(invalidation_service->GetInvalidatorState());
144 143
145 UMA_HISTOGRAM_BOOLEAN("Drive.PushNotificationRegistered", 144 UMA_HISTOGRAM_BOOLEAN("Drive.PushNotificationRegistered",
146 push_notification_registered_); 145 push_notification_registered_);
147 } 146 }
148 147
149 // static 148 // static
150 std::string DriveNotificationManager::NotificationSourceToString( 149 std::string DriveNotificationManager::NotificationSourceToString(
151 NotificationSource source) { 150 NotificationSource source) {
152 switch (source) { 151 switch (source) {
153 case NOTIFICATION_XMPP: 152 case NOTIFICATION_XMPP:
154 return "NOTIFICATION_XMPP"; 153 return "NOTIFICATION_XMPP";
155 case NOTIFICATION_POLLING: 154 case NOTIFICATION_POLLING:
156 return "NOTIFICATION_POLLING"; 155 return "NOTIFICATION_POLLING";
157 } 156 }
158 157
159 NOTREACHED(); 158 NOTREACHED();
160 return ""; 159 return "";
161 } 160 }
162 161
163 } // namespace google_apis 162 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/DEPS ('k') | chrome/browser/invalidation/fake_invalidation_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698