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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_H_
6#define CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_H_
7#pragma once
8
9// This file contains functions necessary for syncing
10// extensions-related data types.
11
12#include <map>
13#include <string>
14
15class Extension;
16class ExtensionServiceInterface;
17class Profile;
18class ProfileSyncService;
19
20namespace sync_api {
21struct UserShare;
22}  // namespace sync_api
23
24namespace sync_pb {
25class ExtensionSpecifics;
26}  // namespace sync_pb
27
28namespace browser_sync {
29
30class ExtensionData;
31struct ExtensionSyncTraits;
32
33// A map from extension IDs to ExtensionData objects.
34typedef std::map<std::string, ExtensionData> ExtensionDataMap;
35
36// Fills in |has_children| with whether or not the root node with the
37// given tag has child nodes.  Returns true iff the lookup succeeded.
38//
39// TODO(akalin): Move this somewhere where it can be used by
40// other data types.
41bool RootNodeHasChildren(const char* tag,
42                         sync_api::UserShare* user_share,
43                         bool* has_children);
44
45// Fills |extension_data_map| with both client-side information about
46// installed extensions and the server-side information about
47// extensions to be synced.  Returns true iff this was successful; if
48// unsuccessful, the contents of |extension_data_map| are undefined.
49bool SlurpExtensionData(const ExtensionSyncTraits& traits,
50                        const ExtensionServiceInterface& extensions_service,
51                        sync_api::UserShare* user_share,
52                        ExtensionDataMap* extension_data_map);
53
54// Updates the server and client as necessary from
55// |extension_data_map|.  Returns true iff this was successful.
56//
57// NOTE(akalin): Keep in mind that updating the client is an
58// asynchronous process; the only thing that's guaranteed if this
59// function is returned is that the updates were successfully started.
60bool FlushExtensionData(const ExtensionSyncTraits& traits,
61                        const ExtensionDataMap& extension_data_map,
62                        ExtensionServiceInterface* extensions_service,
63                        sync_api::UserShare* user_share);
64
65// Updates the server data for the given extension.  Returns true iff
66// this was successful; if unsuccessful, an error string is put into
67// |error|.
68bool UpdateServerData(const ExtensionSyncTraits& traits,
69                      const Extension& extension,
70                      const ExtensionServiceInterface& extensions_service,
71                      sync_api::UserShare* user_share,
72                      std::string* error);
73
74// Removes the server data for the given extension ID.
75void RemoveServerData(const ExtensionSyncTraits& traits,
76                      const std::string& id,
77                      sync_api::UserShare* user_share);
78
79}  // namespace browser_sync
80
81#endif  // CHROME_BROWSER_SYNC_GLUE_EXTENSION_SYNC_H_
82