OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/sync/syncable/model_type.h" | 5 #include "chrome/browser/sync/syncable/model_type.h" |
6 | 6 |
7 #include "chrome/browser/sync/engine/syncproto.h" | 7 #include "chrome/browser/sync/engine/syncproto.h" |
8 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 8 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
9 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 9 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
11 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 11 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
12 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
13 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 13 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
14 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 15 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
15 #include "chrome/browser/sync/protocol/sync.pb.h" | 16 #include "chrome/browser/sync/protocol/sync.pb.h" |
16 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
17 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
18 | 19 |
19 namespace syncable { | 20 namespace syncable { |
20 | 21 |
21 void AddDefaultExtensionValue(syncable::ModelType datatype, | 22 void AddDefaultExtensionValue(syncable::ModelType datatype, |
22 sync_pb::EntitySpecifics* specifics) { | 23 sync_pb::EntitySpecifics* specifics) { |
23 switch (datatype) { | 24 switch (datatype) { |
24 case BOOKMARKS: | 25 case BOOKMARKS: |
(...skipping 13 matching lines...) Expand all Loading... |
38 break; | 39 break; |
39 case TYPED_URLS: | 40 case TYPED_URLS: |
40 specifics->MutableExtension(sync_pb::typed_url); | 41 specifics->MutableExtension(sync_pb::typed_url); |
41 break; | 42 break; |
42 case EXTENSIONS: | 43 case EXTENSIONS: |
43 specifics->MutableExtension(sync_pb::extension); | 44 specifics->MutableExtension(sync_pb::extension); |
44 break; | 45 break; |
45 case NIGORI: | 46 case NIGORI: |
46 specifics->MutableExtension(sync_pb::nigori); | 47 specifics->MutableExtension(sync_pb::nigori); |
47 break; | 48 break; |
| 49 case SESSIONS: |
| 50 specifics->MutableExtension(sync_pb::session); |
| 51 break; |
48 case APPS: | 52 case APPS: |
49 specifics->MutableExtension(sync_pb::app); | 53 specifics->MutableExtension(sync_pb::app); |
50 break; | 54 break; |
51 default: | 55 default: |
52 NOTREACHED() << "No known extension for model type."; | 56 NOTREACHED() << "No known extension for model type."; |
53 } | 57 } |
54 } | 58 } |
55 | 59 |
56 // Note: keep this consistent with GetModelType in syncable.cc! | 60 // Note: keep this consistent with GetModelType in syncable.cc! |
57 ModelType GetModelType(const sync_pb::SyncEntity& sync_pb_entity) { | 61 ModelType GetModelType(const sync_pb::SyncEntity& sync_pb_entity) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 109 |
106 if (specifics.HasExtension(sync_pb::extension)) | 110 if (specifics.HasExtension(sync_pb::extension)) |
107 return EXTENSIONS; | 111 return EXTENSIONS; |
108 | 112 |
109 if (specifics.HasExtension(sync_pb::nigori)) | 113 if (specifics.HasExtension(sync_pb::nigori)) |
110 return NIGORI; | 114 return NIGORI; |
111 | 115 |
112 if (specifics.HasExtension(sync_pb::app)) | 116 if (specifics.HasExtension(sync_pb::app)) |
113 return APPS; | 117 return APPS; |
114 | 118 |
| 119 if (specifics.HasExtension(sync_pb::session)) |
| 120 return SESSIONS; |
| 121 |
115 return UNSPECIFIED; | 122 return UNSPECIFIED; |
116 } | 123 } |
117 | 124 |
118 std::string ModelTypeToString(ModelType model_type) { | 125 std::string ModelTypeToString(ModelType model_type) { |
119 switch (model_type) { | 126 switch (model_type) { |
120 case BOOKMARKS: | 127 case BOOKMARKS: |
121 return "Bookmarks"; | 128 return "Bookmarks"; |
122 case PREFERENCES: | 129 case PREFERENCES: |
123 return "Preferences"; | 130 return "Preferences"; |
124 case PASSWORDS: | 131 case PASSWORDS: |
125 return "Passwords"; | 132 return "Passwords"; |
126 case AUTOFILL: | 133 case AUTOFILL: |
127 return "Autofill"; | 134 return "Autofill"; |
128 case THEMES: | 135 case THEMES: |
129 return "Themes"; | 136 return "Themes"; |
130 case TYPED_URLS: | 137 case TYPED_URLS: |
131 return "Typed URLs"; | 138 return "Typed URLs"; |
132 case EXTENSIONS: | 139 case EXTENSIONS: |
133 return "Extensions"; | 140 return "Extensions"; |
134 case NIGORI: | 141 case NIGORI: |
135 return "Encryption keys"; | 142 return "Encryption keys"; |
| 143 case SESSIONS: |
| 144 return "Sessions"; |
136 case APPS: | 145 case APPS: |
137 return "Apps"; | 146 return "Apps"; |
138 default: | 147 default: |
139 NOTREACHED() << "No known extension for model type."; | 148 NOTREACHED() << "No known extension for model type."; |
140 return "INVALID"; | 149 return "INVALID"; |
141 } | 150 } |
142 } | 151 } |
143 | 152 |
144 // TODO(akalin): Figure out a better way to do these mappings. | 153 // TODO(akalin): Figure out a better way to do these mappings. |
145 | 154 |
146 namespace { | 155 namespace { |
147 const char kBookmarkNotificationType[] = "BOOKMARK"; | 156 const char kBookmarkNotificationType[] = "BOOKMARK"; |
148 const char kPreferenceNotificationType[] = "PREFERENCE"; | 157 const char kPreferenceNotificationType[] = "PREFERENCE"; |
149 const char kPasswordNotificationType[] = "PASSWORD"; | 158 const char kPasswordNotificationType[] = "PASSWORD"; |
150 const char kAutofillNotificationType[] = "AUTOFILL"; | 159 const char kAutofillNotificationType[] = "AUTOFILL"; |
151 const char kThemeNotificationType[] = "THEME"; | 160 const char kThemeNotificationType[] = "THEME"; |
152 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 161 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
153 const char kExtensionNotificationType[] = "EXTENSION"; | 162 const char kExtensionNotificationType[] = "EXTENSION"; |
154 const char kNigoriNotificationType[] = "NIGORI"; | 163 const char kNigoriNotificationType[] = "NIGORI"; |
155 const char kAppNotificationType[] = "APP"; | 164 const char kAppNotificationType[] = "APP"; |
| 165 const char kSessionNotificationType[] = "SESSION"; |
156 // TODO(akalin): This is a hack to make new sync data types work with | 166 // TODO(akalin): This is a hack to make new sync data types work with |
157 // server-issued notifications. Remove this when it's not needed | 167 // server-issued notifications. Remove this when it's not needed |
158 // anymore. | 168 // anymore. |
159 const char kUnknownNotificationType[] = "UNKNOWN"; | 169 const char kUnknownNotificationType[] = "UNKNOWN"; |
160 } // namespace | 170 } // namespace |
161 | 171 |
162 bool RealModelTypeToNotificationType(ModelType model_type, | 172 bool RealModelTypeToNotificationType(ModelType model_type, |
163 std::string* notification_type) { | 173 std::string* notification_type) { |
164 switch (model_type) { | 174 switch (model_type) { |
165 case BOOKMARKS: | 175 case BOOKMARKS: |
(...skipping 16 matching lines...) Expand all Loading... |
182 return true; | 192 return true; |
183 case EXTENSIONS: | 193 case EXTENSIONS: |
184 *notification_type = kExtensionNotificationType; | 194 *notification_type = kExtensionNotificationType; |
185 return true; | 195 return true; |
186 case NIGORI: | 196 case NIGORI: |
187 *notification_type = kNigoriNotificationType; | 197 *notification_type = kNigoriNotificationType; |
188 return true; | 198 return true; |
189 case APPS: | 199 case APPS: |
190 *notification_type = kAppNotificationType; | 200 *notification_type = kAppNotificationType; |
191 return true; | 201 return true; |
| 202 case SESSIONS: |
| 203 *notification_type = kSessionNotificationType; |
| 204 return true; |
192 // TODO(akalin): This is a hack to make new sync data types work with | 205 // TODO(akalin): This is a hack to make new sync data types work with |
193 // server-issued notifications. Remove this when it's not needed | 206 // server-issued notifications. Remove this when it's not needed |
194 // anymore. | 207 // anymore. |
195 case UNSPECIFIED: | 208 case UNSPECIFIED: |
196 *notification_type = kUnknownNotificationType; | 209 *notification_type = kUnknownNotificationType; |
197 return true; | 210 return true; |
198 default: | 211 default: |
199 break; | 212 break; |
200 } | 213 } |
201 notification_type->clear(); | 214 notification_type->clear(); |
(...skipping 22 matching lines...) Expand all Loading... |
224 return true; | 237 return true; |
225 } else if (notification_type == kExtensionNotificationType) { | 238 } else if (notification_type == kExtensionNotificationType) { |
226 *model_type = EXTENSIONS; | 239 *model_type = EXTENSIONS; |
227 return true; | 240 return true; |
228 } else if (notification_type == kNigoriNotificationType) { | 241 } else if (notification_type == kNigoriNotificationType) { |
229 *model_type = NIGORI; | 242 *model_type = NIGORI; |
230 return true; | 243 return true; |
231 } else if (notification_type == kAppNotificationType) { | 244 } else if (notification_type == kAppNotificationType) { |
232 *model_type = APPS; | 245 *model_type = APPS; |
233 return true; | 246 return true; |
234 } else if (notification_type == kUnknownNotificationType) { | 247 } else if (notification_type == kSessionNotificationType) { |
| 248 *model_type = SESSIONS; |
| 249 return true; |
| 250 } |
| 251 else if (notification_type == kUnknownNotificationType) { |
235 // TODO(akalin): This is a hack to make new sync data types work with | 252 // TODO(akalin): This is a hack to make new sync data types work with |
236 // server-issued notifications. Remove this when it's not needed | 253 // server-issued notifications. Remove this when it's not needed |
237 // anymore. | 254 // anymore. |
238 *model_type = UNSPECIFIED; | 255 *model_type = UNSPECIFIED; |
239 return true; | 256 return true; |
240 } | 257 } |
241 *model_type = UNSPECIFIED; | 258 *model_type = UNSPECIFIED; |
242 return false; | 259 return false; |
243 } | 260 } |
244 | 261 |
245 } // namespace syncable | 262 } // namespace syncable |
OLD | NEW |