OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "sync/syncable/syncable.h" | 5 #include "sync/syncable/syncable.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <functional> | 9 #include <functional> |
10 #include <iomanip> | 10 #include <iomanip> |
11 #include <iterator> | 11 #include <iterator> |
12 #include <limits> | 12 #include <limits> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/debug/trace_event.h" | 17 #include "base/debug/trace_event.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/debug/trace_event.h" | 19 #include "base/debug/trace_event.h" |
20 #include "base/file_util.h" | 20 #include "base/file_util.h" |
21 #include "base/hash_tables.h" | 21 #include "base/hash_tables.h" |
22 #include "base/json/json_writer.h" | |
akalin
2012/04/03 00:36:08
didn't you mean to remove this?
rlarocque
2012/04/03 19:01:42
Yes. Done.
| |
22 #include "base/location.h" | 23 #include "base/location.h" |
23 #include "base/logging.h" | 24 #include "base/logging.h" |
24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
25 #include "base/perftimer.h" | 26 #include "base/perftimer.h" |
26 #include "base/stl_util.h" | 27 #include "base/stl_util.h" |
27 #include "base/string_number_conversions.h" | 28 #include "base/string_number_conversions.h" |
28 #include "base/string_util.h" | 29 #include "base/string_util.h" |
29 #include "base/time.h" | 30 #include "base/time.h" |
30 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
31 #include "base/values.h" | 32 #include "base/values.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 if (ref(ID).IsRoot()) | 296 if (ref(ID).IsRoot()) |
296 return TOP_LEVEL_FOLDER; | 297 return TOP_LEVEL_FOLDER; |
297 // Loose check for server-created top-level folders that aren't | 298 // Loose check for server-created top-level folders that aren't |
298 // bound to a particular model type. | 299 // bound to a particular model type. |
299 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) | 300 if (!ref(UNIQUE_SERVER_TAG).empty() && ref(SERVER_IS_DIR)) |
300 return TOP_LEVEL_FOLDER; | 301 return TOP_LEVEL_FOLDER; |
301 | 302 |
302 return UNSPECIFIED; | 303 return UNSPECIFIED; |
303 } | 304 } |
304 | 305 |
305 bool EntryKernel::ContainsString(const std::string& lowercase_query) const { | |
306 // TODO(lipalani) - figure out what to do if the node is encrypted. | |
307 const sync_pb::EntitySpecifics& specifics = ref(SPECIFICS); | |
308 std::string temp; | |
309 // The protobuf serialized string contains the original strings. So | |
310 // we will just serialize it and search it. | |
311 specifics.SerializeToString(&temp); | |
312 | |
313 // Now convert to lower case. | |
314 StringToLowerASCII(&temp); | |
315 | |
316 if (temp.find(lowercase_query) != std::string::npos) | |
317 return true; | |
318 | |
319 // Now go through all the string fields to see if the value is there. | |
320 for (int i = STRING_FIELDS_BEGIN; i < STRING_FIELDS_END; ++i) { | |
321 if (StringToLowerASCII(ref(static_cast<StringField>(i))).find( | |
322 lowercase_query) != std::string::npos) | |
323 return true; | |
324 } | |
325 | |
326 for (int i = ID_FIELDS_BEGIN; i < ID_FIELDS_END; ++i) { | |
327 const Id& id = ref(static_cast<IdField>(i)); | |
328 if (id.ContainsStringCaseInsensitive(lowercase_query)) { | |
329 return true; | |
330 } | |
331 } | |
332 return false; | |
333 } | |
334 | |
335 namespace { | 306 namespace { |
336 | 307 |
337 // Utility function to loop through a set of enum values and add the | 308 // Utility function to loop through a set of enum values and add the |
338 // field keys/values in the kernel to the given dictionary. | 309 // field keys/values in the kernel to the given dictionary. |
339 // | 310 // |
340 // V should be convertible to Value. | 311 // V should be convertible to Value. |
341 template <class T, class U, class V> | 312 template <class T, class U, class V> |
342 void SetFieldValues(const EntryKernel& kernel, | 313 void SetFieldValues(const EntryKernel& kernel, |
343 DictionaryValue* dictionary_value, | 314 DictionaryValue* dictionary_value, |
344 const char* (*enum_key_fn)(T), | 315 const char* (*enum_key_fn)(T), |
(...skipping 2051 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2396 if (entry->ref(NEXT_ID).IsRoot() || | 2367 if (entry->ref(NEXT_ID).IsRoot() || |
2397 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { | 2368 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { |
2398 return entry; | 2369 return entry; |
2399 } | 2370 } |
2400 } | 2371 } |
2401 // There were no children in the linked list. | 2372 // There were no children in the linked list. |
2402 return NULL; | 2373 return NULL; |
2403 } | 2374 } |
2404 | 2375 |
2405 } // namespace syncable | 2376 } // namespace syncable |
OLD | NEW |