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 } // namespace | 166 } // namespace |
157 | 167 |
158 bool RealModelTypeToNotificationType(ModelType model_type, | 168 bool RealModelTypeToNotificationType(ModelType model_type, |
159 std::string* notification_type) { | 169 std::string* notification_type) { |
160 switch (model_type) { | 170 switch (model_type) { |
161 case BOOKMARKS: | 171 case BOOKMARKS: |
162 *notification_type = kBookmarkNotificationType; | 172 *notification_type = kBookmarkNotificationType; |
163 return true; | 173 return true; |
164 case PREFERENCES: | 174 case PREFERENCES: |
165 *notification_type = kPreferenceNotificationType; | 175 *notification_type = kPreferenceNotificationType; |
(...skipping 12 matching lines...) Expand all Loading... |
178 return true; | 188 return true; |
179 case EXTENSIONS: | 189 case EXTENSIONS: |
180 *notification_type = kExtensionNotificationType; | 190 *notification_type = kExtensionNotificationType; |
181 return true; | 191 return true; |
182 case NIGORI: | 192 case NIGORI: |
183 *notification_type = kNigoriNotificationType; | 193 *notification_type = kNigoriNotificationType; |
184 return true; | 194 return true; |
185 case APPS: | 195 case APPS: |
186 *notification_type = kAppNotificationType; | 196 *notification_type = kAppNotificationType; |
187 return true; | 197 return true; |
| 198 case SESSIONS: |
| 199 *notification_type = kSessionNotificationType; |
| 200 return true; |
188 default: | 201 default: |
189 break; | 202 break; |
190 } | 203 } |
191 notification_type->clear(); | 204 notification_type->clear(); |
192 return false; | 205 return false; |
193 } | 206 } |
194 | 207 |
195 bool NotificationTypeToRealModelType(const std::string& notification_type, | 208 bool NotificationTypeToRealModelType(const std::string& notification_type, |
196 ModelType* model_type) { | 209 ModelType* model_type) { |
197 if (notification_type == kBookmarkNotificationType) { | 210 if (notification_type == kBookmarkNotificationType) { |
(...skipping 16 matching lines...) Expand all Loading... |
214 return true; | 227 return true; |
215 } else if (notification_type == kExtensionNotificationType) { | 228 } else if (notification_type == kExtensionNotificationType) { |
216 *model_type = EXTENSIONS; | 229 *model_type = EXTENSIONS; |
217 return true; | 230 return true; |
218 } else if (notification_type == kNigoriNotificationType) { | 231 } else if (notification_type == kNigoriNotificationType) { |
219 *model_type = NIGORI; | 232 *model_type = NIGORI; |
220 return true; | 233 return true; |
221 } else if (notification_type == kAppNotificationType) { | 234 } else if (notification_type == kAppNotificationType) { |
222 *model_type = APPS; | 235 *model_type = APPS; |
223 return true; | 236 return true; |
| 237 } else if (notification_type == kSessionNotificationType) { |
| 238 *model_type = SESSIONS; |
| 239 return true; |
224 } | 240 } |
225 *model_type = UNSPECIFIED; | 241 *model_type = UNSPECIFIED; |
226 return false; | 242 return false; |
227 } | 243 } |
228 | 244 |
229 } // namespace syncable | 245 } // namespace syncable |
OLD | NEW |