| 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/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/themes/theme_service.h" | 11 #include "chrome/browser/themes/theme_service.h" |
| 11 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 12 #include "sync/protocol/sync.pb.h" | 13 #include "sync/protocol/sync.pb.h" |
| 13 #include "sync/protocol/theme_specifics.pb.h" | 14 #include "sync/protocol/theme_specifics.pb.h" |
| 14 | 15 |
| 15 using std::string; | 16 using std::string; |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 190 |
| 190 void ThemeSyncableService::SetCurrentThemeFromThemeSpecifics( | 191 void ThemeSyncableService::SetCurrentThemeFromThemeSpecifics( |
| 191 const sync_pb::ThemeSpecifics& theme_specifics) { | 192 const sync_pb::ThemeSpecifics& theme_specifics) { |
| 192 if (theme_specifics.use_custom_theme()) { | 193 if (theme_specifics.use_custom_theme()) { |
| 193 // TODO(akalin): Figure out what to do about third-party themes | 194 // TODO(akalin): Figure out what to do about third-party themes |
| 194 // (i.e., those not on either Google gallery). | 195 // (i.e., those not on either Google gallery). |
| 195 string id(theme_specifics.custom_theme_id()); | 196 string id(theme_specifics.custom_theme_id()); |
| 196 GURL update_url(theme_specifics.custom_theme_update_url()); | 197 GURL update_url(theme_specifics.custom_theme_update_url()); |
| 197 DVLOG(1) << "Applying theme " << id << " with update_url " << update_url; | 198 DVLOG(1) << "Applying theme " << id << " with update_url " << update_url; |
| 198 ExtensionServiceInterface* extensions_service = | 199 ExtensionServiceInterface* extensions_service = |
| 199 profile_->GetExtensionService(); | 200 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 200 CHECK(extensions_service); | 201 CHECK(extensions_service); |
| 201 const extensions::Extension* extension = | 202 const extensions::Extension* extension = |
| 202 extensions_service->GetExtensionById(id, true); | 203 extensions_service->GetExtensionById(id, true); |
| 203 if (extension) { | 204 if (extension) { |
| 204 if (!extension->is_theme()) { | 205 if (!extension->is_theme()) { |
| 205 DVLOG(1) << "Extension " << id << " is not a theme; aborting"; | 206 DVLOG(1) << "Extension " << id << " is not a theme; aborting"; |
| 206 return; | 207 return; |
| 207 } | 208 } |
| 208 if (!extensions_service->IsExtensionEnabled(id)) { | 209 if (!extensions_service->IsExtensionEnabled(id)) { |
| 209 DVLOG(1) << "Theme " << id << " is not enabled; aborting"; | 210 DVLOG(1) << "Theme " << id << " is not enabled; aborting"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 231 DVLOG(1) << "Switch to use default theme"; | 232 DVLOG(1) << "Switch to use default theme"; |
| 232 theme_service_->UseDefaultTheme(); | 233 theme_service_->UseDefaultTheme(); |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 | 236 |
| 236 void ThemeSyncableService::GetThemeSpecificsFromCurrentTheme( | 237 void ThemeSyncableService::GetThemeSpecificsFromCurrentTheme( |
| 237 sync_pb::ThemeSpecifics* theme_specifics) const { | 238 sync_pb::ThemeSpecifics* theme_specifics) const { |
| 238 const extensions::Extension* current_theme = | 239 const extensions::Extension* current_theme = |
| 239 theme_service_->UsingDefaultTheme() ? | 240 theme_service_->UsingDefaultTheme() ? |
| 240 NULL : | 241 NULL : |
| 241 profile_->GetExtensionService()->GetExtensionById( | 242 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 242 theme_service_->GetThemeID(), false); | 243 GetExtensionById(theme_service_->GetThemeID(), false); |
| 243 bool use_custom_theme = (current_theme != NULL); | 244 bool use_custom_theme = (current_theme != NULL); |
| 244 theme_specifics->set_use_custom_theme(use_custom_theme); | 245 theme_specifics->set_use_custom_theme(use_custom_theme); |
| 245 if (IsSystemThemeDistinctFromDefaultTheme()) { | 246 if (IsSystemThemeDistinctFromDefaultTheme()) { |
| 246 // On platform where system theme is different from default theme, set | 247 // On platform where system theme is different from default theme, set |
| 247 // use_system_theme_by_default to true if system theme is used, false | 248 // use_system_theme_by_default to true if system theme is used, false |
| 248 // if default system theme is used. Otherwise restore it to value in sync. | 249 // if default system theme is used. Otherwise restore it to value in sync. |
| 249 if (theme_service_->UsingNativeTheme()) { | 250 if (theme_service_->UsingNativeTheme()) { |
| 250 theme_specifics->set_use_system_theme_by_default(true); | 251 theme_specifics->set_use_system_theme_by_default(true); |
| 251 } else if (theme_service_->UsingDefaultTheme()) { | 252 } else if (theme_service_->UsingDefaultTheme()) { |
| 252 theme_specifics->set_use_system_theme_by_default(false); | 253 theme_specifics->set_use_system_theme_by_default(false); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 syncer::SyncChange(FROM_HERE, change_type, | 312 syncer::SyncChange(FROM_HERE, change_type, |
| 312 syncer::SyncData::CreateLocalData( | 313 syncer::SyncData::CreateLocalData( |
| 313 kCurrentThemeClientTag, kCurrentThemeNodeTitle, | 314 kCurrentThemeClientTag, kCurrentThemeNodeTitle, |
| 314 entity_specifics))); | 315 entity_specifics))); |
| 315 | 316 |
| 316 DVLOG(1) << "Update theme specifics from current theme: " | 317 DVLOG(1) << "Update theme specifics from current theme: " |
| 317 << changes.back().ToString(); | 318 << changes.back().ToString(); |
| 318 | 319 |
| 319 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 320 return sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 320 } | 321 } |
| OLD | NEW |