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_TYPED_URL_DATA_TYPE_CONTROLLER_H__ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_TYPED_URL_DATA_TYPE_CONTROLLER_H__ |
6 #define 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 | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | |
12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
13 #include "base/synchronization/waitable_event.h" | 12 #include "chrome/browser/sync/glue/non_frontend_data_type_controller.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" | 13 #include "content/browser/cancelable_request.h" |
17 #include "content/common/notification_observer.h" | 14 #include "content/common/notification_observer.h" |
18 #include "content/common/notification_registrar.h" | 15 #include "content/common/notification_registrar.h" |
19 #include "content/common/notification_type.h" | 16 #include "content/common/notification_type.h" |
20 | 17 |
21 class NotificationSource; | 18 class NotificationSource; |
22 class NotificationDetails; | 19 class NotificationDetails; |
23 class HistoryService; | 20 class HistoryService; |
24 class Profile; | |
25 class ProfileSyncFactory; | |
26 class ProfileSyncService; | |
27 | 21 |
28 namespace history { | 22 namespace history { |
29 class HistoryBackend; | 23 class HistoryBackend; |
30 } | 24 } |
31 | 25 |
32 namespace browser_sync { | 26 namespace browser_sync { |
33 | 27 |
34 class AssociatorInterface; | |
35 class ChangeProcessor; | |
36 class ControlTask; | 28 class ControlTask; |
37 | 29 |
38 // A class that manages the startup and shutdown of typed_url sync. | 30 // A class that manages the startup and shutdown of typed_url sync. |
39 class TypedUrlDataTypeController : public DataTypeController, | 31 class TypedUrlDataTypeController : public NonFrontendDataTypeController, |
40 public NotificationObserver, | 32 public NotificationObserver, |
41 public CancelableRequestConsumerBase { | 33 public CancelableRequestConsumerBase { |
42 public: | 34 public: |
43 TypedUrlDataTypeController( | 35 TypedUrlDataTypeController( |
44 ProfileSyncFactory* profile_sync_factory, | 36 ProfileSyncFactory* profile_sync_factory, |
45 Profile* profile, | 37 Profile* profile); |
46 ProfileSyncService* sync_service); | |
47 virtual ~TypedUrlDataTypeController(); | 38 virtual ~TypedUrlDataTypeController(); |
48 | 39 |
49 // DataTypeController implementation | 40 // NonFrontendDataTypeController 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; | 41 virtual syncable::ModelType type() const; |
57 | |
58 virtual browser_sync::ModelSafeGroup model_safe_group() const; | 42 virtual browser_sync::ModelSafeGroup model_safe_group() const; |
59 | 43 |
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. | 44 // NotificationObserver implementation. |
69 virtual void Observe(NotificationType type, | 45 virtual void Observe(NotificationType type, |
70 const NotificationSource& source, | 46 const NotificationSource& source, |
71 const NotificationDetails& details); | 47 const NotificationDetails& details); |
72 | 48 |
73 // CancelableRequestConsumerBase implementation. | 49 // CancelableRequestConsumerBase implementation. |
74 virtual void OnRequestAdded(CancelableRequestProvider* provider, | 50 virtual void OnRequestAdded(CancelableRequestProvider* provider, |
75 CancelableRequestProvider::Handle handle) {} | 51 CancelableRequestProvider::Handle handle) {} |
76 | |
77 virtual void OnRequestRemoved(CancelableRequestProvider* provider, | 52 virtual void OnRequestRemoved(CancelableRequestProvider* provider, |
78 CancelableRequestProvider::Handle handle) {} | 53 CancelableRequestProvider::Handle handle) {} |
79 | |
80 virtual void WillExecute(CancelableRequestProvider* provider, | 54 virtual void WillExecute(CancelableRequestProvider* provider, |
81 CancelableRequestProvider::Handle handle) {} | 55 CancelableRequestProvider::Handle handle) {} |
82 | |
83 virtual void DidExecute(CancelableRequestProvider* provider, | 56 virtual void DidExecute(CancelableRequestProvider* provider, |
84 CancelableRequestProvider::Handle handle) {} | 57 CancelableRequestProvider::Handle handle) {} |
85 | 58 |
| 59 protected: |
| 60 // NonFrontendDataTypeController interface. |
| 61 virtual bool StartModels(); |
| 62 virtual bool StartAssociationAsync(); |
| 63 virtual void CreateSyncComponents(); |
| 64 virtual void StopModels(); |
| 65 virtual bool StopAssociationAsync(); |
| 66 virtual void RecordUnrecoverableError( |
| 67 const tracked_objects::Location& from_here, |
| 68 const std::string& message); |
| 69 virtual void RecordAssociationTime(base::TimeDelta time); |
| 70 virtual void RecordStartFailure(StartResult result); |
| 71 |
86 private: | 72 private: |
87 friend class ControlTask; | 73 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 | 74 |
96 void set_state(State state) { | 75 // Helper method to launch Associate() and Destroy() on the history thread. |
97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 void RunOnHistoryThread(bool start, history::HistoryBackend* backend); |
98 state_ = state; | |
99 } | |
100 | 77 |
101 ProfileSyncFactory* profile_sync_factory_; | 78 history::HistoryBackend* backend_; |
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_; | 79 scoped_refptr<HistoryService> history_service_; |
110 | |
111 NotificationRegistrar notification_registrar_; | 80 NotificationRegistrar notification_registrar_; |
112 | 81 |
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); | 82 DISALLOW_COPY_AND_ASSIGN(TypedUrlDataTypeController); |
122 }; | 83 }; |
123 | 84 |
124 } // namespace browser_sync | 85 } // namespace browser_sync |
125 | 86 |
126 #endif // CHROME_BROWSER_SYNC_GLUE_TYPED_URL_DATA_TYPE_CONTROLLER_H__ | 87 #endif // CHROME_BROWSER_SYNC_GLUE_TYPED_URL_DATA_TYPE_CONTROLLER_H__ |
OLD | NEW |