model_type.h revision 201ade2fbba22bfb27ae029f4d23fca6ded109a0
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// Enumerate the various item subtypes that are supported by sync. 6// Each sync object is expected to have an immutable object type. 7// An object's type is inferred from the type of data it holds. 8 9#ifndef CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ 10#define CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ 11#pragma once 12 13#include <bitset> 14#include <set> 15#include <string> 16 17#include "base/logging.h" 18#include "base/time.h" 19 20namespace sync_pb { 21class EntitySpecifics; 22class SyncEntity; 23} 24 25namespace syncable { 26 27enum ModelType { 28 // Object type unknown. Objects may transition through 29 // the unknown state during their initial creation, before 30 // their properties are set. After deletion, object types 31 // are generally preserved. 32 UNSPECIFIED, 33 // A permanent folder whose children may be of mixed 34 // datatypes (e.g. the "Google Chrome" folder). 35 TOP_LEVEL_FOLDER, 36 37 // ------------------------------------ Start of "real" model types. 38 // The model types declared before here are somewhat special, as they 39 // they do not correspond to any browser data model. The remaining types 40 // are bona fide model types; all have a related browser data model and 41 // can be represented in the protocol using an extension to the 42 // EntitySpecifics protocol buffer. 43 // 44 // A bookmark folder or a bookmark URL object. 45 BOOKMARKS, 46 FIRST_REAL_MODEL_TYPE = BOOKMARKS, // Declared 2nd, for debugger prettiness. 47 48 // A preference folder or a preference object. 49 PREFERENCES, 50 // A password folder or password object. 51 PASSWORDS, 52 // An autofill folder or an autofill object. 53 AUTOFILL, 54 // An autofill Profile Object 55 AUTOFILL_PROFILE, 56 // A themes folder or a themes object. 57 THEMES, 58 // A typed_url folder or a typed_url object. 59 TYPED_URLS, 60 // An extension folder or an extension object. 61 EXTENSIONS, 62 // An object represeting a set of Nigori keys. 63 NIGORI, 64 // An object representing a browser session. 65 SESSIONS, 66 // An app folder or an app object. 67 APPS, 68 69 MODEL_TYPE_COUNT, 70}; 71 72typedef std::bitset<MODEL_TYPE_COUNT> ModelTypeBitSet; 73typedef std::set<ModelType> ModelTypeSet; 74 75inline ModelType ModelTypeFromInt(int i) { 76 DCHECK_GE(i, 0); 77 DCHECK_LT(i, MODEL_TYPE_COUNT); 78 return static_cast<ModelType>(i); 79} 80 81void AddDefaultExtensionValue(syncable::ModelType datatype, 82 sync_pb::EntitySpecifics* specifics); 83 84// Extract the model type of a SyncEntity protocol buffer. ModelType is a 85// local concept: the enum is not in the protocol. The SyncEntity's ModelType 86// is inferred from the presence of particular datatype extensions in the 87// entity specifics. 88ModelType GetModelType(const sync_pb::SyncEntity& sync_entity); 89 90// Extract the model type from an EntitySpecifics extension. Note that there 91// are some ModelTypes (like TOP_LEVEL_FOLDER) that can't be inferred this way; 92// prefer using GetModelType where possible. 93ModelType GetModelTypeFromSpecifics(const sync_pb::EntitySpecifics& specifics); 94 95// Returns a string that represents the name of |model_type|. 96std::string ModelTypeToString(ModelType model_type); 97 98// Returns the ModelType corresponding to the name |model_type_string|. 99ModelType ModelTypeFromString(const std::string& model_type_string); 100 101// Converts a string into a model type bitset. If successful, returns true. If 102// failed to parse string, returns false and model_types is unspecified. 103bool ModelTypeBitSetFromString( 104 const std::string& model_type_bitset_string, 105 ModelTypeBitSet* model_types); 106 107// Posts timedeltas to histogram of datatypes. Allows tracking of the frequency 108// at which datatypes cause syncs. 109void PostTimeToTypeHistogram(ModelType model_type, base::TimeDelta time); 110 111// Convert a real model type to a notification type (used for 112// subscribing to server-issued notifications). Returns true iff 113// |model_type| was a real model type and |notification_type| was 114// filled in. 115bool RealModelTypeToNotificationType(ModelType model_type, 116 std::string* notification_type); 117 118// Converts a notification type to a real model type. Returns true 119// iff |notification_type| was the notification type of a real model 120// type and |model_type| was filled in. 121bool NotificationTypeToRealModelType(const std::string& notification_type, 122 ModelType* model_type); 123 124} // namespace syncable 125 126#endif // CHROME_BROWSER_SYNC_SYNCABLE_MODEL_TYPE_H_ 127