Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/sync/syncable/syncable.cc

Issue 7033043: [Sync] Speed up sync node browser/search in about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #if defined(OS_POSIX) 10 #if defined(OS_POSIX)
(...skipping 18 matching lines...) Expand all
29 29
30 #include "base/hash_tables.h" 30 #include "base/hash_tables.h"
31 #include "base/file_util.h" 31 #include "base/file_util.h"
32 #include "base/logging.h" 32 #include "base/logging.h"
33 #include "base/memory/scoped_ptr.h" 33 #include "base/memory/scoped_ptr.h"
34 #include "base/perftimer.h" 34 #include "base/perftimer.h"
35 #include "base/string_number_conversions.h" 35 #include "base/string_number_conversions.h"
36 #include "base/string_util.h" 36 #include "base/string_util.h"
37 #include "base/stl_util-inl.h" 37 #include "base/stl_util-inl.h"
38 #include "base/time.h" 38 #include "base/time.h"
39 #include "base/utf_string_conversions.h"
39 #include "base/values.h" 40 #include "base/values.h"
40 #include "chrome/browser/sync/engine/syncer.h" 41 #include "chrome/browser/sync/engine/syncer.h"
41 #include "chrome/browser/sync/engine/syncer_util.h" 42 #include "chrome/browser/sync/engine/syncer_util.h"
42 #include "chrome/browser/sync/protocol/proto_value_conversions.h" 43 #include "chrome/browser/sync/protocol/proto_value_conversions.h"
43 #include "chrome/browser/sync/protocol/service_constants.h" 44 #include "chrome/browser/sync/protocol/service_constants.h"
44 #include "chrome/browser/sync/syncable/directory_backing_store.h" 45 #include "chrome/browser/sync/syncable/directory_backing_store.h"
45 #include "chrome/browser/sync/syncable/directory_change_listener.h" 46 #include "chrome/browser/sync/syncable/directory_change_listener.h"
46 #include "chrome/browser/sync/syncable/directory_manager.h" 47 #include "chrome/browser/sync/syncable/directory_manager.h"
47 #include "chrome/browser/sync/syncable/model_type.h" 48 #include "chrome/browser/sync/syncable/model_type.h"
48 #include "chrome/browser/sync/syncable/syncable-inl.h" 49 #include "chrome/browser/sync/syncable/syncable-inl.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 201
201 /////////////////////////////////////////////////////////////////////////// 202 ///////////////////////////////////////////////////////////////////////////
202 // EntryKernel 203 // EntryKernel
203 204
204 EntryKernel::EntryKernel() : dirty_(false) { 205 EntryKernel::EntryKernel() : dirty_(false) {
205 memset(int64_fields, 0, sizeof(int64_fields)); 206 memset(int64_fields, 0, sizeof(int64_fields));
206 } 207 }
207 208
208 EntryKernel::~EntryKernel() {} 209 EntryKernel::~EntryKernel() {}
209 210
211 bool EntryKernel::ContainsString(const std::string& lowercase_query) const {
212 // TODO(lipalani) - figure out what to do if the node is encrypted.
213 const sync_pb::EntitySpecifics& specifics = ref(SPECIFICS);
214 std::string temp;
215 // The protobuf serialized string contains the original strings. So
216 // we will just serialize it and search it.
217 specifics.SerializeToString(&temp);
218
219 // Now convert to lower case.
220 StringToLowerASCII(&temp);
221
222 if (temp.find(lowercase_query) != std::string::npos)
223 return true;
224
225 // Now go through all the string fields to see if the value is there.
226 for (int i = STRING_FIELDS_BEGIN; i < STRING_FIELDS_END; ++i) {
227 std::string value = ref(static_cast<StringField>(i));
228
229 StringToLowerASCII(&value);
230 if (value.find(lowercase_query) != std::string::npos)
231 return true;
232 }
233 return false;
234 }
235
210 namespace { 236 namespace {
211 237
212 // Utility function to loop through a set of enum values and add the 238 // Utility function to loop through a set of enum values and add the
213 // field keys/values in the kernel to the given dictionary. 239 // field keys/values in the kernel to the given dictionary.
214 // 240 //
215 // V should be convertible to Value. 241 // V should be convertible to Value.
216 template <class T, class U, class V> 242 template <class T, class U, class V>
217 void SetFieldValues(const EntryKernel& kernel, 243 void SetFieldValues(const EntryKernel& kernel,
218 DictionaryValue* dictionary_value, 244 DictionaryValue* dictionary_value,
219 const char* (*enum_key_fn)(T), 245 const char* (*enum_key_fn)(T),
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 kernel_->needle.put(META_HANDLE, metahandle); 525 kernel_->needle.put(META_HANDLE, metahandle);
500 MetahandlesIndex::iterator found = 526 MetahandlesIndex::iterator found =
501 kernel_->metahandles_index->find(&kernel_->needle); 527 kernel_->metahandles_index->find(&kernel_->needle);
502 if (found != kernel_->metahandles_index->end()) { 528 if (found != kernel_->metahandles_index->end()) {
503 // Found it in memory. Easy. 529 // Found it in memory. Easy.
504 return *found; 530 return *found;
505 } 531 }
506 return NULL; 532 return NULL;
507 } 533 }
508 534
509 void Directory::GetChildHandles(BaseTransaction* trans, const Id& parent_id, 535 void Directory::GetChildHandlesById(
510 Directory::ChildHandles* result) { 536 BaseTransaction* trans, const Id& parent_id,
537 Directory::ChildHandles* result) {
511 CHECK(this == trans->directory()); 538 CHECK(this == trans->directory());
512 result->clear(); 539 result->clear();
513 {
514 ScopedKernelLock lock(this);
515 540
516 typedef ParentIdChildIndex::iterator iterator; 541 ScopedKernelLock lock(this);
517 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id), 542 AppendChildHandles(lock, parent_id, result);
518 end = GetParentChildIndexUpperBound(lock, parent_id); 543 }
519 i != end; ++i) { 544
520 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); 545 void Directory::GetChildHandlesByHandle(
521 result->push_back((*i)->ref(META_HANDLE)); 546 BaseTransaction* trans, int64 handle,
522 } 547 Directory::ChildHandles* result) {
523 } 548 CHECK(this == trans->directory());
549 result->clear();
550
551 ScopedKernelLock lock(this);
552 EntryKernel* kernel = GetEntryByHandle(handle, &lock);
553 if (!kernel)
554 return;
555
556 AppendChildHandles(lock, kernel->ref(ID), result);
524 } 557 }
525 558
526 EntryKernel* Directory::GetRootEntry() { 559 EntryKernel* Directory::GetRootEntry() {
527 return GetEntryById(Id()); 560 return GetEntryById(Id());
528 } 561 }
529 562
530 void ZeroFields(EntryKernel* entry, int first_field) { 563 void ZeroFields(EntryKernel* entry, int first_field) {
531 int i = first_field; 564 int i = first_field;
532 // Note that bitset<> constructor sets all bits to zero, and strings 565 // Note that bitset<> constructor sets all bits to zero, and strings
533 // initialize to empty. 566 // initialize to empty.
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 result->clear(); 971 result->clear();
939 ScopedKernelLock lock(this); 972 ScopedKernelLock lock(this);
940 MetahandlesIndex::iterator i; 973 MetahandlesIndex::iterator i;
941 for (i = kernel_->metahandles_index->begin(); 974 for (i = kernel_->metahandles_index->begin();
942 i != kernel_->metahandles_index->end(); 975 i != kernel_->metahandles_index->end();
943 ++i) { 976 ++i) {
944 result->insert((*i)->ref(META_HANDLE)); 977 result->insert((*i)->ref(META_HANDLE));
945 } 978 }
946 } 979 }
947 980
981 void Directory::GetAllEntryKernels(BaseTransaction* trans,
982 std::vector<const EntryKernel*>* result) {
983 result->clear();
984 ScopedKernelLock lock(this);
985 result->insert(result->end(),
986 kernel_->metahandles_index->begin(),
987 kernel_->metahandles_index->end());
988 }
989
948 void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, 990 void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans,
949 UnsyncedMetaHandles* result) { 991 UnsyncedMetaHandles* result) {
950 result->clear(); 992 result->clear();
951 ScopedKernelLock lock(this); 993 ScopedKernelLock lock(this);
952 copy(kernel_->unsynced_metahandles->begin(), 994 copy(kernel_->unsynced_metahandles->begin(),
953 kernel_->unsynced_metahandles->end(), back_inserter(*result)); 995 kernel_->unsynced_metahandles->end(), back_inserter(*result));
954 } 996 }
955 997
956 int64 Directory::unsynced_entity_count() const { 998 int64 Directory::unsynced_entity_count() const {
957 ScopedKernelLock lock(this); 999 ScopedKernelLock lock(this);
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 1987
1946 Directory::ParentIdChildIndex::iterator 1988 Directory::ParentIdChildIndex::iterator
1947 Directory::GetParentChildIndexUpperBound(const ScopedKernelLock& lock, 1989 Directory::GetParentChildIndexUpperBound(const ScopedKernelLock& lock,
1948 const Id& parent_id) { 1990 const Id& parent_id) {
1949 // The upper bound of |parent_id|'s range is the lower 1991 // The upper bound of |parent_id|'s range is the lower
1950 // bound of |++parent_id|'s range. 1992 // bound of |++parent_id|'s range.
1951 return GetParentChildIndexLowerBound(lock, 1993 return GetParentChildIndexLowerBound(lock,
1952 parent_id.GetLexicographicSuccessor()); 1994 parent_id.GetLexicographicSuccessor());
1953 } 1995 }
1954 1996
1997 void Directory::AppendChildHandles(const ScopedKernelLock& lock,
1998 const Id& parent_id,
1999 Directory::ChildHandles* result) {
2000 typedef ParentIdChildIndex::iterator iterator;
2001 CHECK(result);
2002 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id),
2003 end = GetParentChildIndexUpperBound(lock, parent_id);
2004 i != end; ++i) {
2005 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID));
2006 result->push_back((*i)->ref(META_HANDLE));
2007 }
2008 }
2009
1955 } // namespace syncable 2010 } // namespace syncable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698