Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: chrome/browser/sync/glue/non_frontend_data_type_controller.h

Issue 6811003: [Sync] Make generic non-frontend thread datatype controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix autofill Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // Implementation for datatypes that do not reside on the frontend thread
27 // (UI thread). This is the same thread we perform initialization
28 // on, so we don't have to worry about thread safety. The main start/stop
29 // funtionality is implemented by default. Derived classes must implement:
tim (not reviewing) 2011/04/07 22:04:25 I like the comment. Just a suggestion -- abbrevia
Nicolas Zea 2011/04/08 16:53:42 Done.
30 // syncable::ModelType type() const
31 // browser_sync::ModelSafeGroup model_safe_group() const = 0;
32 // void CreateSyncComponents();
33 // void RecordUnrecoverableError(
34 // const tracked_objects::Location& from_here,
35 // const std::string& message);
36 // void RecordAssociationTime(base::TimeDelta time);
37 // void RecordStartFailure(StartResult result);
38 class NonFrontendDataTypeController : public DataTypeController {
39 public:
40 NonFrontendDataTypeController(
41 ProfileSyncFactory* profile_sync_factory,
42 Profile* profile,
43 ProfileSyncService* sync_service);
tim (not reviewing) 2011/04/07 22:04:25 do we really need both the profile and service if
Nicolas Zea 2011/04/08 16:53:42 Done.
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 // Kick of any dependent services that need to be running before we can
tim (not reviewing) 2011/04/07 22:04:25 a comment like "kick off" on a method called Start
Nicolas Zea 2011/04/08 16:53:42 Done.
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 // Kick off the the association on the thread the datatype lives on.
tim (not reviewing) 2011/04/07 22:04:25 "the the" > "the" I think we should be as consist
Nicolas Zea 2011/04/08 16:53:42 Done.
72 // Note: this is performed on the frontend (UI) thread.
73 // Return value: True if task posted successfully, False otherwise.
74 virtual bool KickOffAssociation() = 0;
75
76 // Build sync components and associate models.
77 // Note: this is performed on the datatype's thread.
78 virtual void Associate();
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 CleanUpState();
tim (not reviewing) 2011/04/07 22:04:25 I think just Cleanup or Teardown is a more familia
Nicolas Zea 2011/04/08 16:53:42 Done.
105
106 // Kick off disassociation/destruction of the sync components on the
107 // datatype's thread.
108 // Note: this is performed on the frontend (UI) thread.
109 // Return value: True if task posted successfully, False otherwise.
110 virtual bool KickOffDestroy() = 0;
tim (not reviewing) 2011/04/07 22:04:25 same as above
Nicolas Zea 2011/04/08 16:53:42 Done.
111
112 // Disassociate the models and destroy the sync components.
113 // Note: this is performed on the datatype's thread.
114 virtual void Destroy();
115
116 // Implementation of OnUnrecoverableError that lives on UI thread.
117 virtual void OnUnrecoverableErrorImpl(
118 const tracked_objects::Location& from_here,
119 const std::string& message);
120
121 // DataType specific histogram methods. Because histograms use static's, the
122 // specific datatype controllers must implement this themselves.
123 // Important: calling them on other threads can lead to memory corruption!
124 // Record unrecoverable errors. Called on Datatype's thread.
125 virtual void RecordUnrecoverableError(
126 const tracked_objects::Location& from_here,
127 const std::string& message) = 0;
128 // Record association time. Called on Datatype's thread.
129 virtual void RecordAssociationTime(base::TimeDelta time) = 0;
130 // Record causes of start failure. Called on UI thread.
131 virtual void RecordStartFailure(StartResult result) = 0;
132
133 ProfileSyncFactory* const profile_sync_factory_;
tim (not reviewing) 2011/04/07 22:04:25 strictly speaking, style-guide-says members should
Nicolas Zea 2011/04/08 16:53:42 Done.
134 Profile* const profile_;
135 ProfileSyncService* const sync_service_;
136
137 State state_;
138
139 scoped_ptr<StartCallback> start_callback_;
140 scoped_ptr<AssociatorInterface> model_associator_;
141 scoped_ptr<ChangeProcessor> change_processor_;
142
143 // Locks/Barriers for aborting association early.
144 base::Lock abort_association_lock_;
145 bool abort_association_;
146 base::WaitableEvent abort_association_complete_;
147
148 // Barrier to ensure that the datatype has been stopped on the DB thread
149 // from the UI thread.
150 base::WaitableEvent datatype_stopped_;
151 private:
152 DISALLOW_COPY_AND_ASSIGN(NonFrontendDataTypeController);
153 };
154
155 } // namespace browser_sync
156
157 #endif // CHROME_BROWSER_SYNC_GLUE_NON_FRONTEND_DATA_TYPE_CONTROLLER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698