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

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

Issue 1622030: Made ThemeChangeProcessor handle multiple updates to work around (Closed)
Patch Set: Added link to bug Created 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/theme_change_processor.h" 5 #include "chrome/browser/sync/glue/theme_change_processor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/browser_theme_provider.h" 8 #include "chrome/browser/browser_theme_provider.h"
9 #include "chrome/browser/profile.h" 9 #include "chrome/browser/profile.h"
10 #include "chrome/browser/sync/engine/syncapi.h" 10 #include "chrome/browser/sync/engine/syncapi.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return; 131 return;
132 } 132 }
133 133
134 void ThemeChangeProcessor::ApplyChangesFromSyncModel( 134 void ThemeChangeProcessor::ApplyChangesFromSyncModel(
135 const sync_api::BaseTransaction* trans, 135 const sync_api::BaseTransaction* trans,
136 const sync_api::SyncManager::ChangeRecord* changes, 136 const sync_api::SyncManager::ChangeRecord* changes,
137 int change_count) { 137 int change_count) {
138 if (!running()) { 138 if (!running()) {
139 return; 139 return;
140 } 140 }
141 StopObserving(); 141 // TODO(akalin): Normally, we should only have a single change and
142 if (change_count != 1) { 142 // it should be an update. However, the syncapi may occasionally
143 LOG(ERROR) << "Unexpected number of theme changes"; 143 // generates multiple changes. When we fix syncapi to not do that,
144 // we can remove the extra logic below. See:
145 // http://code.google.com/p/chromium/issues/detail?id=41696 .
146 if (change_count < 1) {
147 LOG(ERROR) << "Unexpected change_count: " << change_count;
144 error_handler()->OnUnrecoverableError(); 148 error_handler()->OnUnrecoverableError();
145 return; 149 return;
146 } 150 }
147 const sync_api::SyncManager::ChangeRecord& change = changes[0]; 151 if (change_count > 1) {
152 LOG(WARNING) << change_count << " theme changes detected; "
153 << "only applying the last one";
154 }
155 const sync_api::SyncManager::ChangeRecord& change =
156 changes[change_count - 1];
148 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_UPDATE) { 157 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_UPDATE) {
149 LOG(ERROR) << "Unexpected change.action " << change.action; 158 LOG(WARNING) << "strange theme change.action: " << change.action;
150 error_handler()->OnUnrecoverableError();
151 return;
152 } 159 }
153 sync_api::ReadNode node(trans); 160 sync_pb::ThemeSpecifics theme_specifics;
154 if (!node.InitByIdLookup(change.id)) { 161 // If the action is a delete, simply use the default values for
155 LOG(ERROR) << "Theme node lookup failed"; 162 // ThemeSpecifics, which would cause the default theme to be set.
156 error_handler()->OnUnrecoverableError(); 163 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_DELETE) {
157 return; 164 sync_api::ReadNode node(trans);
165 if (!node.InitByIdLookup(change.id)) {
166 LOG(ERROR) << "Theme node lookup failed";
167 error_handler()->OnUnrecoverableError();
168 return;
169 }
170 DCHECK_EQ(node.GetModelType(), syncable::THEMES);
171 DCHECK(profile_);
172 theme_specifics = node.GetThemeSpecifics();
158 } 173 }
159 DCHECK_EQ(node.GetModelType(), syncable::THEMES); 174 StopObserving();
160 DCHECK(profile_); 175 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_);
161 SetCurrentThemeFromThemeSpecificsIfNecessary(
162 node.GetThemeSpecifics(), profile_);
163 StartObserving(); 176 StartObserving();
164 } 177 }
165 178
166 void ThemeChangeProcessor::StartImpl(Profile* profile) { 179 void ThemeChangeProcessor::StartImpl(Profile* profile) {
167 DCHECK(profile); 180 DCHECK(profile);
168 profile_ = profile; 181 profile_ = profile;
169 StartObserving(); 182 StartObserving();
170 } 183 }
171 184
172 void ThemeChangeProcessor::StopImpl() { 185 void ThemeChangeProcessor::StopImpl() {
(...skipping 16 matching lines...) Expand all
189 Source<Profile>(profile_)); 202 Source<Profile>(profile_));
190 } 203 }
191 204
192 void ThemeChangeProcessor::StopObserving() { 205 void ThemeChangeProcessor::StopObserving() {
193 DCHECK(profile_); 206 DCHECK(profile_);
194 LOG(INFO) << "Unobserving all notifications"; 207 LOG(INFO) << "Unobserving all notifications";
195 notification_registrar_.RemoveAll(); 208 notification_registrar_.RemoveAll();
196 } 209 }
197 210
198 } // namespace browser_sync 211 } // namespace browser_sync
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698