• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_TRAITS_H_
6 #define CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_TRAITS_H_
7 #pragma once
8 
9 #include "chrome/browser/sync/syncable/model_type.h"
10 
11 class Extension;
12 struct UninstalledExtensionInfo;
13 
14 namespace sync_api {
15 class BaseNode;
16 class WriteNode;
17 }  // namespace sync_api
18 
19 namespace sync_pb {
20 class EntitySpecifics;
21 class ExtensionSpecifics;
22 }  // namespace sync_pb
23 
24 namespace browser_sync {
25 
26 typedef bool (*IsValidAndSyncablePredicate)(const Extension&);
27 
28 typedef bool (*ShouldHandleExtensionUninstallPredicate)(
29     const UninstalledExtensionInfo&);
30 
31 // ExtensionSpecificsGetter : BaseNode -> ExtensionSpecifics
32 typedef const sync_pb::ExtensionSpecifics& (*ExtensionSpecificsGetter)(
33     const sync_api::BaseNode&);
34 
35 // A function that sets the appropriate member of the given BaseNode
36 // to the given ExtensionSpecifics.
37 typedef void (*ExtensionSpecificsSetter)(
38     const sync_pb::ExtensionSpecifics&, sync_api::WriteNode*);
39 
40 // A function that tries to retrieve an ExtensionSpecifics from an
41 // EntitySpecifics.  Returns true and fills in the second argument iff
42 // successful.
43 typedef bool (*ExtensionSpecificsEntityGetter)(
44     const sync_pb::EntitySpecifics&, sync_pb::ExtensionSpecifics*);
45 
46 // Represents the properties needed for syncing data types that
47 // involve extensions (e.g., "real" extensions, apps).
48 struct ExtensionSyncTraits {
49   ExtensionSyncTraits(
50       syncable::ModelType model_type,
51       IsValidAndSyncablePredicate is_valid_and_syncable,
52       ShouldHandleExtensionUninstallPredicate
53           should_handle_extension_uninstall,
54       const char* root_node_tag,
55       ExtensionSpecificsGetter extension_specifics_getter,
56       ExtensionSpecificsSetter extension_specifics_setter,
57       ExtensionSpecificsEntityGetter extension_specifics_entity_getter);
58   ~ExtensionSyncTraits();
59 
60   // The sync type for the data type.
61   const syncable::ModelType model_type;
62   // A checker to make sure that the downloaded extension is valid and
63   // syncable.
64   const IsValidAndSyncablePredicate is_valid_and_syncable;
65   // A checker to know which extension uninstall events to handle.
66   const ShouldHandleExtensionUninstallPredicate
67       should_handle_extension_uninstall;
68   // The tag with which the top-level data type node is marked.
69   const char* const root_node_tag;
70   // The function that retrieves a ExtensionSpecifics reference (which
71   // may be embedded in another specifics object) from a sync node.
72   const ExtensionSpecificsGetter extension_specifics_getter;
73   // The function that embeds an ExtensionSpecifics into a sync node.
74   const ExtensionSpecificsSetter extension_specifics_setter;
75   // The function that retrieves a ExtensionSpecifics (if possible)
76   // from an EntitySpecifics.
77   ExtensionSpecificsEntityGetter extension_specifics_entity_getter;
78 };
79 
80 // Gets traits for extensions sync.
81 ExtensionSyncTraits GetExtensionSyncTraits();
82 
83 // Gets traits for apps sync.
84 ExtensionSyncTraits GetAppSyncTraits();
85 
86 }  // namespace browser_sync
87 
88 #endif  // CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_TRAITS_H_
89