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_TYPED_URL_DATA_TYPE_CONTROLLER_H__ 6 #define CHROME_BROWSER_SYNC_GLUE_TYPED_URL_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 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "content/browser/cancelable_request.h" 17 #include "content/common/notification_observer.h" 18 #include "content/common/notification_registrar.h" 19 #include "content/common/notification_type.h" 20 21 class NotificationSource; 22 class NotificationDetails; 23 class HistoryService; 24 class Profile; 25 class ProfileSyncFactory; 26 class ProfileSyncService; 27 28 namespace history { 29 class HistoryBackend; 30 } 31 32 namespace browser_sync { 33 34 class AssociatorInterface; 35 class ChangeProcessor; 36 class ControlTask; 37 38 // A class that manages the startup and shutdown of typed_url sync. 39 class TypedUrlDataTypeController : public DataTypeController, 40 public NotificationObserver, 41 public CancelableRequestConsumerBase { 42 public: 43 TypedUrlDataTypeController( 44 ProfileSyncFactory* profile_sync_factory, 45 Profile* profile, 46 ProfileSyncService* sync_service); 47 virtual ~TypedUrlDataTypeController(); 48 49 // DataTypeController implementation 50 virtual void Start(StartCallback* start_callback); 51 52 virtual void Stop(); 53 54 virtual bool enabled(); 55 56 virtual syncable::ModelType type() const; 57 58 virtual browser_sync::ModelSafeGroup model_safe_group() const; 59 60 virtual std::string name() const; 61 62 virtual State state() const; 63 64 // UnrecoverableHandler implementation 65 virtual void OnUnrecoverableError(const tracked_objects::Location& from_here, 66 const std::string& message); 67 68 // NotificationObserver implementation. 69 virtual void Observe(NotificationType type, 70 const NotificationSource& source, 71 const NotificationDetails& details); 72 73 // CancelableRequestConsumerBase implementation. 74 virtual void OnRequestAdded(CancelableRequestProvider* provider, 75 CancelableRequestProvider::Handle handle) {} 76 77 virtual void OnRequestRemoved(CancelableRequestProvider* provider, 78 CancelableRequestProvider::Handle handle) {} 79 80 virtual void WillExecute(CancelableRequestProvider* provider, 81 CancelableRequestProvider::Handle handle) {} 82 83 virtual void DidExecute(CancelableRequestProvider* provider, 84 CancelableRequestProvider::Handle handle) {} 85 86 private: 87 friend class ControlTask; 88 void StartImpl(history::HistoryBackend* backend); 89 void StartDone(StartResult result, State state); 90 void StartDoneImpl(StartResult result, State state); 91 void StopImpl(); 92 void StartFailed(StartResult result); 93 void OnUnrecoverableErrorImpl(const tracked_objects::Location& from_here, 94 const std::string& message); 95 96 void set_state(State state) { 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 98 state_ = state; 99 } 100 101 ProfileSyncFactory* profile_sync_factory_; 102 Profile* profile_; 103 ProfileSyncService* sync_service_; 104 State state_; 105 106 scoped_ptr<AssociatorInterface> model_associator_; 107 scoped_ptr<ChangeProcessor> change_processor_; 108 scoped_ptr<StartCallback> start_callback_; 109 scoped_refptr<HistoryService> history_service_; 110 111 NotificationRegistrar notification_registrar_; 112 113 base::Lock abort_association_lock_; 114 bool abort_association_; 115 base::WaitableEvent abort_association_complete_; 116 117 // Barrier to ensure that the datatype has been stopped on the DB thread 118 // from the UI thread. 119 base::WaitableEvent datatype_stopped_; 120 121 DISALLOW_COPY_AND_ASSIGN(TypedUrlDataTypeController); 122 }; 123 124 } // namespace browser_sync 125 126 #endif // CHROME_BROWSER_SYNC_GLUE_TYPED_URL_DATA_TYPE_CONTROLLER_H__ 127