| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/location.h" | 7 #include "base/location.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 DCHECK(running()); | 40 DCHECK(running()); |
| 41 DCHECK(profile_); | 41 DCHECK(profile_); |
| 42 DCHECK(type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED); | 42 DCHECK(type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
| 43 | 43 |
| 44 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); | 44 sync_api::WriteTransaction trans(FROM_HERE, share_handle()); |
| 45 sync_api::WriteNode node(&trans); | 45 sync_api::WriteNode node(&trans); |
| 46 if (node.InitByClientTagLookup(syncable::THEMES, | 46 if (node.InitByClientTagLookup(syncable::THEMES, |
| 47 kCurrentThemeClientTag) != | 47 kCurrentThemeClientTag) != |
| 48 sync_api::BaseNode::INIT_OK) { | 48 sync_api::BaseNode::INIT_OK) { |
| 49 std::string err = "Could not create node with client tag: "; | 49 std::string err = "Could not create node with client tag: "; |
| 50 error_handler()->OnUnrecoverableError(FROM_HERE, | 50 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 51 err + kCurrentThemeClientTag); | 51 err + kCurrentThemeClientTag); |
| 52 return; | 52 return; |
| 53 } | 53 } |
| 54 | 54 |
| 55 sync_pb::ThemeSpecifics old_theme_specifics = node.GetThemeSpecifics(); | 55 sync_pb::ThemeSpecifics old_theme_specifics = node.GetThemeSpecifics(); |
| 56 // Make sure to base new_theme_specifics on old_theme_specifics so | 56 // Make sure to base new_theme_specifics on old_theme_specifics so |
| 57 // we preserve the state of use_system_theme_by_default. | 57 // we preserve the state of use_system_theme_by_default. |
| 58 sync_pb::ThemeSpecifics new_theme_specifics = old_theme_specifics; | 58 sync_pb::ThemeSpecifics new_theme_specifics = old_theme_specifics; |
| 59 GetThemeSpecificsFromCurrentTheme(profile_, &new_theme_specifics); | 59 GetThemeSpecificsFromCurrentTheme(profile_, &new_theme_specifics); |
| 60 // Do a write only if something actually changed so as to guard | 60 // Do a write only if something actually changed so as to guard |
| (...skipping 24 matching lines...) Expand all Loading... |
| 85 if (change_count > 1u) { | 85 if (change_count > 1u) { |
| 86 LOG(WARNING) << change_count << " theme changes detected; " | 86 LOG(WARNING) << change_count << " theme changes detected; " |
| 87 << "only applying the last one"; | 87 << "only applying the last one"; |
| 88 } | 88 } |
| 89 const sync_api::ChangeRecord& change = | 89 const sync_api::ChangeRecord& change = |
| 90 changes.Get()[change_count - 1]; | 90 changes.Get()[change_count - 1]; |
| 91 if (change.action != sync_api::ChangeRecord::ACTION_UPDATE && | 91 if (change.action != sync_api::ChangeRecord::ACTION_UPDATE && |
| 92 change.action != sync_api::ChangeRecord::ACTION_DELETE) { | 92 change.action != sync_api::ChangeRecord::ACTION_DELETE) { |
| 93 std::string err = "strange theme change.action " + | 93 std::string err = "strange theme change.action " + |
| 94 base::IntToString(change.action); | 94 base::IntToString(change.action); |
| 95 error_handler()->OnUnrecoverableError(FROM_HERE, err); | 95 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, err); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 sync_pb::ThemeSpecifics theme_specifics; | 98 sync_pb::ThemeSpecifics theme_specifics; |
| 99 // If the action is a delete, simply use the default values for | 99 // If the action is a delete, simply use the default values for |
| 100 // ThemeSpecifics, which would cause the default theme to be set. | 100 // ThemeSpecifics, which would cause the default theme to be set. |
| 101 if (change.action != sync_api::ChangeRecord::ACTION_DELETE) { | 101 if (change.action != sync_api::ChangeRecord::ACTION_DELETE) { |
| 102 sync_api::ReadNode node(trans); | 102 sync_api::ReadNode node(trans); |
| 103 if (node.InitByIdLookup(change.id) != sync_api::BaseNode::INIT_OK) { | 103 if (node.InitByIdLookup(change.id) != sync_api::BaseNode::INIT_OK) { |
| 104 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 104 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 105 "Theme node lookup failed."); | 105 "Theme node lookup failed."); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 133 ThemeServiceFactory::GetForProfile(profile_))); | 133 ThemeServiceFactory::GetForProfile(profile_))); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void ThemeChangeProcessor::StopObserving() { | 136 void ThemeChangeProcessor::StopObserving() { |
| 137 DCHECK(profile_); | 137 DCHECK(profile_); |
| 138 DVLOG(1) << "Unobserving all notifications"; | 138 DVLOG(1) << "Unobserving all notifications"; |
| 139 notification_registrar_.RemoveAll(); | 139 notification_registrar_.RemoveAll(); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace browser_sync | 142 } // namespace browser_sync |
| OLD | NEW |