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