 Chromium Code Reviews
 Chromium Code Reviews Issue 573553004:
  Eliminate NOTIFICATION_HISTORY_LOADED notification  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 573553004:
  Eliminate NOTIFICATION_HISTORY_LOADED notification  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| Index: chrome/browser/sync/glue/bookmark_data_type_controller.cc | 
| diff --git a/chrome/browser/sync/glue/bookmark_data_type_controller.cc b/chrome/browser/sync/glue/bookmark_data_type_controller.cc | 
| index 9e9da929d0b0829a95c485f6dff5812b09d52234..fae3946a544b8b1d1dd952f9b27339a4f063a816 100644 | 
| --- a/chrome/browser/sync/glue/bookmark_data_type_controller.cc | 
| +++ b/chrome/browser/sync/glue/bookmark_data_type_controller.cc | 
| @@ -16,6 +16,7 @@ | 
| #include "components/bookmarks/browser/bookmark_model.h" | 
| #include "content/public/browser/browser_thread.h" | 
| #include "content/public/browser/notification_details.h" | 
| +#include "content/public/browser/notification_service.h" | 
| #include "content/public/browser/notification_source.h" | 
| using content::BrowserThread; | 
| @@ -33,58 +34,44 @@ BookmarkDataTypeController::BookmarkDataTypeController( | 
| profile, | 
| sync_service), | 
| bookmark_model_(NULL), | 
| - installed_bookmark_observer_(false) { | 
| + history_service_observer_(this), | 
| + bookmark_model_observer_(this) { | 
| + notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 
| 
sdefresne
2014/11/07 16:39:42
Another option would be to add a HistoryServiceBei
 
nshaik
2014/11/07 23:45:32
Done. For now I am not listening to this notificat
 | 
| + content::NotificationService::AllSources()); | 
| } | 
| syncer::ModelType BookmarkDataTypeController::type() const { | 
| return syncer::BOOKMARKS; | 
| } | 
| +BookmarkDataTypeController::~BookmarkDataTypeController() { | 
| +} | 
| + | 
| void BookmarkDataTypeController::Observe( | 
| int type, | 
| const content::NotificationSource& source, | 
| const content::NotificationDetails& details) { | 
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| - DCHECK_EQ(state_, MODEL_STARTING); | 
| - DCHECK_EQ(chrome::NOTIFICATION_HISTORY_LOADED, type); | 
| - | 
| - if (!DependentsLoaded()) | 
| - return; | 
| - | 
| - bookmark_model_->RemoveObserver(this); | 
| - installed_bookmark_observer_ = false; | 
| - | 
| - registrar_.RemoveAll(); | 
| - OnModelLoaded(); | 
| -} | 
| + DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | 
| -BookmarkDataTypeController::~BookmarkDataTypeController() { | 
| - if (installed_bookmark_observer_ && bookmark_model_) { | 
| - DCHECK(profile_); | 
| - bookmark_model_->RemoveObserver(this); | 
| - } | 
| + CleanUpState(); | 
| } | 
| bool BookmarkDataTypeController::StartModels() { | 
| bookmark_model_ = BookmarkModelFactory::GetForProfile(profile_); | 
| if (!DependentsLoaded()) { | 
| - bookmark_model_->AddObserver(this); | 
| - installed_bookmark_observer_ = true; | 
| - | 
| - registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, | 
| - content::Source<Profile>(sync_service_->profile())); | 
| + bookmark_model_observer_.Add(bookmark_model_); | 
| + HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 
| + profile_, Profile::EXPLICIT_ACCESS); | 
| + history_service_observer_.Add(history_service); | 
| return false; | 
| } | 
| return true; | 
| } | 
| -// Cleanup for our extra registrar usage. | 
| void BookmarkDataTypeController::CleanUpState() { | 
| - registrar_.RemoveAll(); | 
| - if (bookmark_model_ && installed_bookmark_observer_) { | 
| - bookmark_model_->RemoveObserver(this); | 
| - installed_bookmark_observer_ = false; | 
| - } | 
| + history_service_observer_.RemoveAll(); | 
| + bookmark_model_observer_.RemoveAll(); | 
| } | 
| void BookmarkDataTypeController::CreateSyncComponents() { | 
| @@ -101,19 +88,18 @@ void BookmarkDataTypeController::BookmarkModelChanged() { | 
| void BookmarkDataTypeController::BookmarkModelLoaded(BookmarkModel* model, | 
| bool ids_reassigned) { | 
| DCHECK(model->loaded()); | 
| - model->RemoveObserver(this); | 
| - installed_bookmark_observer_ = false; | 
| + bookmark_model_observer_.RemoveAll(); | 
| if (!DependentsLoaded()) | 
| return; | 
| - registrar_.RemoveAll(); | 
| + history_service_observer_.RemoveAll(); | 
| OnModelLoaded(); | 
| } | 
| void BookmarkDataTypeController::BookmarkModelBeingDeleted( | 
| BookmarkModel* model) { | 
| - installed_bookmark_observer_ = false; | 
| + CleanUpState(); | 
| } | 
| // Check that both the bookmark model and the history service (for favicons) | 
| @@ -131,4 +117,17 @@ bool BookmarkDataTypeController::DependentsLoaded() { | 
| return true; | 
| } | 
| +void BookmarkDataTypeController::OnHistoryServiceLoaded( | 
| + HistoryService* service) { | 
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| + DCHECK_EQ(state_, MODEL_STARTING); | 
| + history_service_observer_.RemoveAll(); | 
| + | 
| + if (!DependentsLoaded()) | 
| + return; | 
| + | 
| + bookmark_model_observer_.RemoveAll(); | 
| + OnModelLoaded(); | 
| +} | 
| + | 
| } // namespace browser_sync |