| 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 25 matching lines...) Expand all Loading... |
| 36 void ThemeChangeProcessor::Observe( | 36 void ThemeChangeProcessor::Observe( |
| 37 int type, | 37 int type, |
| 38 const content::NotificationSource& source, | 38 const content::NotificationSource& source, |
| 39 const content::NotificationDetails& details) { | 39 const content::NotificationDetails& details) { |
| 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 std::string err = "Could not create node with client tag: "; | 49 std::string err = "Could not create node with client tag: "; |
| 49 error_handler()->OnUnrecoverableError(FROM_HERE, | 50 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 50 err + kCurrentThemeClientTag); | 51 err + kCurrentThemeClientTag); |
| 51 return; | 52 return; |
| 52 } | 53 } |
| 53 | 54 |
| 54 sync_pb::ThemeSpecifics old_theme_specifics = node.GetThemeSpecifics(); | 55 sync_pb::ThemeSpecifics old_theme_specifics = node.GetThemeSpecifics(); |
| 55 // 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 |
| 56 // we preserve the state of use_system_theme_by_default. | 57 // we preserve the state of use_system_theme_by_default. |
| 57 sync_pb::ThemeSpecifics new_theme_specifics = old_theme_specifics; | 58 sync_pb::ThemeSpecifics new_theme_specifics = old_theme_specifics; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 std::string err = "strange theme change.action " + | 93 std::string err = "strange theme change.action " + |
| 93 base::IntToString(change.action); | 94 base::IntToString(change.action); |
| 94 error_handler()->OnUnrecoverableError(FROM_HERE, err); | 95 error_handler()->OnUnrecoverableError(FROM_HERE, err); |
| 95 return; | 96 return; |
| 96 } | 97 } |
| 97 sync_pb::ThemeSpecifics theme_specifics; | 98 sync_pb::ThemeSpecifics theme_specifics; |
| 98 // 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 |
| 99 // ThemeSpecifics, which would cause the default theme to be set. | 100 // ThemeSpecifics, which would cause the default theme to be set. |
| 100 if (change.action != sync_api::ChangeRecord::ACTION_DELETE) { | 101 if (change.action != sync_api::ChangeRecord::ACTION_DELETE) { |
| 101 sync_api::ReadNode node(trans); | 102 sync_api::ReadNode node(trans); |
| 102 if (!node.InitByIdLookup(change.id)) { | 103 if (node.InitByIdLookup(change.id) != sync_api::BaseNode::INIT_OK) { |
| 103 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, | 104 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, |
| 104 "Theme node lookup failed."); | 105 "Theme node lookup failed."); |
| 105 return; | 106 return; |
| 106 } | 107 } |
| 107 DCHECK_EQ(node.GetModelType(), syncable::THEMES); | 108 DCHECK_EQ(node.GetModelType(), syncable::THEMES); |
| 108 DCHECK(profile_); | 109 DCHECK(profile_); |
| 109 theme_specifics = node.GetThemeSpecifics(); | 110 theme_specifics = node.GetThemeSpecifics(); |
| 110 } | 111 } |
| 111 ScopedStopObserving<ThemeChangeProcessor> stop_observing(this); | 112 ScopedStopObserving<ThemeChangeProcessor> stop_observing(this); |
| 112 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_); | 113 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 132 ThemeServiceFactory::GetForProfile(profile_))); | 133 ThemeServiceFactory::GetForProfile(profile_))); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void ThemeChangeProcessor::StopObserving() { | 136 void ThemeChangeProcessor::StopObserving() { |
| 136 DCHECK(profile_); | 137 DCHECK(profile_); |
| 137 DVLOG(1) << "Unobserving all notifications"; | 138 DVLOG(1) << "Unobserving all notifications"; |
| 138 notification_registrar_.RemoveAll(); | 139 notification_registrar_.RemoveAll(); |
| 139 } | 140 } |
| 140 | 141 |
| 141 } // namespace browser_sync | 142 } // namespace browser_sync |
| OLD | NEW |