diff options
5 files changed, 48 insertions, 4 deletions
diff --git a/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.cc b/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.cc index 07fb3be..21361f1 100644 --- a/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.cc +++ b/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.cc @@ -129,8 +129,10 @@ bool PopulateJSDataListFromSync( } // namespace SyncedNotificationsShim::SyncedNotificationsShim( - const EventLauncher& event_launcher) - : event_launcher_(event_launcher) { + const EventLauncher& event_launcher, + const base::Closure& refresh_request) + : event_launcher_(event_launcher), + refresh_request_(refresh_request) { } SyncedNotificationsShim::~SyncedNotificationsShim() { @@ -240,6 +242,12 @@ bool SyncedNotificationsShim::SetRenderContext( syncer::SyncError error = notifications_change_processor_->UpdateDataTypeContext( syncer::SYNCED_NOTIFICATIONS, sync_refresh_status, new_context); + + if (sync_refresh_status == syncer::SyncChangeProcessor::REFRESH_NEEDED && + !refresh_request_.is_null()) { + refresh_request_.Run(); + } + return !error.IsSet(); } diff --git a/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.h b/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.h index 7e75718..9d225ce 100644 --- a/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.h +++ b/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.h @@ -23,7 +23,8 @@ class SyncedNotificationsShim : public syncer::SyncableService { // Callback for firing extension events. typedef base::Callback<void(scoped_ptr<extensions::Event>)> EventLauncher; - explicit SyncedNotificationsShim(const EventLauncher& event_launcher); + explicit SyncedNotificationsShim(const EventLauncher& event_launcher, + const base::Closure& refresh_request); virtual ~SyncedNotificationsShim(); // SyncableService interface. @@ -58,6 +59,9 @@ class SyncedNotificationsShim : public syncer::SyncableService { // Callback to trigger firing extension events. EventLauncher event_launcher_; + // Callback to trigger synced notification refresh. + base::Closure refresh_request_; + // The sync change processors, initialized via MergeDataAndStartSyncing. scoped_ptr<syncer::SyncChangeProcessor> notifications_change_processor_; scoped_ptr<syncer::SyncChangeProcessor> app_info_change_processor_; diff --git a/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim_unittest.cc b/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim_unittest.cc index 3a635c7..5f77655 100644 --- a/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim_unittest.cc +++ b/chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim_unittest.cc @@ -81,6 +81,9 @@ class SyncedNotificationsShimTest : public testing::Test { // Transfers ownership of the last event received. scoped_ptr<Event> GetLastEvent(); + // Records that a refresh has been requested. + void RequestRefresh(); + SyncedNotificationsShim* shim() { return &shim_; } syncer::FakeSyncChangeProcessor* notification_processor() { return notification_processor_; @@ -88,6 +91,7 @@ class SyncedNotificationsShimTest : public testing::Test { syncer::FakeSyncChangeProcessor* app_info_processor() { return app_info_processor_; } + bool refresh_requested() const { return refresh_requested_; } private: void EventCallback(scoped_ptr<Event> event); @@ -100,13 +104,19 @@ class SyncedNotificationsShimTest : public testing::Test { // The last event fired by the shim. scoped_ptr<Event> last_event_fired_; + + // Whether a refresh has been requested; + bool refresh_requested_; }; SyncedNotificationsShimTest::SyncedNotificationsShimTest() : shim_(base::Bind(&SyncedNotificationsShimTest::EventCallback, + base::Unretained(this)), + base::Bind(&SyncedNotificationsShimTest::RequestRefresh, base::Unretained(this))), notification_processor_(NULL), - app_info_processor_(NULL) {} + app_info_processor_(NULL), + refresh_requested_(false) {} SyncedNotificationsShimTest::~SyncedNotificationsShimTest() {} @@ -115,6 +125,11 @@ void SyncedNotificationsShimTest::EventCallback(scoped_ptr<Event> event) { last_event_fired_ = event.Pass(); } +void SyncedNotificationsShimTest::RequestRefresh() { + ASSERT_FALSE(refresh_requested_); + refresh_requested_ = true; +} + scoped_ptr<Event> SyncedNotificationsShimTest::GetLastEvent() { return last_event_fired_.Pass(); } @@ -320,12 +335,14 @@ TEST_F(SyncedNotificationsShimTest, SetRenderContext) { const std::string kContext = "context"; EXPECT_FALSE(shim()->SetRenderContext( synced_notifications_private::REFRESH_REQUEST_REFRESH_NEEDED, kContext)); + EXPECT_FALSE(refresh_requested()); StartSync(); EXPECT_TRUE(shim()->SetRenderContext( synced_notifications_private::REFRESH_REQUEST_REFRESH_NEEDED, kContext)); EXPECT_EQ(kContext, notification_processor()->context()); + EXPECT_TRUE(refresh_requested()); } } // namespace diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc index 613a178..c85fa07 100644 --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc @@ -8,8 +8,10 @@ #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" +#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/api/synced_notifications_private/synced_notifications_shim.h" #include "chrome/browser/profiles/profile.h" +#include "content/public/browser/notification_service.h" #include "extensions/browser/event_router.h" namespace notifier { @@ -19,6 +21,8 @@ ChromeNotifierService::ChromeNotifierService(Profile* profile) weak_ptr_factory_(this) { synced_notifications_shim_.reset(new SyncedNotificationsShim( base::Bind(&ChromeNotifierService::FireSyncJSEvent, + weak_ptr_factory_.GetWeakPtr()), + base::Bind(&ChromeNotifierService::NotifyRefreshNeeded, weak_ptr_factory_.GetWeakPtr()))); } @@ -40,4 +44,12 @@ void ChromeNotifierService::FireSyncJSEvent( extensions::EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); } +void ChromeNotifierService::NotifyRefreshNeeded() { + const syncer::ModelTypeSet types(syncer::SYNCED_NOTIFICATIONS); + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, + content::Source<Profile>(profile_), + content::Details<const syncer::ModelTypeSet>(&types)); +} + } // namespace notifier diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h index ad0ec65..15a9fa3 100644 --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_service.h @@ -37,6 +37,9 @@ class ChromeNotifierService : public KeyedService { // Helper method for firing JS events triggered by sync. void FireSyncJSEvent(scoped_ptr<extensions::Event> event); + // Helper method for trigger synced notification refreshes. + void NotifyRefreshNeeded(); + // The owning profile. Profile* const profile_; |