| 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/themes/theme_syncable_service.h" | 5 #include "chrome/browser/themes/theme_syncable_service.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
| 11 #include "chrome/common/extensions/manifest_url_handler.h" | 11 #include "chrome/common/extensions/manifest_url_handler.h" |
| 12 #include "chrome/common/extensions/sync_helper.h" | 12 #include "chrome/common/extensions/sync_helper.h" |
| 13 #include "extensions/browser/extension_prefs.h" | 13 #include "extensions/browser/extension_prefs.h" |
| 14 #include "extensions/browser/extension_system.h" | 14 #include "extensions/browser/extension_system.h" |
| 15 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 16 #include "sync/protocol/sync.pb.h" | 16 #include "sync/protocol/sync.pb.h" |
| 17 #include "sync/protocol/theme_specifics.pb.h" | 17 #include "sync/protocol/theme_specifics.pb.h" |
| 18 | 18 |
| 19 using std::string; | 19 using std::string; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 bool IsTheme(const extensions::Extension* extension) { | 23 bool IsTheme(const extensions::Extension* extension) { |
| 24 return extension->is_theme(); | 24 return extension->is_theme(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // TODO(akalin): Remove this. | |
| 28 bool IsSystemThemeDistinctFromDefaultTheme() { | |
| 29 #if defined(TOOLKIT_GTK) | |
| 30 return true; | |
| 31 #else | |
| 32 return false; | |
| 33 #endif | |
| 34 } | |
| 35 | |
| 36 } // namespace | 27 } // namespace |
| 37 | 28 |
| 38 const char ThemeSyncableService::kCurrentThemeClientTag[] = "current_theme"; | 29 const char ThemeSyncableService::kCurrentThemeClientTag[] = "current_theme"; |
| 39 const char ThemeSyncableService::kCurrentThemeNodeTitle[] = "Current Theme"; | 30 const char ThemeSyncableService::kCurrentThemeNodeTitle[] = "Current Theme"; |
| 40 | 31 |
| 41 ThemeSyncableService::ThemeSyncableService(Profile* profile, | 32 ThemeSyncableService::ThemeSyncableService(Profile* profile, |
| 42 ThemeService* theme_service) | 33 ThemeService* theme_service) |
| 43 : profile_(profile), | 34 : profile_(profile), |
| 44 theme_service_(theme_service), | 35 theme_service_(theme_service), |
| 45 use_system_theme_by_default_(false) { | 36 use_system_theme_by_default_(false) { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 "Didn't find valid theme specifics", | 177 "Didn't find valid theme specifics", |
| 187 syncer::THEMES); | 178 syncer::THEMES); |
| 188 } | 179 } |
| 189 | 180 |
| 190 void ThemeSyncableService::MaybeSetTheme( | 181 void ThemeSyncableService::MaybeSetTheme( |
| 191 const sync_pb::ThemeSpecifics& current_specs, | 182 const sync_pb::ThemeSpecifics& current_specs, |
| 192 const syncer::SyncData& sync_data) { | 183 const syncer::SyncData& sync_data) { |
| 193 const sync_pb::ThemeSpecifics& sync_theme = sync_data.GetSpecifics().theme(); | 184 const sync_pb::ThemeSpecifics& sync_theme = sync_data.GetSpecifics().theme(); |
| 194 use_system_theme_by_default_ = sync_theme.use_system_theme_by_default(); | 185 use_system_theme_by_default_ = sync_theme.use_system_theme_by_default(); |
| 195 DVLOG(1) << "Set current theme from specifics: " << sync_data.ToString(); | 186 DVLOG(1) << "Set current theme from specifics: " << sync_data.ToString(); |
| 196 if (!AreThemeSpecificsEqual(current_specs, sync_theme, | 187 if (!AreThemeSpecificsEqual( |
| 197 IsSystemThemeDistinctFromDefaultTheme())) { | 188 current_specs, |
| 189 sync_theme, |
| 190 theme_service_->IsSystemThemeDistinctFromDefaultTheme())) { |
| 198 SetCurrentThemeFromThemeSpecifics(sync_theme); | 191 SetCurrentThemeFromThemeSpecifics(sync_theme); |
| 199 } else { | 192 } else { |
| 200 DVLOG(1) << "Skip setting theme because specs are equal"; | 193 DVLOG(1) << "Skip setting theme because specs are equal"; |
| 201 } | 194 } |
| 202 } | 195 } |
| 203 | 196 |
| 204 void ThemeSyncableService::SetCurrentThemeFromThemeSpecifics( | 197 void ThemeSyncableService::SetCurrentThemeFromThemeSpecifics( |
| 205 const sync_pb::ThemeSpecifics& theme_specifics) { | 198 const sync_pb::ThemeSpecifics& theme_specifics) { |
| 206 if (theme_specifics.use_custom_theme()) { | 199 if (theme_specifics.use_custom_theme()) { |
| 207 // TODO(akalin): Figure out what to do about third-party themes | 200 // TODO(akalin): Figure out what to do about third-party themes |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 NULL : | 252 NULL : |
| 260 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 253 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 261 GetExtensionById(theme_service_->GetThemeID(), false); | 254 GetExtensionById(theme_service_->GetThemeID(), false); |
| 262 if (current_theme && !extensions::sync_helper::IsSyncable(current_theme)) { | 255 if (current_theme && !extensions::sync_helper::IsSyncable(current_theme)) { |
| 263 DVLOG(1) << "Ignoring extension from external source: " << | 256 DVLOG(1) << "Ignoring extension from external source: " << |
| 264 current_theme->location(); | 257 current_theme->location(); |
| 265 return false; | 258 return false; |
| 266 } | 259 } |
| 267 bool use_custom_theme = (current_theme != NULL); | 260 bool use_custom_theme = (current_theme != NULL); |
| 268 theme_specifics->set_use_custom_theme(use_custom_theme); | 261 theme_specifics->set_use_custom_theme(use_custom_theme); |
| 269 if (IsSystemThemeDistinctFromDefaultTheme()) { | 262 if (theme_service_->IsSystemThemeDistinctFromDefaultTheme()) { |
| 270 // On platform where system theme is different from default theme, set | 263 // On platform where system theme is different from default theme, set |
| 271 // use_system_theme_by_default to true if system theme is used, false | 264 // use_system_theme_by_default to true if system theme is used, false |
| 272 // if default system theme is used. Otherwise restore it to value in sync. | 265 // if default system theme is used. Otherwise restore it to value in sync. |
| 273 if (theme_service_->UsingSystemTheme()) { | 266 if (theme_service_->UsingSystemTheme()) { |
| 274 theme_specifics->set_use_system_theme_by_default(true); | 267 theme_specifics->set_use_system_theme_by_default(true); |
| 275 } else if (theme_service_->UsingDefaultTheme()) { | 268 } else if (theme_service_->UsingDefaultTheme()) { |
| 276 theme_specifics->set_use_system_theme_by_default(false); | 269 theme_specifics->set_use_system_theme_by_default(false); |
| 277 } else { | 270 } else { |
| 278 theme_specifics->set_use_system_theme_by_default( | 271 theme_specifics->set_use_system_theme_by_default( |
| 279 use_system_theme_by_default_); | 272 use_system_theme_by_default_); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 syncer::SyncChange(FROM_HERE, change_type, | 329 syncer::SyncChange(FROM_HERE, change_type, |
| 337 syncer::SyncData::CreateLocalData( | 330 syncer::SyncData::CreateLocalData( |
| 338 kCurrentThemeClientTag, kCurrentThemeNodeTitle, | 331 kCurrentThemeClientTag, kCurrentThemeNodeTitle, |
| 339 entity_specifics))); | 332 entity_specifics))); |
| 340 | 333 |
| 341 DVLOG(1) << "Update theme specifics from current theme: " | 334 DVLOG(1) << "Update theme specifics from current theme: " |
| 342 << changes.back().ToString(); | 335 << changes.back().ToString(); |
| 343 | 336 |
| 344 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 337 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 345 } | 338 } |
| OLD | NEW |