extension_util.h revision c407dc5cd9bdc5668497f21b26b09d988ab439de
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_UTIL_H_
6#define CHROME_BROWSER_SYNC_GLUE_EXTENSION_UTIL_H_
7
8#include <string>
9
10class Extension;
11class ExtensionsService;
12
13namespace sync_pb {
14class ExtensionSpecifics;
15}  // sync_pb
16
17namespace browser_sync {
18
19// Returns whether or not the given extension is one we want to sync.
20bool IsExtensionSyncable(const Extension& extension);
21
22// Stringifies the given ExtensionSpecifics.
23std::string ExtensionSpecificsToString(
24    const sync_pb::ExtensionSpecifics& specifics);
25
26// Returns whether or not the values of the given specifics are valid,
27// in particular the id, version, and update URL.
28bool IsExtensionSpecificsValid(
29    const sync_pb::ExtensionSpecifics& specifics);
30
31// Equivalent to DCHECK(IsExtensionSpecificsValid(specifics)) <<
32// ExtensionSpecificsToString(specifics);
33void DcheckIsExtensionSpecificsValid(
34    const sync_pb::ExtensionSpecifics& specifics);
35
36// Returns true iff two ExtensionSpecifics denote the same extension
37// state.  Neither |a| nor |b| need to be valid.
38bool AreExtensionSpecificsEqual(const sync_pb::ExtensionSpecifics& a,
39                                const sync_pb::ExtensionSpecifics& b);
40
41// Returns true iff the given ExtensionSpecifics is equal to the empty
42// ExtensionSpecifics object.  |specifics| does not have to be valid
43// and indeed, IsExtensionSpecificsValid(specifics) ->
44// !IsExtensionSpecificsUnset(specifics).
45bool IsExtensionSpecificsUnset(
46    const sync_pb::ExtensionSpecifics& specifics);
47
48// Copies the user properties from |specifics| into |dest_specifics|.
49// User properties are properties that are set by the user, i.e. not
50// inherent to the extension.  Currently they include |enabled| and
51// |incognito_enabled|.  Neither parameter need be valid.
52void CopyUserProperties(
53    const sync_pb::ExtensionSpecifics& specifics,
54    sync_pb::ExtensionSpecifics* dest_specifics);
55
56// Copies everything but non-user properties.  Neither parameter need
57// be valid.
58void CopyNonUserProperties(
59    const sync_pb::ExtensionSpecifics& specifics,
60    sync_pb::ExtensionSpecifics* dest_specifics);
61
62// Returns true iff two ExtensionSpecifics have the same user
63// properties.  Neither |a| nor |b| need to be valid.
64bool AreExtensionSpecificsUserPropertiesEqual(
65    const sync_pb::ExtensionSpecifics& a,
66    const sync_pb::ExtensionSpecifics& b);
67
68// Returns true iff two ExtensionSpecifics have the same non-user
69// properties.  Neither |a| nor |b| need to be valid.
70bool AreExtensionSpecificsNonUserPropertiesEqual(
71    const sync_pb::ExtensionSpecifics& a,
72    const sync_pb::ExtensionSpecifics& b);
73
74// Fills |specifics| with information taken from |extension|, which
75// must be a syncable extension.  |specifics| will be valid after this
76// function is called.
77void GetExtensionSpecifics(const Extension& extension,
78                           ExtensionsService* extensions_service,
79                           sync_pb::ExtensionSpecifics* specifics);
80
81// Exposed only for testing.  Pre- and post-conditions are the same as
82// GetExtensionSpecifics().
83void GetExtensionSpecificsHelper(const Extension& extension,
84                                 bool enabled, bool incognito_enabled,
85                                 sync_pb::ExtensionSpecifics* specifics);
86
87// Returns whether or not the extension should be updated according to
88// the specifics.  |extension| must be syncable and |specifics| must
89// be valid.
90bool IsExtensionOutdated(const Extension& extension,
91                         const sync_pb::ExtensionSpecifics& specifics);
92
93// Sets properties of |extension| according to the information in
94// specifics.  |extension| must be syncable and |specifics| must be
95// valid.
96void SetExtensionProperties(
97    const sync_pb::ExtensionSpecifics& specifics,
98    ExtensionsService* extensions_service, Extension* extension);
99
100// Merge |specifics| into |merged_specifics|.  Both must be valid and
101// have the same ID.  The merge policy is currently to copy the
102// non-user properties of |specifics| into |merged_specifics| (and the
103// user properties if |merge_user_properties| is set) if |specifics|
104// has a more recent or the same version as |merged_specifics|.
105void MergeExtensionSpecifics(
106    const sync_pb::ExtensionSpecifics& specifics,
107    bool merge_user_properties,
108    sync_pb::ExtensionSpecifics* merged_specifics);
109
110}  // namespace browser_sync
111
112#endif  // CHROME_BROWSER_SYNC_GLUE_EXTENSION_UTIL_H_
113