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 #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 Loading... |
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 RecordStartFailure(result); |
| 114 |
| 115 // We have to release the callback before we call it, since it's possible |
| 116 // invoking the callback will trigger a call to STOP(), which will get |
| 117 // confused by the non-NULL start_callback_. |
| 118 scoped_ptr<StartCallback> callback(start_callback_.release()); |
| 119 callback->Run(result, location); |
| 120 } |
| 121 |
| 122 void FrontendDataTypeController::FinishStart(StartResult result, |
| 123 const tracked_objects::Location& location) { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 125 |
| 126 // We have to release the callback before we call it, since it's possible |
| 127 // invoking the callback will trigger a call to STOP(), which will get |
| 128 // confused by the non-NULL start_callback_. |
| 129 scoped_ptr<StartCallback> callback(start_callback_.release()); |
| 130 callback->Run(result, location); |
| 131 } |
| 132 |
106 void FrontendDataTypeController::Stop() { | 133 void FrontendDataTypeController::Stop() { |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
108 // If Stop() is called while Start() is waiting for the datatype model to | 135 // If Stop() is called while Start() is waiting for the datatype model to |
109 // load, abort the start. | 136 // load, abort the start. |
110 if (state_ == MODEL_STARTING) | 137 if (state_ == MODEL_STARTING) { |
111 FinishStart(ABORTED, FROM_HERE); | 138 StartFailed(ABORTED, FROM_HERE); |
| 139 // We can just return here since we haven't performed association if we're |
| 140 // still in MODEL_STARTING. |
| 141 return; |
| 142 } |
112 DCHECK(!start_callback_.get()); | 143 DCHECK(!start_callback_.get()); |
113 | 144 |
114 CleanupState(); | 145 CleanUpState(); |
115 | 146 |
116 if (change_processor_ != NULL) | 147 if (change_processor_ != NULL) |
117 sync_service_->DeactivateDataType(this, change_processor_.get()); | 148 sync_service_->DeactivateDataType(this, change_processor_.get()); |
118 | 149 |
119 if (model_associator_ != NULL) | 150 if (model_associator_ != NULL) |
120 model_associator_->DisassociateModels(); | 151 model_associator_->DisassociateModels(); |
121 | 152 |
122 change_processor_.reset(); | 153 change_processor_.reset(); |
123 model_associator_.reset(); | 154 model_associator_.reset(); |
124 | 155 |
125 state_ = NOT_RUNNING; | 156 state_ = NOT_RUNNING; |
126 } | 157 } |
127 | 158 |
128 void FrontendDataTypeController::CleanupState() { | 159 void FrontendDataTypeController::CleanUpState() { |
129 // Do nothing by default. | 160 // Do nothing by default. |
130 } | 161 } |
131 | 162 |
132 browser_sync::ModelSafeGroup FrontendDataTypeController::model_safe_group() | 163 browser_sync::ModelSafeGroup FrontendDataTypeController::model_safe_group() |
133 const { | 164 const { |
134 return browser_sync::GROUP_UI; | 165 return browser_sync::GROUP_UI; |
135 } | 166 } |
136 | 167 |
137 std::string FrontendDataTypeController::name() const { | 168 std::string FrontendDataTypeController::name() const { |
138 // For logging only. | 169 // For logging only. |
139 return syncable::ModelTypeToString(type()); | 170 return syncable::ModelTypeToString(type()); |
140 } | 171 } |
141 | 172 |
142 DataTypeController::State FrontendDataTypeController::state() const { | 173 DataTypeController::State FrontendDataTypeController::state() const { |
143 return state_; | 174 return state_; |
144 } | 175 } |
145 | 176 |
146 void FrontendDataTypeController::OnUnrecoverableError( | 177 void FrontendDataTypeController::OnUnrecoverableError( |
147 const tracked_objects::Location& from_here, const std::string& message) { | 178 const tracked_objects::Location& from_here, const std::string& message) { |
148 // The ProfileSyncService will invoke our Stop() method in response to this. | 179 // The ProfileSyncService will invoke our Stop() method in response to this. |
149 RecordUnrecoverableError(from_here, message); | 180 RecordUnrecoverableError(from_here, message); |
150 sync_service_->OnUnrecoverableError(from_here, message); | 181 sync_service_->OnUnrecoverableError(from_here, message); |
151 } | 182 } |
152 | 183 |
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 | 184 } // namespace browser_sync |
OLD | NEW |