Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/sync/glue/theme_model_associator.cc

Issue 7497014: Revert 94128 - [Sync] Refactor sync datatype error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_model_associator.h" 5 #include "chrome/browser/sync/glue/theme_model_associator.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/tracked.h" 9 #include "base/tracked.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/sync/api/sync_error.h"
12 #include "chrome/browser/sync/engine/syncapi.h" 11 #include "chrome/browser/sync/engine/syncapi.h"
13 #include "chrome/browser/sync/glue/sync_backend_host.h" 12 #include "chrome/browser/sync/glue/sync_backend_host.h"
14 #include "chrome/browser/sync/glue/theme_util.h" 13 #include "chrome/browser/sync/glue/theme_util.h"
15 #include "chrome/browser/sync/profile_sync_service.h" 14 #include "chrome/browser/sync/profile_sync_service.h"
16 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" 15 #include "chrome/browser/sync/protocol/theme_specifics.pb.h"
17 16
18 namespace browser_sync { 17 namespace browser_sync {
19 18
20 namespace { 19 namespace {
21 20
22 static const char kThemesTag[] = "google_chrome_themes"; 21 static const char kThemesTag[] = "google_chrome_themes";
23 static const char kCurrentThemeNodeTitle[] = "Current Theme"; 22 static const char kCurrentThemeNodeTitle[] = "Current Theme";
24 23
25 static const char kNoThemesFolderError[] = 24 static const char kNoThemesFolderError[] =
26 "Server did not create the top-level themes node. We " 25 "Server did not create the top-level themes node. We "
27 "might be running against an out-of-date server."; 26 "might be running against an out-of-date server.";
28 27
29 } // namespace 28 } // namespace
30 29
31 ThemeModelAssociator::ThemeModelAssociator( 30 ThemeModelAssociator::ThemeModelAssociator(
32 ProfileSyncService* sync_service) 31 ProfileSyncService* sync_service)
33 : sync_service_(sync_service) { 32 : sync_service_(sync_service) {
34 DCHECK(sync_service_); 33 DCHECK(sync_service_);
35 } 34 }
36 35
37 ThemeModelAssociator::~ThemeModelAssociator() {} 36 ThemeModelAssociator::~ThemeModelAssociator() {}
38 37
39 bool ThemeModelAssociator::AssociateModels(SyncError* error) { 38 bool ThemeModelAssociator::AssociateModels() {
40 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 39 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare());
41 sync_api::ReadNode root(&trans); 40 sync_api::ReadNode root(&trans);
42 if (!root.InitByTagLookup(kThemesTag)) { 41 if (!root.InitByTagLookup(kThemesTag)) {
43 error->Reset(FROM_HERE, kNoThemesFolderError, model_type()); 42 LOG(ERROR) << kNoThemesFolderError;
44 return false; 43 return false;
45 } 44 }
46 45
47 Profile* profile = sync_service_->profile(); 46 Profile* profile = sync_service_->profile();
48 sync_api::WriteNode node(&trans); 47 sync_api::WriteNode node(&trans);
49 // TODO(akalin): When we have timestamps, we may want to do 48 // TODO(akalin): When we have timestamps, we may want to do
50 // something more intelligent than preferring the sync data over our 49 // something more intelligent than preferring the sync data over our
51 // local data. 50 // local data.
52 if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag)) { 51 if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag)) {
53 // Update the current theme from the sync data. 52 // Update the current theme from the sync data.
54 // TODO(akalin): If the sync data does not have 53 // TODO(akalin): If the sync data does not have
55 // use_system_theme_by_default and we do, update that flag on the 54 // use_system_theme_by_default and we do, update that flag on the
56 // sync data. 55 // sync data.
57 sync_pb::ThemeSpecifics theme_specifics = node.GetThemeSpecifics(); 56 sync_pb::ThemeSpecifics theme_specifics = node.GetThemeSpecifics();
58 if (UpdateThemeSpecificsOrSetCurrentThemeIfNecessary(profile, 57 if (UpdateThemeSpecificsOrSetCurrentThemeIfNecessary(profile,
59 &theme_specifics)) 58 &theme_specifics))
60 node.SetThemeSpecifics(theme_specifics); 59 node.SetThemeSpecifics(theme_specifics);
61 } else { 60 } else {
62 // Set the sync data from the current theme. 61 // Set the sync data from the current theme.
63 sync_api::WriteNode node(&trans); 62 sync_api::WriteNode node(&trans);
64 if (!node.InitUniqueByCreation(syncable::THEMES, root, 63 if (!node.InitUniqueByCreation(syncable::THEMES, root,
65 kCurrentThemeClientTag)) { 64 kCurrentThemeClientTag)) {
66 error->Reset(FROM_HERE, 65 LOG(ERROR) << "Could not create current theme node.";
67 "Could not create current theme node.",
68 model_type());
69 return false; 66 return false;
70 } 67 }
71 node.SetIsFolder(false); 68 node.SetIsFolder(false);
72 node.SetTitle(UTF8ToWide(kCurrentThemeNodeTitle)); 69 node.SetTitle(UTF8ToWide(kCurrentThemeNodeTitle));
73 sync_pb::ThemeSpecifics theme_specifics; 70 sync_pb::ThemeSpecifics theme_specifics;
74 GetThemeSpecificsFromCurrentTheme(profile, &theme_specifics); 71 GetThemeSpecificsFromCurrentTheme(profile, &theme_specifics);
75 node.SetThemeSpecifics(theme_specifics); 72 node.SetThemeSpecifics(theme_specifics);
76 } 73 }
77 return true; 74 return true;
78 } 75 }
79 76
80 bool ThemeModelAssociator::DisassociateModels(SyncError* error) { 77 bool ThemeModelAssociator::DisassociateModels() {
81 // We don't maintain any association state, so nothing to do. 78 // We don't maintain any association state, so nothing to do.
82 return true; 79 return true;
83 } 80 }
84 81
85 bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { 82 bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) {
86 DCHECK(has_nodes); 83 DCHECK(has_nodes);
87 *has_nodes = false; 84 *has_nodes = false;
88 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 85 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
89 sync_api::ReadNode root(&trans); 86 sync_api::ReadNode root(&trans);
90 if (!root.InitByTagLookup(kThemesTag)) { 87 if (!root.InitByTagLookup(kThemesTag)) {
91 LOG(ERROR) << kNoThemesFolderError; 88 LOG(ERROR) << kNoThemesFolderError;
92 return false; 89 return false;
93 } 90 }
94 // The sync model has user created nodes iff the themes folder has 91 // The sync model has user created nodes iff the themes folder has
95 // any children. 92 // any children.
96 *has_nodes = root.GetFirstChildId() != sync_api::kInvalidId; 93 *has_nodes = root.GetFirstChildId() != sync_api::kInvalidId;
97 return true; 94 return true;
98 } 95 }
99 96
100 bool ThemeModelAssociator::CryptoReadyIfNecessary() { 97 bool ThemeModelAssociator::CryptoReadyIfNecessary() {
101 // We only access the cryptographer while holding a transaction. 98 // We only access the cryptographer while holding a transaction.
102 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 99 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
103 syncable::ModelTypeSet encrypted_types; 100 syncable::ModelTypeSet encrypted_types;
104 encrypted_types = sync_api::GetEncryptedTypes(&trans); 101 encrypted_types = sync_api::GetEncryptedTypes(&trans);
105 return encrypted_types.count(syncable::THEMES) == 0 || 102 return encrypted_types.count(syncable::THEMES) == 0 ||
106 sync_service_->IsCryptographerReady(&trans); 103 sync_service_->IsCryptographerReady(&trans);
107 } 104 }
108 105
109 } // namespace browser_sync 106 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/theme_model_associator.h ('k') | chrome/browser/sync/glue/typed_url_model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698