| 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/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 "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/sync/glue/theme_util.h" | 10 #include "chrome/browser/sync/glue/theme_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 sync_api::ReadNode node(trans); | 99 sync_api::ReadNode node(trans); |
| 100 if (!node.InitByIdLookup(change.id)) { | 100 if (!node.InitByIdLookup(change.id)) { |
| 101 error_handler()->OnUnrecoverableError(FROM_HERE, | 101 error_handler()->OnUnrecoverableError(FROM_HERE, |
| 102 "Theme node lookup failed."); | 102 "Theme node lookup failed."); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 DCHECK_EQ(node.GetModelType(), syncable::THEMES); | 105 DCHECK_EQ(node.GetModelType(), syncable::THEMES); |
| 106 DCHECK(profile_); | 106 DCHECK(profile_); |
| 107 theme_specifics = node.GetThemeSpecifics(); | 107 theme_specifics = node.GetThemeSpecifics(); |
| 108 } | 108 } |
| 109 StopObserving(); | 109 ScopedStopObserving<ThemeChangeProcessor> stop_observing(this); |
| 110 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_); | 110 SetCurrentThemeFromThemeSpecificsIfNecessary(theme_specifics, profile_); |
| 111 StartObserving(); | |
| 112 } | 111 } |
| 113 | 112 |
| 114 void ThemeChangeProcessor::StartImpl(Profile* profile) { | 113 void ThemeChangeProcessor::StartImpl(Profile* profile) { |
| 115 DCHECK(profile); | 114 DCHECK(profile); |
| 116 profile_ = profile; | 115 profile_ = profile; |
| 117 StartObserving(); | 116 StartObserving(); |
| 118 } | 117 } |
| 119 | 118 |
| 120 void ThemeChangeProcessor::StopImpl() { | 119 void ThemeChangeProcessor::StopImpl() { |
| 121 StopObserving(); | 120 StopObserving(); |
| 122 profile_ = NULL; | 121 profile_ = NULL; |
| 123 } | 122 } |
| 124 | 123 |
| 125 void ThemeChangeProcessor::StartObserving() { | 124 void ThemeChangeProcessor::StartObserving() { |
| 126 DCHECK(profile_); | 125 DCHECK(profile_); |
| 127 VLOG(1) << "Observing BROWSER_THEME_CHANGED"; | 126 VLOG(1) << "Observing BROWSER_THEME_CHANGED"; |
| 128 notification_registrar_.Add( | 127 notification_registrar_.Add( |
| 129 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 128 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 130 content::Source<ThemeService>( | 129 content::Source<ThemeService>( |
| 131 ThemeServiceFactory::GetForProfile(profile_))); | 130 ThemeServiceFactory::GetForProfile(profile_))); |
| 132 } | 131 } |
| 133 | 132 |
| 134 void ThemeChangeProcessor::StopObserving() { | 133 void ThemeChangeProcessor::StopObserving() { |
| 135 DCHECK(profile_); | 134 DCHECK(profile_); |
| 136 VLOG(1) << "Unobserving all notifications"; | 135 VLOG(1) << "Unobserving all notifications"; |
| 137 notification_registrar_.RemoveAll(); | 136 notification_registrar_.RemoveAll(); |
| 138 } | 137 } |
| 139 | 138 |
| 140 } // namespace browser_sync | 139 } // namespace browser_sync |
| OLD | NEW |