| OLD | NEW |
| 1 // Copyright (c) 2011 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_FRONTEND_DATA_TYPE_CONTROLLER_H__ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| 6 #define CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ | 6 #define CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chrome/browser/sync/glue/data_type_controller.h" | 13 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 14 | 14 |
| 15 class Profile; | 15 class Profile; |
| 16 class ProfileSyncService; | 16 class ProfileSyncService; |
| 17 class ProfileSyncFactory; | 17 class ProfileSyncFactory; |
| 18 | 18 |
| 19 namespace base { class TimeDelta; } | 19 namespace base { class TimeDelta; } |
| 20 namespace browser_sync { | 20 namespace browser_sync { |
| 21 | 21 |
| 22 class AssociatorInterface; | 22 class AssociatorInterface; |
| 23 class ChangeProcessor; | 23 class ChangeProcessor; |
| 24 | 24 |
| 25 // TODO(zea): have naming and style match NonFrontendDataTypeController. |
| 26 // TODO(zea): Rename frontend to UI (http://crbug.com/78833). |
| 25 // Implementation for datatypes that reside on the frontend thread | 27 // Implementation for datatypes that reside on the frontend thread |
| 26 // (UI thread). This is the same thread we perform initialization on, so we | 28 // (UI thread). This is the same thread we perform initialization on, so we |
| 27 // don't have to worry about thread safety. The main start/stop funtionality is | 29 // don't have to worry about thread safety. The main start/stop funtionality is |
| 28 // implemented by default. | 30 // implemented by default. |
| 29 // Derived classes must implement (at least): | 31 // Derived classes must implement (at least): |
| 30 // syncable::ModelType type() const | 32 // syncable::ModelType type() const |
| 31 // void CreateSyncComponents(); | 33 // void CreateSyncComponents(); |
| 32 // void RecordUnrecoverableError( | 34 // void RecordUnrecoverableError( |
| 33 // const tracked_objects::Location& from_here, | 35 // const tracked_objects::Location& from_here, |
| 34 // const std::string& message); | 36 // const std::string& message); |
| 35 // void RecordAssociationTime(base::TimeDelta time); | 37 // void RecordAssociationTime(base::TimeDelta time); |
| 36 // void RecordStartFailure(StartResult result); | 38 // void RecordStartFailure(StartResult result); |
| 37 class FrontendDataTypeController : public DataTypeController { | 39 class FrontendDataTypeController : public DataTypeController { |
| 38 public: | 40 public: |
| 39 FrontendDataTypeController( | 41 FrontendDataTypeController( |
| 40 ProfileSyncFactory* profile_sync_factory, | 42 ProfileSyncFactory* profile_sync_factory, |
| 41 Profile* profile, | 43 Profile* profile, |
| 42 ProfileSyncService* sync_service); | 44 ProfileSyncService* sync_service); |
| 43 virtual ~FrontendDataTypeController(); | 45 virtual ~FrontendDataTypeController(); |
| 44 | 46 |
| 45 // DataTypeController interface. | 47 // DataTypeController interface. |
| 46 virtual void Start(StartCallback* start_callback); | 48 virtual void Start(StartCallback* start_callback); |
| 47 | |
| 48 virtual void Stop(); | 49 virtual void Stop(); |
| 49 | |
| 50 virtual syncable::ModelType type() const = 0; | 50 virtual syncable::ModelType type() const = 0; |
| 51 | |
| 52 virtual browser_sync::ModelSafeGroup model_safe_group() const; | 51 virtual browser_sync::ModelSafeGroup model_safe_group() const; |
| 53 | |
| 54 virtual std::string name() const; | 52 virtual std::string name() const; |
| 55 | |
| 56 virtual State state() const; | 53 virtual State state() const; |
| 57 | 54 |
| 58 // UnrecoverableErrorHandler interface. | 55 // UnrecoverableErrorHandler interface. |
| 59 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, | 56 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, |
| 60 const std::string& message); | 57 const std::string& message); |
| 61 protected: | 58 protected: |
| 62 // For testing only. | 59 // For testing only. |
| 63 FrontendDataTypeController(); | 60 FrontendDataTypeController(); |
| 64 | 61 |
| 65 // Kick off any dependent services that need to be running before we can | 62 // Kick off any dependent services that need to be running before we can |
| 66 // associate models. The default implementation is a no-op. | 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. Associate() should be called when the |
| 67 // models are ready. Refer to Start(_) implementation. |
| 67 virtual bool StartModels(); | 68 virtual bool StartModels(); |
| 68 | 69 |
| 69 // Build sync components and associate models. | 70 // Build sync components and associate models. |
| 71 // Return value: |
| 72 // True - if association was successful. FinishStart should have been |
| 73 // invoked. |
| 74 // False - if association failed. StartFailed should have been invoked. |
| 70 virtual bool Associate(); | 75 virtual bool Associate(); |
| 71 | 76 |
| 77 // Datatype specific creation of sync components. |
| 78 virtual void CreateSyncComponents() = 0; |
| 79 |
| 72 // Perform any DataType controller specific state cleanup before stopping | 80 // Perform any DataType controller specific state cleanup before stopping |
| 73 // the datatype controller. The default implementation is a no-op. | 81 // the datatype controller. The default implementation is a no-op. |
| 74 virtual void CleanupState(); | 82 virtual void CleanUpState(); |
| 83 |
| 84 // Cleans up state and calls callback when start fails. |
| 85 virtual void StartFailed(StartResult result, |
| 86 const tracked_objects::Location& from_here); |
| 75 | 87 |
| 76 // Helper method to run the stashed start callback with a given result. | 88 // Helper method to run the stashed start callback with a given result. |
| 77 virtual void FinishStart(StartResult result, | 89 virtual void FinishStart(StartResult result, |
| 78 const tracked_objects::Location& from_here); | 90 const tracked_objects::Location& from_here); |
| 79 | 91 |
| 80 // Cleans up state and calls callback when start fails. | |
| 81 virtual void StartFailed(StartResult result, | |
| 82 const tracked_objects::Location& from_here); | |
| 83 | |
| 84 // Datatype specific creation of sync components. | |
| 85 virtual void CreateSyncComponents() = 0; | |
| 86 | |
| 87 // DataType specific histogram methods. Because histograms use static's, the | 92 // DataType specific histogram methods. Because histograms use static's, the |
| 88 // specific datatype controllers must implement this themselves. | 93 // specific datatype controllers must implement this themselves. |
| 89 // Record unrecoverable errors. | 94 // Record unrecoverable errors. |
| 90 virtual void RecordUnrecoverableError( | 95 virtual void RecordUnrecoverableError( |
| 91 const tracked_objects::Location& from_here, | 96 const tracked_objects::Location& from_here, |
| 92 const std::string& message) = 0; | 97 const std::string& message) = 0; |
| 93 // Record association time. | 98 // Record association time. |
| 94 virtual void RecordAssociationTime(base::TimeDelta time) = 0; | 99 virtual void RecordAssociationTime(base::TimeDelta time) = 0; |
| 95 // Record causes of start failure. | 100 // Record causes of start failure. |
| 96 virtual void RecordStartFailure(StartResult result) = 0; | 101 virtual void RecordStartFailure(StartResult result) = 0; |
| 97 | 102 |
| 98 ProfileSyncFactory* const profile_sync_factory_; | 103 ProfileSyncFactory* const profile_sync_factory_; |
| 99 Profile* const profile_; | 104 Profile* const profile_; |
| 100 ProfileSyncService* const sync_service_; | 105 ProfileSyncService* const sync_service_; |
| 101 | 106 |
| 102 State state_; | 107 State state_; |
| 103 | 108 |
| 104 scoped_ptr<StartCallback> start_callback_; | 109 scoped_ptr<StartCallback> start_callback_; |
| 105 scoped_ptr<AssociatorInterface> model_associator_; | 110 scoped_ptr<AssociatorInterface> model_associator_; |
| 106 scoped_ptr<ChangeProcessor> change_processor_; | 111 scoped_ptr<ChangeProcessor> change_processor_; |
| 107 | 112 |
| 108 DISALLOW_COPY_AND_ASSIGN(FrontendDataTypeController); | 113 DISALLOW_COPY_AND_ASSIGN(FrontendDataTypeController); |
| 109 }; | 114 }; |
| 110 | 115 |
| 111 } // namespace browser_sync | 116 } // namespace browser_sync |
| 112 | 117 |
| 113 #endif // CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ | 118 #endif // CHROME_BROWSER_SYNC_GLUE_FRONTEND_DATA_TYPE_CONTROLLER_H__ |
| OLD | NEW |