| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 SYNC_INTERNAL_API_JS_MUTATION_EVENT_OBSERVER_H_ | 5 #ifndef SYNC_INTERNAL_API_JS_MUTATION_EVENT_OBSERVER_H_ |
| 6 #define SYNC_INTERNAL_API_JS_MUTATION_EVENT_OBSERVER_H_ | 6 #define SYNC_INTERNAL_API_JS_MUTATION_EVENT_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "sync/internal_api/public/sync_manager.h" | 14 #include "sync/internal_api/public/sync_manager.h" |
| 15 #include "sync/internal_api/public/util/weak_handle.h" | 15 #include "sync/internal_api/public/util/weak_handle.h" |
| 16 #include "sync/syncable/transaction_observer.h" | 16 #include "sync/syncable/transaction_observer.h" |
| 17 | 17 |
| 18 namespace tracked_objects { | 18 namespace tracked_objects { |
| 19 class Location; | 19 class Location; |
| 20 } // namespace tracked_objects | 20 } // namespace tracked_objects |
| 21 | 21 |
| 22 namespace syncer { | 22 namespace syncer { |
| 23 | 23 |
| 24 class JsEventDetails; | 24 class JsEventDetails; |
| 25 class JsEventHandler; | 25 class JsEventHandler; |
| 26 | 26 |
| 27 // Observes all change- and transaction-related events and routes a | 27 // Observes all change- and transaction-related events and routes a |
| 28 // summarized version to a JsEventHandler. | 28 // summarized version to a JsEventHandler. |
| 29 class JsMutationEventObserver | 29 class JsMutationEventObserver |
| 30 : public syncer::SyncManager::ChangeObserver, | 30 : public SyncManager::ChangeObserver, |
| 31 public syncable::TransactionObserver, | 31 public syncable::TransactionObserver, |
| 32 public base::NonThreadSafe { | 32 public base::NonThreadSafe { |
| 33 public: | 33 public: |
| 34 JsMutationEventObserver(); | 34 JsMutationEventObserver(); |
| 35 | 35 |
| 36 virtual ~JsMutationEventObserver(); | 36 virtual ~JsMutationEventObserver(); |
| 37 | 37 |
| 38 base::WeakPtr<JsMutationEventObserver> AsWeakPtr(); | 38 base::WeakPtr<JsMutationEventObserver> AsWeakPtr(); |
| 39 | 39 |
| 40 void InvalidateWeakPtrs(); | 40 void InvalidateWeakPtrs(); |
| 41 | 41 |
| 42 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler); | 42 void SetJsEventHandler(const WeakHandle<JsEventHandler>& event_handler); |
| 43 | 43 |
| 44 // syncer::SyncManager::ChangeObserver implementation. | 44 // SyncManager::ChangeObserver implementation. |
| 45 virtual void OnChangesApplied( | 45 virtual void OnChangesApplied( |
| 46 syncer::ModelType model_type, | 46 ModelType model_type, |
| 47 int64 write_transaction_id, | 47 int64 write_transaction_id, |
| 48 const syncer::ImmutableChangeRecordList& changes) OVERRIDE; | 48 const ImmutableChangeRecordList& changes) OVERRIDE; |
| 49 virtual void OnChangesComplete(syncer::ModelType model_type) OVERRIDE; | 49 virtual void OnChangesComplete(ModelType model_type) OVERRIDE; |
| 50 | 50 |
| 51 // syncable::TransactionObserver implementation. | 51 // syncable::TransactionObserver implementation. |
| 52 virtual void OnTransactionWrite( | 52 virtual void OnTransactionWrite( |
| 53 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, | 53 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, |
| 54 syncer::ModelTypeSet models_with_changes) OVERRIDE; | 54 ModelTypeSet models_with_changes) OVERRIDE; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 base::WeakPtrFactory<JsMutationEventObserver> weak_ptr_factory_; | 57 base::WeakPtrFactory<JsMutationEventObserver> weak_ptr_factory_; |
| 58 WeakHandle<JsEventHandler> event_handler_; | 58 WeakHandle<JsEventHandler> event_handler_; |
| 59 | 59 |
| 60 void HandleJsEvent( | 60 void HandleJsEvent( |
| 61 const tracked_objects::Location& from_here, | 61 const tracked_objects::Location& from_here, |
| 62 const std::string& name, const JsEventDetails& details); | 62 const std::string& name, const JsEventDetails& details); |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(JsMutationEventObserver); | 64 DISALLOW_COPY_AND_ASSIGN(JsMutationEventObserver); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 } // namespace syncer | 67 } // namespace syncer |
| 68 | 68 |
| 69 #endif // SYNC_INTERNAL_API_JS_MUTATION_EVENT_OBSERVER_H_ | 69 #endif // SYNC_INTERNAL_API_JS_MUTATION_EVENT_OBSERVER_H_ |
| OLD | NEW |