| OLD | NEW |
| 1 // Copyright (c) 2010 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/extension_sync_traits.h" | 5 #include "chrome/browser/sync/glue/extension_sync_traits.h" |
| 6 | 6 |
| 7 #include "base/string_piece.h" | 7 #include "base/string_piece.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/sync/engine/syncapi.h" | 9 #include "chrome/browser/sync/engine/syncapi.h" |
| 10 #include "chrome/browser/sync/glue/extension_util.h" | 10 #include "chrome/browser/sync/glue/extension_util.h" |
| 11 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 11 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
| 12 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
| 14 | 14 |
| 15 namespace browser_sync { | 15 namespace browser_sync { |
| 16 | 16 |
| 17 ExtensionSyncTraits::ExtensionSyncTraits( | 17 ExtensionSyncTraits::ExtensionSyncTraits( |
| 18 syncable::ModelType model_type, | 18 syncable::ModelType model_type, |
| 19 IsValidAndSyncablePredicate is_valid_and_syncable, | 19 IsValidAndSyncablePredicate is_valid_and_syncable, |
| 20 ShouldHandleExtensionUninstallPredicate | |
| 21 should_handle_extension_uninstall, | |
| 22 const char* root_node_tag, | 20 const char* root_node_tag, |
| 23 ExtensionSpecificsGetter extension_specifics_getter, | 21 ExtensionSpecificsGetter extension_specifics_getter, |
| 24 ExtensionSpecificsSetter extension_specifics_setter, | 22 ExtensionSpecificsSetter extension_specifics_setter, |
| 25 ExtensionSpecificsEntityGetter extension_specifics_entity_getter) | 23 ExtensionSpecificsEntityGetter extension_specifics_entity_getter) |
| 26 : model_type(model_type), | 24 : model_type(model_type), |
| 27 is_valid_and_syncable(is_valid_and_syncable), | 25 is_valid_and_syncable(is_valid_and_syncable), |
| 28 should_handle_extension_uninstall(should_handle_extension_uninstall), | |
| 29 root_node_tag(root_node_tag), | 26 root_node_tag(root_node_tag), |
| 30 extension_specifics_getter(extension_specifics_getter), | 27 extension_specifics_getter(extension_specifics_getter), |
| 31 extension_specifics_setter(extension_specifics_setter), | 28 extension_specifics_setter(extension_specifics_setter), |
| 32 extension_specifics_entity_getter(extension_specifics_entity_getter) {} | 29 extension_specifics_entity_getter(extension_specifics_entity_getter) {} |
| 33 | 30 |
| 34 ExtensionSyncTraits::~ExtensionSyncTraits() {} | 31 ExtensionSyncTraits::~ExtensionSyncTraits() {} |
| 35 | 32 |
| 36 namespace { | 33 namespace { |
| 37 | 34 |
| 38 const sync_pb::ExtensionSpecifics& GetExtensionSpecifics( | 35 const sync_pb::ExtensionSpecifics& GetExtensionSpecifics( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 68 return false; | 65 return false; |
| 69 } | 66 } |
| 70 } | 67 } |
| 71 | 68 |
| 72 bool IsValidAndSyncableExtension(const Extension& extension) { | 69 bool IsValidAndSyncableExtension(const Extension& extension) { |
| 73 return | 70 return |
| 74 IsExtensionValid(extension) && | 71 IsExtensionValid(extension) && |
| 75 IsSyncableExtension(extension.GetType(), extension.update_url()); | 72 IsSyncableExtension(extension.GetType(), extension.update_url()); |
| 76 } | 73 } |
| 77 | 74 |
| 78 bool IsExtensionUninstall( | |
| 79 const UninstalledExtensionInfo& uninstalled_extension_info) { | |
| 80 return IsSyncableExtension(uninstalled_extension_info.extension_type, | |
| 81 uninstalled_extension_info.update_url); | |
| 82 } | |
| 83 | |
| 84 } // namespace | 75 } // namespace |
| 85 | 76 |
| 86 ExtensionSyncTraits GetExtensionSyncTraits() { | 77 ExtensionSyncTraits GetExtensionSyncTraits() { |
| 87 return ExtensionSyncTraits(syncable::EXTENSIONS, | 78 return ExtensionSyncTraits(syncable::EXTENSIONS, |
| 88 &IsValidAndSyncableExtension, | 79 &IsValidAndSyncableExtension, |
| 89 &IsExtensionUninstall, | |
| 90 "google_chrome_extensions", | 80 "google_chrome_extensions", |
| 91 &GetExtensionSpecifics, | 81 &GetExtensionSpecifics, |
| 92 &SetExtensionSpecifics, | 82 &SetExtensionSpecifics, |
| 93 &GetExtensionSpecificsFromEntity); | 83 &GetExtensionSpecificsFromEntity); |
| 94 } | 84 } |
| 95 | 85 |
| 96 namespace { | 86 namespace { |
| 97 | 87 |
| 98 const sync_pb::ExtensionSpecifics& GetExtensionSpecificsOfApp( | 88 const sync_pb::ExtensionSpecifics& GetExtensionSpecificsOfApp( |
| 99 const sync_api::BaseNode& node) { | 89 const sync_api::BaseNode& node) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 124 return | 114 return |
| 125 (type == Extension::TYPE_HOSTED_APP) || | 115 (type == Extension::TYPE_HOSTED_APP) || |
| 126 (type == Extension::TYPE_PACKAGED_APP); | 116 (type == Extension::TYPE_PACKAGED_APP); |
| 127 } | 117 } |
| 128 | 118 |
| 129 bool IsValidAndSyncableApp( | 119 bool IsValidAndSyncableApp( |
| 130 const Extension& extension) { | 120 const Extension& extension) { |
| 131 return IsExtensionValid(extension) && IsSyncableApp(extension.GetType()); | 121 return IsExtensionValid(extension) && IsSyncableApp(extension.GetType()); |
| 132 } | 122 } |
| 133 | 123 |
| 134 bool IsAppUninstall( | |
| 135 const UninstalledExtensionInfo& uninstalled_extension_info) { | |
| 136 return IsSyncableApp(uninstalled_extension_info.extension_type); | |
| 137 } | |
| 138 | |
| 139 } // namespace | 124 } // namespace |
| 140 | 125 |
| 141 ExtensionSyncTraits GetAppSyncTraits() { | 126 ExtensionSyncTraits GetAppSyncTraits() { |
| 142 return ExtensionSyncTraits(syncable::APPS, | 127 return ExtensionSyncTraits(syncable::APPS, |
| 143 &IsValidAndSyncableApp, | 128 &IsValidAndSyncableApp, |
| 144 &IsAppUninstall, | |
| 145 "google_chrome_apps", | 129 "google_chrome_apps", |
| 146 &GetExtensionSpecificsOfApp, | 130 &GetExtensionSpecificsOfApp, |
| 147 &SetExtensionSpecificsOfApp, | 131 &SetExtensionSpecificsOfApp, |
| 148 &GetExtensionSpecificsFromEntityOfApp); | 132 &GetExtensionSpecificsFromEntityOfApp); |
| 149 } | 133 } |
| 150 | 134 |
| 151 } // namespace browser_sync | 135 } // namespace browser_sync |
| OLD | NEW |