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