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