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_SESSION_CHANGE_PROCESSOR_H_ 6#define CHROME_BROWSER_SYNC_GLUE_SESSION_CHANGE_PROCESSOR_H_ 7#pragma once 8 9#include "base/basictypes.h" 10#include "chrome/browser/sessions/session_backend.h" 11#include "chrome/browser/sessions/session_service.h" 12#include "chrome/browser/sync/engine/syncapi.h" 13#include "chrome/browser/sync/glue/change_processor.h" 14#include "content/common/notification_observer.h" 15#include "content/common/notification_registrar.h" 16#include "content/common/notification_type.h" 17 18class NotificationDetails; 19class NotificationSource; 20class Profile; 21 22namespace browser_sync { 23 24class SessionModelAssociator; 25class UnrecoverableErrorHandler; 26 27// This class is responsible for taking changes from the 28// SessionService and applying them to the sync_api 'syncable' 29// model, and vice versa. All operations and use of this class are 30// from the UI thread. 31class SessionChangeProcessor : public ChangeProcessor, 32 public NotificationObserver { 33 public: 34 // Does not take ownership of either argument. 35 SessionChangeProcessor( 36 UnrecoverableErrorHandler* error_handler, 37 SessionModelAssociator* session_model_associator); 38 SessionChangeProcessor( 39 UnrecoverableErrorHandler* error_handler, 40 SessionModelAssociator* session_model_associator, 41 bool setup_for_test); 42 virtual ~SessionChangeProcessor(); 43 44 // NotificationObserver implementation. 45 // BrowserSessionProvider -> sync_api model change application. 46 virtual void Observe(NotificationType type, 47 const NotificationSource& source, 48 const NotificationDetails& details); 49 50 // ChangeProcessor implementation. 51 // sync_api model -> BrowserSessionProvider change application. 52 virtual void ApplyChangesFromSyncModel( 53 const sync_api::BaseTransaction* trans, 54 const sync_api::SyncManager::ChangeRecord* changes, 55 int change_count); 56 57 protected: 58 // ChangeProcessor implementation. 59 virtual void StartImpl(Profile* profile); 60 virtual void StopImpl(); 61 private: 62 void StartObserving(); 63 void StopObserving(); 64 SessionModelAssociator* session_model_associator_; 65 NotificationRegistrar notification_registrar_; 66 67 // Owner of the SessionService. Non-NULL iff |running()| is true. 68 Profile* profile_; 69 70 // To bypass some checks/codepaths not applicable in tests. 71 bool setup_for_test_; 72 73 DISALLOW_COPY_AND_ASSIGN(SessionChangeProcessor); 74}; 75 76} // namespace browser_sync 77 78#endif // CHROME_BROWSER_SYNC_GLUE_SESSION_CHANGE_PROCESSOR_H_ 79