| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <bitset> | 9 #include <bitset> |
| 10 #include <iosfwd> | 10 #include <iosfwd> |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 enum Create { | 212 enum Create { |
| 213 CREATE | 213 CREATE |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 enum CreateNewUpdateItem { | 216 enum CreateNewUpdateItem { |
| 217 CREATE_NEW_UPDATE_ITEM | 217 CREATE_NEW_UPDATE_ITEM |
| 218 }; | 218 }; |
| 219 | 219 |
| 220 typedef std::set<PathString> AttributeKeySet; | 220 typedef std::set<std::string> AttributeKeySet; |
| 221 | 221 |
| 222 // Why the singular enums? So the code compile-time dispatches instead of | 222 // Why the singular enums? So the code compile-time dispatches instead of |
| 223 // runtime dispatches as it would with a single enum and an if() statement. | 223 // runtime dispatches as it would with a single enum and an if() statement. |
| 224 | 224 |
| 225 // The EntryKernel class contains the actual data for an entry. It | 225 // The EntryKernel class contains the actual data for an entry. It |
| 226 // would be a private class, except the number of required friend | 226 // would be a private class, except the number of required friend |
| 227 // declarations would bloat the code. | 227 // declarations would bloat the code. |
| 228 struct EntryKernel { | 228 struct EntryKernel { |
| 229 protected: | 229 protected: |
| 230 PathString string_fields[STRING_FIELDS_COUNT]; | 230 std::string string_fields[STRING_FIELDS_COUNT]; |
| 231 Blob blob_fields[BLOB_FIELDS_COUNT]; | 231 Blob blob_fields[BLOB_FIELDS_COUNT]; |
| 232 int64 int64_fields[INT64_FIELDS_COUNT]; | 232 int64 int64_fields[INT64_FIELDS_COUNT]; |
| 233 Id id_fields[ID_FIELDS_COUNT]; | 233 Id id_fields[ID_FIELDS_COUNT]; |
| 234 std::bitset<BIT_FIELDS_COUNT> bit_fields; | 234 std::bitset<BIT_FIELDS_COUNT> bit_fields; |
| 235 std::bitset<BIT_TEMPS_COUNT> bit_temps; | 235 std::bitset<BIT_TEMPS_COUNT> bit_temps; |
| 236 | 236 |
| 237 public: | 237 public: |
| 238 std::bitset<FIELD_COUNT> dirty; | 238 std::bitset<FIELD_COUNT> dirty; |
| 239 | 239 |
| 240 // Contain all this error-prone arithmetic in one place. | 240 // Contain all this error-prone arithmetic in one place. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 252 } | 252 } |
| 253 inline std::bitset<BIT_FIELDS_COUNT>::reference ref(IndexedBitField field) { | 253 inline std::bitset<BIT_FIELDS_COUNT>::reference ref(IndexedBitField field) { |
| 254 return bit_fields[field - BIT_FIELDS_BEGIN]; | 254 return bit_fields[field - BIT_FIELDS_BEGIN]; |
| 255 } | 255 } |
| 256 inline std::bitset<BIT_FIELDS_COUNT>::reference ref(IsDelField field) { | 256 inline std::bitset<BIT_FIELDS_COUNT>::reference ref(IsDelField field) { |
| 257 return bit_fields[field - BIT_FIELDS_BEGIN]; | 257 return bit_fields[field - BIT_FIELDS_BEGIN]; |
| 258 } | 258 } |
| 259 inline std::bitset<BIT_FIELDS_COUNT>::reference ref(BitField field) { | 259 inline std::bitset<BIT_FIELDS_COUNT>::reference ref(BitField field) { |
| 260 return bit_fields[field - BIT_FIELDS_BEGIN]; | 260 return bit_fields[field - BIT_FIELDS_BEGIN]; |
| 261 } | 261 } |
| 262 inline PathString& ref(StringField field) { | 262 inline std::string& ref(StringField field) { |
| 263 return string_fields[field - STRING_FIELDS_BEGIN]; | 263 return string_fields[field - STRING_FIELDS_BEGIN]; |
| 264 } | 264 } |
| 265 inline Blob& ref(BlobField field) { | 265 inline Blob& ref(BlobField field) { |
| 266 return blob_fields[field - BLOB_FIELDS_BEGIN]; | 266 return blob_fields[field - BLOB_FIELDS_BEGIN]; |
| 267 } | 267 } |
| 268 inline std::bitset<BIT_TEMPS_COUNT>::reference ref(BitTemp field) { | 268 inline std::bitset<BIT_TEMPS_COUNT>::reference ref(BitTemp field) { |
| 269 return bit_temps[field - BIT_TEMPS_BEGIN]; | 269 return bit_temps[field - BIT_TEMPS_BEGIN]; |
| 270 } | 270 } |
| 271 | 271 |
| 272 inline int64 ref(MetahandleField field) const { | 272 inline int64 ref(MetahandleField field) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 283 } | 283 } |
| 284 inline bool ref(IndexedBitField field) const { | 284 inline bool ref(IndexedBitField field) const { |
| 285 return bit_fields[field - BIT_FIELDS_BEGIN]; | 285 return bit_fields[field - BIT_FIELDS_BEGIN]; |
| 286 } | 286 } |
| 287 inline bool ref(IsDelField field) const { | 287 inline bool ref(IsDelField field) const { |
| 288 return bit_fields[field - BIT_FIELDS_BEGIN]; | 288 return bit_fields[field - BIT_FIELDS_BEGIN]; |
| 289 } | 289 } |
| 290 inline bool ref(BitField field) const { | 290 inline bool ref(BitField field) const { |
| 291 return bit_fields[field - BIT_FIELDS_BEGIN]; | 291 return bit_fields[field - BIT_FIELDS_BEGIN]; |
| 292 } | 292 } |
| 293 inline PathString ref(StringField field) const { | 293 inline const std::string& ref(StringField field) const { |
| 294 return string_fields[field - STRING_FIELDS_BEGIN]; | 294 return string_fields[field - STRING_FIELDS_BEGIN]; |
| 295 } | 295 } |
| 296 inline Blob ref(BlobField field) const { | 296 inline Blob ref(BlobField field) const { |
| 297 return blob_fields[field - BLOB_FIELDS_BEGIN]; | 297 return blob_fields[field - BLOB_FIELDS_BEGIN]; |
| 298 } | 298 } |
| 299 inline bool ref(BitTemp field) const { | 299 inline bool ref(BitTemp field) const { |
| 300 return bit_temps[field - BIT_TEMPS_BEGIN]; | 300 return bit_temps[field - BIT_TEMPS_BEGIN]; |
| 301 } | 301 } |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 // A read-only meta entry. | 304 // A read-only meta entry. |
| 305 class Entry { | 305 class Entry { |
| 306 friend class Directory; | 306 friend class Directory; |
| 307 friend std::ostream& ::operator << (std::ostream& s, const Entry& e); | 307 friend std::ostream& ::operator << (std::ostream& s, const Entry& e); |
| 308 | 308 |
| 309 public: | 309 public: |
| 310 // After constructing, you must check good() to test whether the Get | 310 // After constructing, you must check good() to test whether the Get |
| 311 // succeeded. | 311 // succeeded. |
| 312 Entry(BaseTransaction* trans, GetByHandle, int64 handle); | 312 Entry(BaseTransaction* trans, GetByHandle, int64 handle); |
| 313 Entry(BaseTransaction* trans, GetById, const Id& id); | 313 Entry(BaseTransaction* trans, GetById, const Id& id); |
| 314 Entry(BaseTransaction* trans, GetByTag, const PathString& tag); | 314 Entry(BaseTransaction* trans, GetByTag, const std::string& tag); |
| 315 | 315 |
| 316 bool good() const { return 0 != kernel_; } | 316 bool good() const { return 0 != kernel_; } |
| 317 | 317 |
| 318 BaseTransaction* trans() const { return basetrans_; } | 318 BaseTransaction* trans() const { return basetrans_; } |
| 319 | 319 |
| 320 // Field accessors. | 320 // Field accessors. |
| 321 inline int64 Get(MetahandleField field) const { | 321 inline int64 Get(MetahandleField field) const { |
| 322 DCHECK(kernel_); | 322 DCHECK(kernel_); |
| 323 return kernel_->ref(field); | 323 return kernel_->ref(field); |
| 324 } | 324 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 339 return kernel_->ref(field); | 339 return kernel_->ref(field); |
| 340 } | 340 } |
| 341 inline bool Get(IsDelField field) const { | 341 inline bool Get(IsDelField field) const { |
| 342 DCHECK(kernel_); | 342 DCHECK(kernel_); |
| 343 return kernel_->ref(field); | 343 return kernel_->ref(field); |
| 344 } | 344 } |
| 345 inline bool Get(BitField field) const { | 345 inline bool Get(BitField field) const { |
| 346 DCHECK(kernel_); | 346 DCHECK(kernel_); |
| 347 return kernel_->ref(field); | 347 return kernel_->ref(field); |
| 348 } | 348 } |
| 349 PathString Get(StringField field) const; | 349 const std::string& Get(StringField field) const; |
| 350 inline Blob Get(BlobField field) const { | 350 inline Blob Get(BlobField field) const { |
| 351 DCHECK(kernel_); | 351 DCHECK(kernel_); |
| 352 return kernel_->ref(field); | 352 return kernel_->ref(field); |
| 353 } | 353 } |
| 354 inline bool Get(BitTemp field) const { | 354 inline bool Get(BitTemp field) const { |
| 355 DCHECK(kernel_); | 355 DCHECK(kernel_); |
| 356 return kernel_->ref(field); | 356 return kernel_->ref(field); |
| 357 } | 357 } |
| 358 | 358 |
| 359 inline bool ExistsOnClientBecauseNameIsNonEmpty() const { | 359 inline bool ExistsOnClientBecauseNameIsNonEmpty() const { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 394 |
| 395 DISALLOW_COPY_AND_ASSIGN(Entry); | 395 DISALLOW_COPY_AND_ASSIGN(Entry); |
| 396 }; | 396 }; |
| 397 | 397 |
| 398 // A mutable meta entry. Changes get committed to the database when the | 398 // A mutable meta entry. Changes get committed to the database when the |
| 399 // WriteTransaction is destroyed. | 399 // WriteTransaction is destroyed. |
| 400 class MutableEntry : public Entry { | 400 class MutableEntry : public Entry { |
| 401 friend class WriteTransaction; | 401 friend class WriteTransaction; |
| 402 friend class Directory; | 402 friend class Directory; |
| 403 void Init(WriteTransaction* trans, const Id& parent_id, | 403 void Init(WriteTransaction* trans, const Id& parent_id, |
| 404 const PathString& name); | 404 const std::string& name); |
| 405 public: | 405 public: |
| 406 MutableEntry(WriteTransaction* trans, Create, const Id& parent_id, | 406 MutableEntry(WriteTransaction* trans, Create, const Id& parent_id, |
| 407 const PathString& name); | 407 const std::string& name); |
| 408 MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id); | 408 MutableEntry(WriteTransaction* trans, CreateNewUpdateItem, const Id& id); |
| 409 MutableEntry(WriteTransaction* trans, GetByHandle, int64); | 409 MutableEntry(WriteTransaction* trans, GetByHandle, int64); |
| 410 MutableEntry(WriteTransaction* trans, GetById, const Id&); | 410 MutableEntry(WriteTransaction* trans, GetById, const Id&); |
| 411 | 411 |
| 412 inline WriteTransaction* write_transaction() const { | 412 inline WriteTransaction* write_transaction() const { |
| 413 return write_transaction_; | 413 return write_transaction_; |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Field Accessors. Some of them trigger the re-indexing of the entry. | 416 // Field Accessors. Some of them trigger the re-indexing of the entry. |
| 417 // Return true on success, return false on failure, which means | 417 // Return true on success, return false on failure, which means |
| 418 // that putting the value would have caused a duplicate in the index. | 418 // that putting the value would have caused a duplicate in the index. |
| 419 // TODO(chron): Remove some of these unecessary return values. | 419 // TODO(chron): Remove some of these unecessary return values. |
| 420 bool Put(Int64Field field, const int64& value); | 420 bool Put(Int64Field field, const int64& value); |
| 421 bool Put(IdField field, const Id& value); | 421 bool Put(IdField field, const Id& value); |
| 422 bool Put(StringField field, const PathString& value); | 422 bool Put(StringField field, const std::string& value); |
| 423 bool Put(BaseVersion field, int64 value); | 423 bool Put(BaseVersion field, int64 value); |
| 424 | 424 |
| 425 inline bool Put(BlobField field, const Blob& value) { | 425 inline bool Put(BlobField field, const Blob& value) { |
| 426 return PutField(field, value); | 426 return PutField(field, value); |
| 427 } | 427 } |
| 428 inline bool Put(BitField field, bool value) { | 428 inline bool Put(BitField field, bool value) { |
| 429 return PutField(field, value); | 429 return PutField(field, value); |
| 430 } | 430 } |
| 431 inline bool Put(IsDelField field, bool value) { | 431 inline bool Put(IsDelField field, bool value) { |
| 432 return PutIsDel(value); | 432 return PutIsDel(value); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 461 kernel_->ref(field) = value; | 461 kernel_->ref(field) = value; |
| 462 return true; | 462 return true; |
| 463 } | 463 } |
| 464 | 464 |
| 465 bool PutIsDel(bool value); | 465 bool PutIsDel(bool value); |
| 466 | 466 |
| 467 private: // Don't allow creation on heap, except by sync API wrappers. | 467 private: // Don't allow creation on heap, except by sync API wrappers. |
| 468 friend class sync_api::WriteNode; | 468 friend class sync_api::WriteNode; |
| 469 void* operator new(size_t size) { return (::operator new)(size); } | 469 void* operator new(size_t size) { return (::operator new)(size); } |
| 470 | 470 |
| 471 bool PutImpl(StringField field, const PathString& value); | 471 bool PutImpl(StringField field, const std::string& value); |
| 472 | 472 |
| 473 // Adjusts the successor and predecessor entries so that they no longer | 473 // Adjusts the successor and predecessor entries so that they no longer |
| 474 // refer to this entry. | 474 // refer to this entry. |
| 475 void UnlinkFromOrder(); | 475 void UnlinkFromOrder(); |
| 476 | 476 |
| 477 // Kind of redundant. We should reduce the number of pointers | 477 // Kind of redundant. We should reduce the number of pointers |
| 478 // floating around if at all possible. Could we store this in Directory? | 478 // floating around if at all possible. Could we store this in Directory? |
| 479 // Scope: Set on construction, never changed after that. | 479 // Scope: Set on construction, never changed after that. |
| 480 WriteTransaction* const write_transaction_; | 480 WriteTransaction* const write_transaction_; |
| 481 | 481 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 BaseTransaction* trans; | 529 BaseTransaction* trans; |
| 530 WriterTag writer; | 530 WriterTag writer; |
| 531 typedef DirectoryChangeEvent EventType; | 531 typedef DirectoryChangeEvent EventType; |
| 532 static inline bool IsChannelShutdownEvent(const EventType& e) { | 532 static inline bool IsChannelShutdownEvent(const EventType& e) { |
| 533 return SHUTDOWN == e.todo; | 533 return SHUTDOWN == e.todo; |
| 534 } | 534 } |
| 535 }; | 535 }; |
| 536 | 536 |
| 537 struct ExtendedAttributeKey { | 537 struct ExtendedAttributeKey { |
| 538 int64 metahandle; | 538 int64 metahandle; |
| 539 PathString key; | 539 std::string key; |
| 540 inline bool operator < (const ExtendedAttributeKey& x) const { | 540 inline bool operator < (const ExtendedAttributeKey& x) const { |
| 541 if (metahandle != x.metahandle) | 541 if (metahandle != x.metahandle) |
| 542 return metahandle < x.metahandle; | 542 return metahandle < x.metahandle; |
| 543 return key.compare(x.key) < 0; | 543 return key.compare(x.key) < 0; |
| 544 } | 544 } |
| 545 ExtendedAttributeKey(int64 metahandle, PathString key) : | 545 ExtendedAttributeKey(int64 metahandle, const std::string& key) |
| 546 metahandle(metahandle), key(key) { } | 546 : metahandle(metahandle), key(key) { } |
| 547 }; | 547 }; |
| 548 | 548 |
| 549 struct ExtendedAttributeValue { | 549 struct ExtendedAttributeValue { |
| 550 Blob value; | 550 Blob value; |
| 551 bool is_deleted; | 551 bool is_deleted; |
| 552 bool dirty; | 552 bool dirty; |
| 553 }; | 553 }; |
| 554 | 554 |
| 555 typedef std::map<ExtendedAttributeKey, ExtendedAttributeValue> | 555 typedef std::map<ExtendedAttributeKey, ExtendedAttributeValue> |
| 556 ExtendedAttributes; | 556 ExtendedAttributes; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 PersistedKernelInfo kernel_info; | 639 PersistedKernelInfo kernel_info; |
| 640 OriginalEntries dirty_metas; | 640 OriginalEntries dirty_metas; |
| 641 ExtendedAttributes dirty_xattrs; | 641 ExtendedAttributes dirty_xattrs; |
| 642 SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { | 642 SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { |
| 643 } | 643 } |
| 644 }; | 644 }; |
| 645 | 645 |
| 646 Directory(); | 646 Directory(); |
| 647 virtual ~Directory(); | 647 virtual ~Directory(); |
| 648 | 648 |
| 649 DirOpenResult Open(const FilePath& file_path, const PathString& name); | 649 DirOpenResult Open(const FilePath& file_path, const std::string& name); |
| 650 | 650 |
| 651 void Close(); | 651 void Close(); |
| 652 | 652 |
| 653 int64 NextMetahandle(); | 653 int64 NextMetahandle(); |
| 654 // Always returns a negative id. Positive client ids are generated | 654 // Always returns a negative id. Positive client ids are generated |
| 655 // by the server only. | 655 // by the server only. |
| 656 Id NextId(); | 656 Id NextId(); |
| 657 | 657 |
| 658 const FilePath& file_path() const { return kernel_->db_path; } | 658 const FilePath& file_path() const { return kernel_->db_path; } |
| 659 bool good() const { return NULL != store_; } | 659 bool good() const { return NULL != store_; } |
| 660 | 660 |
| 661 // The sync timestamp is an index into the list of changes for an account. | 661 // The sync timestamp is an index into the list of changes for an account. |
| 662 // It doesn't actually map to any time scale, it's name is an historical | 662 // It doesn't actually map to any time scale, it's name is an historical |
| 663 // anomaly. | 663 // anomaly. |
| 664 int64 last_sync_timestamp() const; | 664 int64 last_sync_timestamp() const; |
| 665 void set_last_sync_timestamp(int64 timestamp); | 665 void set_last_sync_timestamp(int64 timestamp); |
| 666 | 666 |
| 667 bool initial_sync_ended() const; | 667 bool initial_sync_ended() const; |
| 668 void set_initial_sync_ended(bool value); | 668 void set_initial_sync_ended(bool value); |
| 669 | 669 |
| 670 PathString name() const { return kernel_->name_; } | 670 const std::string& name() const { return kernel_->name_; } |
| 671 | 671 |
| 672 // (Account) Store birthday is opaque to the client, | 672 // (Account) Store birthday is opaque to the client, |
| 673 // so we keep it in the format it is in the proto buffer | 673 // so we keep it in the format it is in the proto buffer |
| 674 // in case we switch to a binary birthday later. | 674 // in case we switch to a binary birthday later. |
| 675 std::string store_birthday() const; | 675 std::string store_birthday() const; |
| 676 void set_store_birthday(std::string store_birthday); | 676 void set_store_birthday(std::string store_birthday); |
| 677 | 677 |
| 678 // Unique to each account / client pair. | 678 // Unique to each account / client pair. |
| 679 std::string cache_guid() const; | 679 std::string cache_guid() const; |
| 680 | 680 |
| 681 protected: // for friends, mainly used by Entry constructors | 681 protected: // for friends, mainly used by Entry constructors |
| 682 EntryKernel* GetEntryByHandle(const int64 handle); | 682 EntryKernel* GetEntryByHandle(const int64 handle); |
| 683 EntryKernel* GetEntryByHandle(const int64 metahandle, ScopedKernelLock* lock); | 683 EntryKernel* GetEntryByHandle(const int64 metahandle, ScopedKernelLock* lock); |
| 684 EntryKernel* GetEntryById(const Id& id); | 684 EntryKernel* GetEntryById(const Id& id); |
| 685 EntryKernel* GetEntryByTag(const PathString& tag); | 685 EntryKernel* GetEntryByTag(const std::string& tag); |
| 686 EntryKernel* GetRootEntry(); | 686 EntryKernel* GetRootEntry(); |
| 687 bool ReindexId(EntryKernel* const entry, const Id& new_id); | 687 bool ReindexId(EntryKernel* const entry, const Id& new_id); |
| 688 void ReindexParentId(EntryKernel* const entry, const Id& new_parent_id); | 688 void ReindexParentId(EntryKernel* const entry, const Id& new_parent_id); |
| 689 | 689 |
| 690 // These don't do semantic checking. | 690 // These don't do semantic checking. |
| 691 // The semantic checking is implemented higher up. | 691 // The semantic checking is implemented higher up. |
| 692 void Undelete(EntryKernel* const entry); | 692 void Undelete(EntryKernel* const entry); |
| 693 void Delete(EntryKernel* const entry); | 693 void Delete(EntryKernel* const entry); |
| 694 | 694 |
| 695 // Overridden by tests. | 695 // Overridden by tests. |
| 696 virtual DirectoryBackingStore* CreateBackingStore( | 696 virtual DirectoryBackingStore* CreateBackingStore( |
| 697 const PathString& dir_name, | 697 const std::string& dir_name, |
| 698 const FilePath& backing_filepath); | 698 const FilePath& backing_filepath); |
| 699 | 699 |
| 700 private: | 700 private: |
| 701 // These private versions expect the kernel lock to already be held | 701 // These private versions expect the kernel lock to already be held |
| 702 // before calling. | 702 // before calling. |
| 703 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); | 703 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); |
| 704 | 704 |
| 705 DirOpenResult OpenImpl(const FilePath& file_path, const PathString& name); | 705 DirOpenResult OpenImpl(const FilePath& file_path, const std::string& name); |
| 706 | 706 |
| 707 struct DirectoryEventTraits { | 707 struct DirectoryEventTraits { |
| 708 typedef DirectoryEvent EventType; | 708 typedef DirectoryEvent EventType; |
| 709 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { | 709 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { |
| 710 return DIRECTORY_DESTROYED == event; | 710 return DIRECTORY_DESTROYED == event; |
| 711 } | 711 } |
| 712 }; | 712 }; |
| 713 public: | 713 public: |
| 714 typedef EventChannel<DirectoryEventTraits, Lock> Channel; | 714 typedef EventChannel<DirectoryEventTraits, Lock> Channel; |
| 715 typedef EventChannel<DirectoryChangeEvent, Lock> ChangesChannel; | 715 typedef EventChannel<DirectoryChangeEvent, Lock> ChangesChannel; |
| 716 typedef std::vector<int64> ChildHandles; | 716 typedef std::vector<int64> ChildHandles; |
| 717 | 717 |
| 718 // Returns the child meta handles for given parent id. | 718 // Returns the child meta handles for given parent id. |
| 719 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 719 void GetChildHandles(BaseTransaction*, const Id& parent_id, |
| 720 const PathString& path_spec, ChildHandles* result); | 720 const std::string& path_spec, ChildHandles* result); |
| 721 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 721 void GetChildHandles(BaseTransaction*, const Id& parent_id, |
| 722 ChildHandles* result); | 722 ChildHandles* result); |
| 723 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id, | 723 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id, |
| 724 PathMatcher* matcher, ChildHandles* result); | 724 PathMatcher* matcher, ChildHandles* result); |
| 725 | 725 |
| 726 // Find the first or last child in the positional ordering under a parent, | 726 // Find the first or last child in the positional ordering under a parent, |
| 727 // and return its id. Returns a root Id if parent has no children. | 727 // and return its id. Returns a root Id if parent has no children. |
| 728 Id GetFirstChildId(BaseTransaction* trans, const Id& parent_id); | 728 Id GetFirstChildId(BaseTransaction* trans, const Id& parent_id); |
| 729 Id GetLastChildId(BaseTransaction* trans, const Id& parent_id); | 729 Id GetLastChildId(BaseTransaction* trans, const Id& parent_id); |
| 730 | 730 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 // the IdsIndex, but only non-deleted entries will be the | 831 // the IdsIndex, but only non-deleted entries will be the |
| 832 // ParentIdChildIndex. | 832 // ParentIdChildIndex. |
| 833 // This index contains EntryKernels ordered by parent ID and metahandle. | 833 // This index contains EntryKernels ordered by parent ID and metahandle. |
| 834 // It allows efficient lookup of the children of a given parent. | 834 // It allows efficient lookup of the children of a given parent. |
| 835 typedef std::set<EntryKernel*, LessParentIdAndHandle> ParentIdChildIndex; | 835 typedef std::set<EntryKernel*, LessParentIdAndHandle> ParentIdChildIndex; |
| 836 typedef std::vector<int64> MetahandlesToPurge; | 836 typedef std::vector<int64> MetahandlesToPurge; |
| 837 | 837 |
| 838 private: | 838 private: |
| 839 | 839 |
| 840 struct Kernel { | 840 struct Kernel { |
| 841 Kernel(const FilePath& db_path, const PathString& name, | 841 Kernel(const FilePath& db_path, const std::string& name, |
| 842 const KernelLoadInfo& info); | 842 const KernelLoadInfo& info); |
| 843 | 843 |
| 844 ~Kernel(); | 844 ~Kernel(); |
| 845 | 845 |
| 846 FilePath const db_path; | 846 FilePath const db_path; |
| 847 // TODO(timsteele): audit use of the member and remove if possible | 847 // TODO(timsteele): audit use of the member and remove if possible |
| 848 volatile base::subtle::AtomicWord refcount; | 848 volatile base::subtle::AtomicWord refcount; |
| 849 void AddRef(); // For convenience. | 849 void AddRef(); // For convenience. |
| 850 void Release(); | 850 void Release(); |
| 851 | 851 |
| 852 // Implements ReadTransaction / WriteTransaction using a simple lock. | 852 // Implements ReadTransaction / WriteTransaction using a simple lock. |
| 853 Lock transaction_mutex; | 853 Lock transaction_mutex; |
| 854 | 854 |
| 855 // The name of this directory, used as a key into open_files_; | 855 // The name of this directory, used as a key into open_files_; |
| 856 PathString const name_; | 856 std::string const name_; |
| 857 | 857 |
| 858 // Protects all members below. | 858 // Protects all members below. |
| 859 // The mutex effectively protects all the indices, but not the | 859 // The mutex effectively protects all the indices, but not the |
| 860 // entries themselves. So once a pointer to an entry is pulled | 860 // entries themselves. So once a pointer to an entry is pulled |
| 861 // from the index, the mutex can be unlocked and entry read or written. | 861 // from the index, the mutex can be unlocked and entry read or written. |
| 862 // | 862 // |
| 863 // Never hold the mutex and do anything with the database or any | 863 // Never hold the mutex and do anything with the database or any |
| 864 // other buffered IO. Violating this rule will result in deadlock. | 864 // other buffered IO. Violating this rule will result in deadlock. |
| 865 Lock mutex; | 865 Lock mutex; |
| 866 MetahandlesIndex* metahandles_index; // Entries indexed by metahandle | 866 MetahandlesIndex* metahandles_index; // Entries indexed by metahandle |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 protected: | 988 protected: |
| 989 // Before an entry gets modified, we copy the original into a list | 989 // Before an entry gets modified, we copy the original into a list |
| 990 // so that we can issue change notifications when the transaction | 990 // so that we can issue change notifications when the transaction |
| 991 // is done. | 991 // is done. |
| 992 OriginalEntries* const originals_; | 992 OriginalEntries* const originals_; |
| 993 | 993 |
| 994 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); | 994 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); |
| 995 }; | 995 }; |
| 996 | 996 |
| 997 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); | 997 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); |
| 998 int ComparePathNames(const PathString& a, const PathString& b); | 998 int ComparePathNames(const std::string& a, const std::string& b); |
| 999 | 999 |
| 1000 // Exposed in header as this is used as a sqlite3 callback. | 1000 // Exposed in header as this is used as a sqlite3 callback. |
| 1001 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, | 1001 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, |
| 1002 const void* b); | 1002 const void* b); |
| 1003 | 1003 |
| 1004 int64 Now(); | 1004 int64 Now(); |
| 1005 | 1005 |
| 1006 class ExtendedAttribute { | 1006 class ExtendedAttribute { |
| 1007 public: | 1007 public: |
| 1008 ExtendedAttribute(BaseTransaction* trans, GetByHandle, | 1008 ExtendedAttribute(BaseTransaction* trans, GetByHandle, |
| 1009 const ExtendedAttributeKey& key); | 1009 const ExtendedAttributeKey& key); |
| 1010 int64 metahandle() const { return i_->first.metahandle; } | 1010 int64 metahandle() const { return i_->first.metahandle; } |
| 1011 const PathString& key() const { return i_->first.key; } | 1011 const std::string& key() const { return i_->first.key; } |
| 1012 const Blob& value() const { return i_->second.value; } | 1012 const Blob& value() const { return i_->second.value; } |
| 1013 bool is_deleted() const { return i_->second.is_deleted; } | 1013 bool is_deleted() const { return i_->second.is_deleted; } |
| 1014 bool good() const { return good_; } | 1014 bool good() const { return good_; } |
| 1015 bool operator < (const ExtendedAttribute& x) const { | 1015 bool operator < (const ExtendedAttribute& x) const { |
| 1016 return i_->first < x.i_->first; | 1016 return i_->first < x.i_->first; |
| 1017 } | 1017 } |
| 1018 protected: | 1018 protected: |
| 1019 bool Init(BaseTransaction* trans, | 1019 bool Init(BaseTransaction* trans, |
| 1020 Directory::Kernel* const kernel, | 1020 Directory::Kernel* const kernel, |
| 1021 ScopedKernelLock* lock, | 1021 ScopedKernelLock* lock, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1042 i_->second.dirty = true; | 1042 i_->second.dirty = true; |
| 1043 i_->second.is_deleted = true; | 1043 i_->second.is_deleted = true; |
| 1044 } | 1044 } |
| 1045 }; | 1045 }; |
| 1046 | 1046 |
| 1047 // Get an extended attribute from an Entry by name. Returns a pointer | 1047 // Get an extended attribute from an Entry by name. Returns a pointer |
| 1048 // to a const Blob containing the attribute data, or NULL if there is | 1048 // to a const Blob containing the attribute data, or NULL if there is |
| 1049 // no attribute with the given name. The pointer is valid for the | 1049 // no attribute with the given name. The pointer is valid for the |
| 1050 // duration of the Entry's transaction. | 1050 // duration of the Entry's transaction. |
| 1051 const Blob* GetExtendedAttributeValue(const Entry& e, | 1051 const Blob* GetExtendedAttributeValue(const Entry& e, |
| 1052 const PathString& attribute_name); | 1052 const std::string& attribute_name); |
| 1053 | 1053 |
| 1054 // This function sets only the flags needed to get this entry to sync. | 1054 // This function sets only the flags needed to get this entry to sync. |
| 1055 void MarkForSyncing(syncable::MutableEntry* e); | 1055 void MarkForSyncing(syncable::MutableEntry* e); |
| 1056 | 1056 |
| 1057 // This is not a reset. It just sets the numeric fields which are not | 1057 // This is not a reset. It just sets the numeric fields which are not |
| 1058 // initialized by the constructor to zero. | 1058 // initialized by the constructor to zero. |
| 1059 void ZeroFields(EntryKernel* entry, int first_field); | 1059 void ZeroFields(EntryKernel* entry, int first_field); |
| 1060 | 1060 |
| 1061 } // namespace syncable | 1061 } // namespace syncable |
| 1062 | 1062 |
| 1063 std::ostream& operator <<(std::ostream&, const syncable::Blob&); | 1063 std::ostream& operator <<(std::ostream&, const syncable::Blob&); |
| 1064 | 1064 |
| 1065 browser_sync::FastDump& operator << | 1065 browser_sync::FastDump& operator << |
| 1066 (browser_sync::FastDump&, const syncable::Blob&); | 1066 (browser_sync::FastDump&, const syncable::Blob&); |
| 1067 | 1067 |
| 1068 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 1068 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| OLD | NEW |