| OLD | NEW |
| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 LOG(INFO) << "Theme changed to " << GetThemeId(extension); | 106 LOG(INFO) << "Theme changed to " << GetThemeId(extension); |
| 107 | 107 |
| 108 // Here, we know that a theme is being set; the theme is a custom | 108 // Here, we know that a theme is being set; the theme is a custom |
| 109 // theme iff extension is non-NULL. | 109 // theme iff extension is non-NULL. |
| 110 | 110 |
| 111 sync_api::WriteTransaction trans(share_handle()); | 111 sync_api::WriteTransaction trans(share_handle()); |
| 112 sync_api::WriteNode node(&trans); | 112 sync_api::WriteNode node(&trans); |
| 113 if (!node.InitByClientTagLookup(syncable::THEMES, | 113 if (!node.InitByClientTagLookup(syncable::THEMES, |
| 114 kCurrentThemeClientTag)) { | 114 kCurrentThemeClientTag)) { |
| 115 LOG(ERROR) << "Could not create node with client tag: " | 115 std::string err = "Could not create node with client tag: "; |
| 116 << kCurrentThemeClientTag; | 116 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 117 error_handler()->OnUnrecoverableError(); | 117 err + kCurrentThemeClientTag); |
| 118 return; | 118 return; |
| 119 } | 119 } |
| 120 | 120 |
| 121 sync_pb::ThemeSpecifics old_theme_specifics = node.GetThemeSpecifics(); | 121 sync_pb::ThemeSpecifics old_theme_specifics = node.GetThemeSpecifics(); |
| 122 // Make sure to base new_theme_specifics on old_theme_specifics so | 122 // Make sure to base new_theme_specifics on old_theme_specifics so |
| 123 // we preserve the state of use_system_theme_by_default. | 123 // we preserve the state of use_system_theme_by_default. |
| 124 sync_pb::ThemeSpecifics new_theme_specifics = old_theme_specifics; | 124 sync_pb::ThemeSpecifics new_theme_specifics = old_theme_specifics; |
| 125 GetThemeSpecificsFromCurrentTheme(profile_, &new_theme_specifics); | 125 GetThemeSpecificsFromCurrentTheme(profile_, &new_theme_specifics); |
| 126 // Do a write only if something actually changed so as to guard | 126 // Do a write only if something actually changed so as to guard |
| 127 // against cycles. | 127 // against cycles. |
| 128 if (!AreThemeSpecificsEqual(old_theme_specifics, new_theme_specifics)) { | 128 if (!AreThemeSpecificsEqual(old_theme_specifics, new_theme_specifics)) { |
| 129 node.SetThemeSpecifics(new_theme_specifics); | 129 node.SetThemeSpecifics(new_theme_specifics); |
| 130 } | 130 } |
| 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 // TODO(akalin): Normally, we should only have a single change and | 141 // TODO(akalin): Normally, we should only have a single change and |
| 142 // it should be an update. However, the syncapi may occasionally | 142 // it should be an update. However, the syncapi may occasionally |
| 143 // generates multiple changes. When we fix syncapi to not do that, | 143 // generates multiple changes. When we fix syncapi to not do that, |
| 144 // we can remove the extra logic below. See: | 144 // we can remove the extra logic below. See: |
| 145 // http://code.google.com/p/chromium/issues/detail?id=41696 . | 145 // http://code.google.com/p/chromium/issues/detail?id=41696 . |
| 146 if (change_count < 1) { | 146 if (change_count < 1) { |
| 147 LOG(ERROR) << "Unexpected change_count: " << change_count; | 147 std::string err("Unexpected change_count: "); |
| 148 error_handler()->OnUnrecoverableError(); | 148 err += change_count; |
| 149 error_handler()->OnUnrecoverableError(FROM_HERE, err); |
| 149 return; | 150 return; |
| 150 } | 151 } |
| 151 if (change_count > 1) { | 152 if (change_count > 1) { |
| 152 LOG(WARNING) << change_count << " theme changes detected; " | 153 LOG(WARNING) << change_count << " theme changes detected; " |
| 153 << "only applying the last one"; | 154 << "only applying the last one"; |
| 154 } | 155 } |
| 155 const sync_api::SyncManager::ChangeRecord& change = | 156 const sync_api::SyncManager::ChangeRecord& change = |
| 156 changes[change_count - 1]; | 157 changes[change_count - 1]; |
| 157 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_UPDATE) { | 158 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_UPDATE) { |
| 158 LOG(WARNING) << "strange theme change.action: " << change.action; | 159 std::string err = "strange theme change.action " + change.action; |
| 160 error_handler()->OnUnrecoverableError(FROM_HERE, err); |
| 159 } | 161 } |
| 160 sync_pb::ThemeSpecifics theme_specifics; | 162 sync_pb::ThemeSpecifics theme_specifics; |
| 161 // If the action is a delete, simply use the default values for | 163 // If the action is a delete, simply use the default values for |
| 162 // ThemeSpecifics, which would cause the default theme to be set. | 164 // ThemeSpecifics, which would cause the default theme to be set. |
| 163 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { | 165 if (change.action != sync_api::SyncManager::ChangeRecord::ACTION_DELETE) { |
| 164 sync_api::ReadNode node(trans); | 166 sync_api::ReadNode node(trans); |
| 165 if (!node.InitByIdLookup(change.id)) { | 167 if (!node.InitByIdLookup(change.id)) { |
| 166 LOG(ERROR) << "Theme node lookup failed"; | 168 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 167 error_handler()->OnUnrecoverableError(); | 169 "Theme node lookup failed."); |
| 168 return; | 170 return; |
| 169 } | 171 } |
| 170 DCHECK_EQ(node.GetModelType(), syncable::THEMES); | 172 DCHECK_EQ(node.GetModelType(), syncable::THEMES); |
| 171 DCHECK(profile_); | 173 DCHECK(profile_); |
| 172 theme_specifics = node.GetThemeSpecifics(); | 174 theme_specifics = node.GetThemeSpecifics(); |
| 173 } | 175 } |
| 174 StopObserving(); | 176 StopObserving(); |
| 175 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_); | 177 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_); |
| 176 StartObserving(); | 178 StartObserving(); |
| 177 } | 179 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 202 Source<Profile>(profile_)); | 204 Source<Profile>(profile_)); |
| 203 } | 205 } |
| 204 | 206 |
| 205 void ThemeChangeProcessor::StopObserving() { | 207 void ThemeChangeProcessor::StopObserving() { |
| 206 DCHECK(profile_); | 208 DCHECK(profile_); |
| 207 LOG(INFO) << "Unobserving all notifications"; | 209 LOG(INFO) << "Unobserving all notifications"; |
| 208 notification_registrar_.RemoveAll(); | 210 notification_registrar_.RemoveAll(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 } // namespace browser_sync | 213 } // namespace browser_sync |
| OLD | NEW |