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

Side by Side Diff: chrome/browser/sync/glue/frontend_data_type_controller.cc

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
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 #include "chrome/browser/sync/glue/frontend_data_type_controller.h" 5 #include "chrome/browser/sync/glue/frontend_data_type_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/sync/glue/change_processor.h" 9 #include "chrome/browser/sync/glue/change_processor.h"
10 #include "chrome/browser/sync/glue/model_associator.h" 10 #include "chrome/browser/sync/glue/model_associator.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 StartFailed(ASSOCIATION_FAILED, FROM_HERE); 96 StartFailed(ASSOCIATION_FAILED, FROM_HERE);
97 return false; 97 return false;
98 } 98 }
99 99
100 sync_service_->ActivateDataType(this, change_processor_.get()); 100 sync_service_->ActivateDataType(this, change_processor_.get());
101 state_ = RUNNING; 101 state_ = RUNNING;
102 FinishStart(!sync_has_nodes ? OK_FIRST_RUN : OK, FROM_HERE); 102 FinishStart(!sync_has_nodes ? OK_FIRST_RUN : OK, FROM_HERE);
103 return true; 103 return true;
104 } 104 }
105 105
106 void FrontendDataTypeController::StartFailed(StartResult result,
107 const tracked_objects::Location& location) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 CleanUpState();
110 model_associator_.reset();
111 change_processor_.reset();
112 state_ = NOT_RUNNING;
113 start_callback_->Run(result, location);
114 start_callback_.reset();
115 RecordStartFailure(result);
116 }
117
118 void FrontendDataTypeController::FinishStart(StartResult result,
119 const tracked_objects::Location& location) {
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 start_callback_->Run(result, location);
122 start_callback_.reset();
123 }
124
106 void FrontendDataTypeController::Stop() { 125 void FrontendDataTypeController::Stop() {
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
108 // If Stop() is called while Start() is waiting for the datatype model to 127 // If Stop() is called while Start() is waiting for the datatype model to
109 // load, abort the start. 128 // load, abort the start.
110 if (state_ == MODEL_STARTING) 129 if (state_ == MODEL_STARTING) {
111 FinishStart(ABORTED, FROM_HERE); 130 StartFailed(ABORTED, FROM_HERE);
131 // We can just return here since we haven't performed association if we're
132 // still in MODEL_STARTING.
133 return;
134 }
112 DCHECK(!start_callback_.get()); 135 DCHECK(!start_callback_.get());
113 136
114 CleanupState(); 137 CleanUpState();
115 138
116 if (change_processor_ != NULL) 139 if (change_processor_ != NULL)
117 sync_service_->DeactivateDataType(this, change_processor_.get()); 140 sync_service_->DeactivateDataType(this, change_processor_.get());
118 141
119 if (model_associator_ != NULL) 142 if (model_associator_ != NULL)
120 model_associator_->DisassociateModels(); 143 model_associator_->DisassociateModels();
121 144
122 change_processor_.reset(); 145 change_processor_.reset();
123 model_associator_.reset(); 146 model_associator_.reset();
124 147
125 state_ = NOT_RUNNING; 148 state_ = NOT_RUNNING;
126 } 149 }
127 150
128 void FrontendDataTypeController::CleanupState() { 151 void FrontendDataTypeController::CleanUpState() {
129 // Do nothing by default. 152 // Do nothing by default.
130 } 153 }
131 154
132 browser_sync::ModelSafeGroup FrontendDataTypeController::model_safe_group() 155 browser_sync::ModelSafeGroup FrontendDataTypeController::model_safe_group()
133 const { 156 const {
134 return browser_sync::GROUP_UI; 157 return browser_sync::GROUP_UI;
135 } 158 }
136 159
137 std::string FrontendDataTypeController::name() const { 160 std::string FrontendDataTypeController::name() const {
138 // For logging only. 161 // For logging only.
139 return syncable::ModelTypeToString(type()); 162 return syncable::ModelTypeToString(type());
140 } 163 }
141 164
142 DataTypeController::State FrontendDataTypeController::state() const { 165 DataTypeController::State FrontendDataTypeController::state() const {
143 return state_; 166 return state_;
144 } 167 }
145 168
146 void FrontendDataTypeController::OnUnrecoverableError( 169 void FrontendDataTypeController::OnUnrecoverableError(
147 const tracked_objects::Location& from_here, const std::string& message) { 170 const tracked_objects::Location& from_here, const std::string& message) {
148 // The ProfileSyncService will invoke our Stop() method in response to this. 171 // The ProfileSyncService will invoke our Stop() method in response to this.
149 RecordUnrecoverableError(from_here, message); 172 RecordUnrecoverableError(from_here, message);
150 sync_service_->OnUnrecoverableError(from_here, message); 173 sync_service_->OnUnrecoverableError(from_here, message);
151 } 174 }
152 175
153 void FrontendDataTypeController::FinishStart(StartResult result,
154 const tracked_objects::Location& location) {
155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
156 start_callback_->Run(result, location);
157 start_callback_.reset();
158 }
159
160 void FrontendDataTypeController::StartFailed(StartResult result,
161 const tracked_objects::Location& location) {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
163 CleanupState();
164 model_associator_.reset();
165 change_processor_.reset();
166 state_ = NOT_RUNNING;
167 start_callback_->Run(result, location);
168 start_callback_.reset();
169 RecordStartFailure(result);
170 }
171
172 } // namespace browser_sync 176 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698