1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SYNC_GLUE_PREFERENCE_CHANGE_PROCESSOR_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_PREFERENCE_CHANGE_PROCESSOR_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "chrome/browser/prefs/pref_change_registrar.h" 12 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/sync/engine/syncapi.h" 14 #include "chrome/browser/sync/glue/change_processor.h" 15 #include "chrome/browser/sync/glue/sync_backend_host.h" 16 #include "content/common/notification_observer.h" 17 18 namespace browser_sync { 19 20 class PreferenceModelAssociator; 21 class UnrecoverableErrorHandler; 22 23 // This class is responsible for taking changes from the PrefService and 24 // applying them to the sync_api 'syncable' model, and vice versa. All 25 // operations and use of this class are from the UI thread. 26 class PreferenceChangeProcessor : public ChangeProcessor, 27 public NotificationObserver { 28 public: 29 PreferenceChangeProcessor(PreferenceModelAssociator* model_associator, 30 UnrecoverableErrorHandler* error_handler); 31 virtual ~PreferenceChangeProcessor(); 32 33 // NotificationObserver implementation. 34 // PrefService -> sync_api model change application. 35 virtual void Observe(NotificationType type, 36 const NotificationSource& source, 37 const NotificationDetails& details); 38 39 // sync_api model -> PrefService change application. 40 virtual void ApplyChangesFromSyncModel( 41 const sync_api::BaseTransaction* trans, 42 const sync_api::SyncManager::ChangeRecord* changes, 43 int change_count); 44 45 protected: 46 virtual void StartImpl(Profile* profile); 47 virtual void StopImpl(); 48 49 private: 50 Value* ReadPreference(sync_api::ReadNode* node, std::string* name); 51 52 void StartObserving(); 53 void StopObserving(); 54 55 // The model we are processing changes from. Non-NULL when |running_| is true. 56 PrefService* pref_service_; 57 58 // The two models should be associated according to this ModelAssociator. 59 PreferenceModelAssociator* model_associator_; 60 61 // Whether we are currently processing a preference change notification. 62 bool processing_pref_change_; 63 64 PrefChangeRegistrar registrar_; 65 66 DISALLOW_COPY_AND_ASSIGN(PreferenceChangeProcessor); 67 }; 68 69 } // namespace browser_sync 70 71 #endif // CHROME_BROWSER_SYNC_GLUE_PREFERENCE_CHANGE_PROCESSOR_H_ 72