1 // Copyright (c) 2006-2009 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_CHANGE_PROCESSOR_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ 7 #pragma once 8 9 #include "chrome/browser/sync/engine/syncapi.h" 10 #include "chrome/browser/sync/glue/sync_backend_host.h" 11 12 class Profile; 13 14 namespace browser_sync { 15 16 class ModelAssociator; 17 class UnrecoverableErrorHandler; 18 19 // An interface used to apply changes from the sync model to the browser's 20 // native model. This does not currently distinguish between model data types. 21 class ChangeProcessor { 22 public: ChangeProcessor(UnrecoverableErrorHandler * error_handler)23 explicit ChangeProcessor(UnrecoverableErrorHandler* error_handler) 24 : running_(false), error_handler_(error_handler), share_handle_(NULL) {} 25 virtual ~ChangeProcessor(); 26 27 // Call when the processor should accept changes from either provided model 28 // and apply them to the other. Both the chrome model and sync_api are 29 // expected to be initialized and loaded. You must have set a valid 30 // ModelAssociator and UnrecoverableErrorHandler before using this method, 31 // and the two models should be associated w.r.t the ModelAssociator provided. 32 // It is safe to call Start again after previously Stop()ing the processor. 33 // Subclasses can extract their associated chrome model from |profile| in 34 // |StartImpl|. 35 void Start(Profile* profile, sync_api::UserShare* share_handle); 36 void Stop(); 37 virtual bool IsRunning() const; 38 39 // Changes have been applied to the backend model and are ready to be 40 // applied to the frontend model. See syncapi.h for detailed instructions on 41 // how to interpret and process |changes|. 42 virtual void ApplyChangesFromSyncModel( 43 const sync_api::BaseTransaction* trans, 44 const sync_api::SyncManager::ChangeRecord* changes, 45 int change_count) = 0; 46 47 // The changes found in ApplyChangesFromSyncModel may be too slow to be 48 // performed while holding a [Read/Write]Transaction lock. This function 49 // is called once the lock is released and performs any slow I/O operations 50 // without unnecessarily slowing the UI. Note that not all datatypes need 51 // this, so we provide an empty default version. CommitChangesFromSyncModel()52 virtual void CommitChangesFromSyncModel() { } 53 54 protected: 55 // These methods are invoked by Start() and Stop() to do 56 // implementation-specific work. 57 virtual void StartImpl(Profile* profile) = 0; 58 virtual void StopImpl() = 0; 59 running()60 bool running() { return running_; } error_handler()61 UnrecoverableErrorHandler* error_handler() { return error_handler_; } share_handle()62 sync_api::UserShare* share_handle() { return share_handle_; } 63 64 private: 65 bool running_; // True if we have been told it is safe to process changes. 66 UnrecoverableErrorHandler* error_handler_; // Guaranteed to outlive us. 67 68 // The sync model we are processing changes from. Non-NULL when |running_| is 69 // true. 70 sync_api::UserShare* share_handle_; 71 72 DISALLOW_COPY_AND_ASSIGN(ChangeProcessor); 73 }; 74 75 } // namespace browser_sync 76 77 #endif // CHROME_BROWSER_SYNC_GLUE_CHANGE_PROCESSOR_H_ 78