extension_change_processor.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
1// Copyright (c) 2010 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_EXTENSION_CHANGE_PROCESSOR_H_ 6#define CHROME_BROWSER_SYNC_GLUE_EXTENSION_CHANGE_PROCESSOR_H_ 7 8#include "base/basictypes.h" 9#include "chrome/browser/sync/engine/syncapi.h" 10#include "chrome/browser/sync/glue/change_processor.h" 11#include "chrome/common/notification_observer.h" 12#include "chrome/common/notification_type.h" 13#include "chrome/common/notification_registrar.h" 14 15class NotificationDetails; 16class NotificationSource; 17class Profile; 18 19namespace browser_sync { 20 21class ExtensionModelAssociator; 22class UnrecoverableErrorHandler; 23 24// This class is responsible for taking changes from the 25// ExtensionService and applying them to the sync_api 'syncable' 26// model, and vice versa. All operations and use of this class are 27// from the UI thread. 28class ExtensionChangeProcessor : public ChangeProcessor, 29 public NotificationObserver { 30 public: 31 // Does not take ownership of either argument. 32 // 33 // TODO(akalin): Create a Delegate interface and take that instead. 34 // That'll enable us to unit test this class. 35 ExtensionChangeProcessor( 36 UnrecoverableErrorHandler* error_handler, 37 ExtensionModelAssociator* extension_model_associator); 38 virtual ~ExtensionChangeProcessor(); 39 40 // NotificationObserver implementation. 41 // BrowserExtensionProvider -> sync_api model change application. 42 virtual void Observe(NotificationType type, 43 const NotificationSource& source, 44 const NotificationDetails& details); 45 46 // ChangeProcessor implementation. 47 // sync_api model -> BrowserExtensionProvider change application. 48 virtual void ApplyChangesFromSyncModel( 49 const sync_api::BaseTransaction* trans, 50 const sync_api::SyncManager::ChangeRecord* changes, 51 int change_count); 52 53 protected: 54 // ChangeProcessor implementation. 55 virtual void StartImpl(Profile* profile); 56 virtual void StopImpl(); 57 58 private: 59 void StartObserving(); 60 void StopObserving(); 61 62 ExtensionModelAssociator* extension_model_associator_; 63 NotificationRegistrar notification_registrar_; 64 // Owner of the ExtensionService. Non-NULL iff |running()| is true. 65 Profile* profile_; 66 67 DISALLOW_COPY_AND_ASSIGN(ExtensionChangeProcessor); 68}; 69 70} // namespace browser_sync 71 72#endif // CHROME_BROWSER_SYNC_GLUE_EXTENSION_CHANGE_PROCESSOR_H_ 73