OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/glue/extension_sync_traits.h" |
| 6 |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/sync/engine/syncapi.h" |
| 9 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 10 |
| 11 namespace browser_sync { |
| 12 |
| 13 ExtensionSyncTraits::ExtensionSyncTraits( |
| 14 syncable::ModelType model_type, |
| 15 const char* root_node_tag, |
| 16 const ExtensionTypeSet& allowed_extension_types, |
| 17 ExtensionSpecificsGetter extension_specifics_getter, |
| 18 ExtensionSpecificsSetter extension_specifics_setter, |
| 19 ExtensionSpecificsEntityGetter extension_specifics_entity_getter) |
| 20 : model_type(model_type), |
| 21 root_node_tag(root_node_tag), |
| 22 allowed_extension_types(allowed_extension_types), |
| 23 extension_specifics_getter(extension_specifics_getter), |
| 24 extension_specifics_setter(extension_specifics_setter), |
| 25 extension_specifics_entity_getter(extension_specifics_entity_getter) {} |
| 26 |
| 27 namespace { |
| 28 |
| 29 const sync_pb::ExtensionSpecifics& GetExtensionSpecifics( |
| 30 const sync_api::BaseNode& node) { |
| 31 return node.GetExtensionSpecifics(); |
| 32 } |
| 33 |
| 34 void SetExtensionSpecifics( |
| 35 const sync_pb::ExtensionSpecifics& extension_specifics, |
| 36 sync_api::WriteNode* node) { |
| 37 node->SetTitle(UTF8ToWide(extension_specifics.name())); |
| 38 node->SetExtensionSpecifics(extension_specifics); |
| 39 } |
| 40 |
| 41 bool GetExtensionSpecificsFromEntity( |
| 42 const sync_pb::EntitySpecifics& entity_specifics, |
| 43 sync_pb::ExtensionSpecifics* extension_specifics) { |
| 44 if (!entity_specifics.HasExtension(sync_pb::extension)) { |
| 45 return false; |
| 46 } |
| 47 *extension_specifics = entity_specifics.GetExtension(sync_pb::extension); |
| 48 return true; |
| 49 } |
| 50 |
| 51 } // namespace |
| 52 |
| 53 ExtensionSyncTraits GetExtensionSyncTraits() { |
| 54 ExtensionTypeSet allowed_extension_types; |
| 55 allowed_extension_types.insert(EXTENSION); |
| 56 // We allow user scripts since some of them are actually uploaded to |
| 57 // the gallery as extensions (!). |
| 58 allowed_extension_types.insert(USER_SCRIPT); |
| 59 return ExtensionSyncTraits(syncable::EXTENSIONS, |
| 60 "google_chrome_extensions", |
| 61 allowed_extension_types, |
| 62 &GetExtensionSpecifics, |
| 63 &SetExtensionSpecifics, |
| 64 &GetExtensionSpecificsFromEntity); |
| 65 } |
| 66 |
| 67 } // namespace browser_sync |
OLD | NEW |