diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-29 20:04:05 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-29 20:04:05 +0000 |
commit | 60cab460a9f891d34efacddd3efc10d89279b6d6 (patch) | |
tree | 5edbf5cafb368c09a386bf3dcf122077d067c396 /chrome/browser/sync/glue/theme_model_associator.cc | |
parent | c5e401ad5812699fafaf41492015eb26174084ed (diff) | |
download | chromium_src-60cab460a9f891d34efacddd3efc10d89279b6d6.zip chromium_src-60cab460a9f891d34efacddd3efc10d89279b6d6.tar.gz chromium_src-60cab460a9f891d34efacddd3efc10d89279b6d6.tar.bz2 |
Implemented initial version of themes syncing (behind a flag).
BUG=32414
TEST=manual,unittests,trybot
Review URL: http://codereview.chromium.org/1399001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42984 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/glue/theme_model_associator.cc')
-rw-r--r-- | chrome/browser/sync/glue/theme_model_associator.cc | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/chrome/browser/sync/glue/theme_model_associator.cc b/chrome/browser/sync/glue/theme_model_associator.cc new file mode 100644 index 0000000..c4f87ce --- /dev/null +++ b/chrome/browser/sync/glue/theme_model_associator.cc @@ -0,0 +1,111 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/sync/glue/theme_model_associator.h" + +#include "base/basictypes.h" +#include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/browser_theme_provider.h" +#include "chrome/browser/sync/engine/syncapi.h" +#include "chrome/browser/sync/glue/sync_backend_host.h" +#include "chrome/browser/sync/glue/theme_util.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/protocol/theme_specifics.pb.h" +#include "chrome/browser/sync/unrecoverable_error_handler.h" + +namespace browser_sync { + +namespace { + +static const char kThemesTag[] = "google_chrome_themes"; +static const char kCurrentThemeNodeTitle[] = "Current Theme"; + +static const char kNoThemesFolderError[] = + "Server did not create the top-level themes node. We " + "might be running against an out-of-date server."; + +} // namespace + +ThemeModelAssociator::ThemeModelAssociator( + ProfileSyncService* sync_service, + UnrecoverableErrorHandler* error_handler) + : sync_service_(sync_service), + error_handler_(error_handler) { + DCHECK(sync_service_); + DCHECK(error_handler_); +} + +ThemeModelAssociator::~ThemeModelAssociator() {} + +bool ThemeModelAssociator::AssociateModels() { + sync_api::WriteTransaction trans( + sync_service_->backend()->GetUserShareHandle()); + sync_api::ReadNode root(&trans); + if (!root.InitByTagLookup(kThemesTag)) { + LOG(ERROR) << kNoThemesFolderError; + error_handler_->OnUnrecoverableError(); + return false; + } + + Profile* profile = sync_service_->profile(); + sync_api::ReadNode node(&trans); + // TODO(akalin): When we have timestamps, we may want to do + // something more intelligent than preferring the sync data over our + // local data. + if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag)) { + // Update the current theme from the sync data. + // TODO(akalin): If the sync data does not have + // use_system_theme_by_default and we do, update that flag on the + // sync data. + SetCurrentThemeFromThemeSpecificsIfNecessary( + node.GetThemeSpecifics(), profile); + } else { + // Set the sync data from the current theme. + sync_api::WriteNode node(&trans); + if (!node.InitUniqueByCreation(syncable::THEMES, root, + kCurrentThemeClientTag)) { + LOG(ERROR) << "Could not create current theme node."; + error_handler_->OnUnrecoverableError(); + return false; + } + node.SetIsFolder(false); + node.SetTitle(UTF8ToWide(kCurrentThemeNodeTitle)); + sync_pb::ThemeSpecifics theme_specifics; + GetThemeSpecificsFromCurrentTheme(profile, &theme_specifics); + node.SetThemeSpecifics(theme_specifics); + } + return true; +} + +bool ThemeModelAssociator::DisassociateModels() { + // We don't maintain any association state, so nothing to do. + return true; +} + +bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { + DCHECK(has_nodes); + *has_nodes = false; + sync_api::ReadTransaction trans( + sync_service_->backend()->GetUserShareHandle()); + sync_api::ReadNode root(&trans); + if (!root.InitByTagLookup(kThemesTag)) { + error_handler_->OnUnrecoverableError(); + LOG(ERROR) << kNoThemesFolderError; + return false; + } + // The sync model has user created nodes iff the themes folder has + // any children. + *has_nodes = root.GetFirstChildId() != sync_api::kInvalidId; + return true; +} + +bool ThemeModelAssociator::ChromeModelHasUserCreatedNodes(bool* has_nodes) { + DCHECK(has_nodes); + // Assume the themes model always has user-created nodes. + *has_nodes = true; + return true; +} + +} // namespace browser_sync |