OLD | NEW |
(Empty) | |
| 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_NON_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_NON_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| 7 #pragma once |
| 8 |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/synchronization/waitable_event.h" |
| 14 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 15 |
| 16 class Profile; |
| 17 class ProfileSyncService; |
| 18 class ProfileSyncFactory; |
| 19 |
| 20 namespace base { class TimeDelta; } |
| 21 namespace browser_sync { |
| 22 |
| 23 class AssociatorInterface; |
| 24 class ChangeProcessor; |
| 25 |
| 26 // TODO(zea): Rename frontend to UI (http://crbug.com/78833). |
| 27 // Implementation for datatypes that do not reside on the frontend thread |
| 28 // (UI thread). This is the same thread we perform initialization |
| 29 // on, so we don't have to worry about thread safety. The main start/stop |
| 30 // funtionality is implemented by default. Derived classes must implement: |
| 31 // type() |
| 32 // model_safe_group() |
| 33 // StartAssociationAsync() |
| 34 // CreateSyncComponents() |
| 35 // StopAssociationAsync() |
| 36 // RecordUnrecoverableError(...) |
| 37 // RecordAssociationTime(...); |
| 38 // RecordStartFailure(...); |
| 39 class NonFrontendDataTypeController : public DataTypeController { |
| 40 public: |
| 41 NonFrontendDataTypeController( |
| 42 ProfileSyncFactory* profile_sync_factory, |
| 43 Profile* profile); |
| 44 virtual ~NonFrontendDataTypeController(); |
| 45 |
| 46 // DataTypeController interface. |
| 47 virtual void Start(StartCallback* start_callback); |
| 48 virtual void Stop(); |
| 49 virtual syncable::ModelType type() const = 0; |
| 50 virtual browser_sync::ModelSafeGroup model_safe_group() const = 0; |
| 51 virtual std::string name() const; |
| 52 virtual State state() const; |
| 53 |
| 54 // UnrecoverableErrorHandler interface. |
| 55 // Note: this is performed on the datatype's thread. |
| 56 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, |
| 57 const std::string& message); |
| 58 protected: |
| 59 // For testing only. |
| 60 NonFrontendDataTypeController(); |
| 61 |
| 62 // Start any dependent services that need to be running before we can |
| 63 // associate models. The default implementation is a no-op. |
| 64 // Return value: |
| 65 // True - if models are ready and association can proceed. |
| 66 // False - if models are not ready. KickOffAssociation should be called |
| 67 // when the models are ready. Refer to Start(_) implementation. |
| 68 // Note: this is performed on the frontend (UI) thread. |
| 69 virtual bool StartModels(); |
| 70 |
| 71 // Post the association task to the thread the datatype lives on. |
| 72 // Note: this is performed on the frontend (UI) thread. |
| 73 // Return value: True if task posted successfully, False otherwise. |
| 74 virtual bool StartAssociationAsync() = 0; |
| 75 |
| 76 // Build sync components and associate models. |
| 77 // Note: this is performed on the datatype's thread. |
| 78 virtual void StartAssociation(); |
| 79 |
| 80 // Datatype specific creation of sync components. |
| 81 // Note: this is performed on the datatype's thread. |
| 82 virtual void CreateSyncComponents() = 0; |
| 83 |
| 84 // Start failed, make sure we record it, clean up state, and invoke the |
| 85 // callback on the frontend thread. |
| 86 // Note: this is performed on the datatype's thread. |
| 87 virtual void StartFailed(StartResult result, |
| 88 const tracked_objects::Location& location); |
| 89 |
| 90 // Start up complete, update the state and invoke the callback. |
| 91 // Note: this is performed on the datatype's thread. |
| 92 virtual void StartDone(DataTypeController::StartResult result, |
| 93 DataTypeController::State new_state, |
| 94 const tracked_objects::Location& location); |
| 95 |
| 96 // UI thread implementation of StartDone. |
| 97 virtual void StartDoneImpl(DataTypeController::StartResult result, |
| 98 DataTypeController::State new_state, |
| 99 const tracked_objects::Location& location); |
| 100 |
| 101 // Perform any DataType controller specific state cleanup before stopping |
| 102 // the datatype controller. The default implementation is a no-op. |
| 103 // Note: this is performed on the frontend (UI) thread. |
| 104 virtual void StopModels(); |
| 105 |
| 106 // Post the StopAssociation task to the thread the datatype lives on. |
| 107 // Note: this is performed on the frontend (UI) thread. |
| 108 // Return value: True if task posted successfully, False otherwise. |
| 109 virtual bool StopAssociationAsync() = 0; |
| 110 |
| 111 // Disassociate the models and destroy the sync components. |
| 112 // Note: this is performed on the datatype's thread. |
| 113 virtual void StopAssociation(); |
| 114 |
| 115 // Implementation of OnUnrecoverableError that lives on UI thread. |
| 116 virtual void OnUnrecoverableErrorImpl( |
| 117 const tracked_objects::Location& from_here, |
| 118 const std::string& message); |
| 119 |
| 120 // DataType specific histogram methods. Because histograms use static's, the |
| 121 // specific datatype controllers must implement this themselves. |
| 122 // Important: calling them on other threads can lead to memory corruption! |
| 123 // Record unrecoverable errors. Called on Datatype's thread. |
| 124 virtual void RecordUnrecoverableError( |
| 125 const tracked_objects::Location& from_here, |
| 126 const std::string& message) = 0; |
| 127 // Record association time. Called on Datatype's thread. |
| 128 virtual void RecordAssociationTime(base::TimeDelta time) = 0; |
| 129 // Record causes of start failure. Called on UI thread. |
| 130 virtual void RecordStartFailure(StartResult result) = 0; |
| 131 |
| 132 // Accessors and mutators used by derived classes. |
| 133 ProfileSyncFactory* profile_sync_factory() const; |
| 134 Profile* profile() const; |
| 135 ProfileSyncService* profile_sync_service() const; |
| 136 void set_state(State state); |
| 137 void set_model_associator(AssociatorInterface* associator); |
| 138 void set_change_processor(ChangeProcessor* change_processor); |
| 139 |
| 140 private: |
| 141 ProfileSyncFactory* const profile_sync_factory_; |
| 142 Profile* const profile_; |
| 143 ProfileSyncService* const profile_sync_service_; |
| 144 |
| 145 State state_; |
| 146 |
| 147 scoped_ptr<StartCallback> start_callback_; |
| 148 scoped_ptr<AssociatorInterface> model_associator_; |
| 149 scoped_ptr<ChangeProcessor> change_processor_; |
| 150 |
| 151 // Locks/Barriers for aborting association early. |
| 152 base::Lock abort_association_lock_; |
| 153 bool abort_association_; |
| 154 base::WaitableEvent abort_association_complete_; |
| 155 |
| 156 // Barrier to ensure that the datatype has been stopped on the DB thread |
| 157 // from the UI thread. |
| 158 base::WaitableEvent datatype_stopped_; |
| 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(NonFrontendDataTypeController); |
| 161 }; |
| 162 |
| 163 } // namespace browser_sync |
| 164 |
| 165 #endif // CHROME_BROWSER_SYNC_GLUE_NON_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
OLD | NEW |