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_DATA_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_EXTENSION_DATA_H_ 7 #pragma once 8 9 // ExtensionData is the class used to manage the client and server 10 // versions of the data for a particular extension. 11 12 #include <map> 13 14 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 15 16 namespace browser_sync { 17 18 class ExtensionData { 19 public: 20 enum Source { 21 CLIENT, 22 SERVER, 23 }; 24 25 // Returns an ExtensionData constructed from the given data from the 26 // given source. merged_data() will be equal to |data| and 27 // NeedsUpdate(source) will return false. 28 static ExtensionData FromData( 29 Source source, const sync_pb::ExtensionSpecifics& data); 30 31 ~ExtensionData(); 32 33 // Implicit copy constructor and assignment operator welcome. 34 35 // Returns the version of the data that all sources should 36 // eventually have. 37 const sync_pb::ExtensionSpecifics& merged_data() const; 38 39 // Returns whether or not the data from the given source needs to be 40 // updated from merged_data(). 41 bool NeedsUpdate(Source source) const; 42 43 // Stores the given data as being from the given source, merging it 44 // into merged_data(). May change what NeedsUpdate() returns for 45 // any source. 46 void SetData( 47 Source source, bool merge_user_properties, 48 const sync_pb::ExtensionSpecifics& data); 49 50 // Marks the data from the given data as updated, 51 // i.e. NeedsUpdate(source) will return false. 52 void ResolveData(Source source); 53 54 private: 55 typedef std::map<Source, sync_pb::ExtensionSpecifics> SourceDataMap; 56 SourceDataMap source_data_; 57 sync_pb::ExtensionSpecifics merged_data_; 58 59 // This is private; clients must use FromData(). 60 ExtensionData(); 61 }; 62 63 } // namespace 64 65 #endif // CHROME_BROWSER_SYNC_GLUE_EXTENSION_DATA_H_ 66