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/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/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 : sync_service_(sync_service), | 37 : sync_service_(sync_service), |
38 error_handler_(error_handler) { | 38 error_handler_(error_handler) { |
39 DCHECK(sync_service_); | 39 DCHECK(sync_service_); |
40 } | 40 } |
41 | 41 |
42 ThemeModelAssociator::~ThemeModelAssociator() {} | 42 ThemeModelAssociator::~ThemeModelAssociator() {} |
43 | 43 |
44 SyncError ThemeModelAssociator::AssociateModels() { | 44 SyncError ThemeModelAssociator::AssociateModels() { |
45 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 45 sync_api::WriteTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
46 sync_api::ReadNode root(&trans); | 46 sync_api::ReadNode root(&trans); |
47 if (!root.InitByTagLookup(kThemesTag)) { | 47 if (root.InitByTagLookup(kThemesTag) != sync_api::BaseNode::INIT_OK) { |
48 return error_handler_->CreateAndUploadError(FROM_HERE, | 48 return error_handler_->CreateAndUploadError(FROM_HERE, |
49 kNoThemesFolderError, | 49 kNoThemesFolderError, |
50 model_type()); | 50 model_type()); |
51 } | 51 } |
52 | 52 |
53 Profile* profile = sync_service_->profile(); | 53 Profile* profile = sync_service_->profile(); |
54 sync_api::WriteNode node(&trans); | 54 sync_api::WriteNode node(&trans); |
55 // TODO(akalin): When we have timestamps, we may want to do | 55 // TODO(akalin): When we have timestamps, we may want to do |
56 // something more intelligent than preferring the sync data over our | 56 // something more intelligent than preferring the sync data over our |
57 // local data. | 57 // local data. |
58 if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag)) { | 58 if (node.InitByClientTagLookup(syncable::THEMES, kCurrentThemeClientTag) == |
| 59 sync_api::BaseNode::INIT_OK) { |
59 // Update the current theme from the sync data. | 60 // Update the current theme from the sync data. |
60 // TODO(akalin): If the sync data does not have | 61 // TODO(akalin): If the sync data does not have |
61 // use_system_theme_by_default and we do, update that flag on the | 62 // use_system_theme_by_default and we do, update that flag on the |
62 // sync data. | 63 // sync data. |
63 sync_pb::ThemeSpecifics theme_specifics = node.GetThemeSpecifics(); | 64 sync_pb::ThemeSpecifics theme_specifics = node.GetThemeSpecifics(); |
64 if (UpdateThemeSpecificsOrSetCurrentThemeIfNecessary(profile, | 65 if (UpdateThemeSpecificsOrSetCurrentThemeIfNecessary(profile, |
65 &theme_specifics)) | 66 &theme_specifics)) |
66 node.SetThemeSpecifics(theme_specifics); | 67 node.SetThemeSpecifics(theme_specifics); |
67 } else { | 68 } else { |
68 // Set the sync data from the current theme. | 69 // Set the sync data from the current theme. |
(...skipping 17 matching lines...) Expand all Loading... |
86 SyncError ThemeModelAssociator::DisassociateModels() { | 87 SyncError ThemeModelAssociator::DisassociateModels() { |
87 // We don't maintain any association state, so nothing to do. | 88 // We don't maintain any association state, so nothing to do. |
88 return SyncError(); | 89 return SyncError(); |
89 } | 90 } |
90 | 91 |
91 bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { | 92 bool ThemeModelAssociator::SyncModelHasUserCreatedNodes(bool* has_nodes) { |
92 DCHECK(has_nodes); | 93 DCHECK(has_nodes); |
93 *has_nodes = false; | 94 *has_nodes = false; |
94 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 95 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
95 sync_api::ReadNode root(&trans); | 96 sync_api::ReadNode root(&trans); |
96 if (!root.InitByTagLookup(kThemesTag)) { | 97 if (root.InitByTagLookup(kThemesTag) != sync_api::BaseNode::INIT_OK) { |
97 LOG(ERROR) << kNoThemesFolderError; | 98 LOG(ERROR) << kNoThemesFolderError; |
98 return false; | 99 return false; |
99 } | 100 } |
100 // The sync model has user created nodes iff the themes folder has | 101 // The sync model has user created nodes iff the themes folder has |
101 // any children. | 102 // any children. |
102 *has_nodes = root.HasChildren(); | 103 *has_nodes = root.HasChildren(); |
103 return true; | 104 return true; |
104 } | 105 } |
105 | 106 |
106 bool ThemeModelAssociator::CryptoReadyIfNecessary() { | 107 bool ThemeModelAssociator::CryptoReadyIfNecessary() { |
107 // We only access the cryptographer while holding a transaction. | 108 // We only access the cryptographer while holding a transaction. |
108 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); | 109 sync_api::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); |
109 const syncable::ModelTypeSet encrypted_types = | 110 const syncable::ModelTypeSet encrypted_types = |
110 sync_api::GetEncryptedTypes(&trans); | 111 sync_api::GetEncryptedTypes(&trans); |
111 return !encrypted_types.Has(syncable::THEMES) || | 112 return !encrypted_types.Has(syncable::THEMES) || |
112 sync_service_->IsCryptographerReady(&trans); | 113 sync_service_->IsCryptographerReady(&trans); |
113 } | 114 } |
114 | 115 |
115 } // namespace browser_sync | 116 } // namespace browser_sync |
OLD | NEW |