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

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

Issue 7926001: [Sync] Move change-related methods out of SyncManager::Observer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 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 #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 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <bitset> 10 #include <bitset>
11 #include <cstddef>
11 #include <iosfwd> 12 #include <iosfwd>
12 #include <limits> 13 #include <limits>
13 #include <map> 14 #include <map>
14 #include <set> 15 #include <set>
15 #include <string> 16 #include <string>
16 #include <vector> 17 #include <vector>
17 18
18 #include "base/atomicops.h" 19 #include "base/atomicops.h"
19 #include "base/basictypes.h" 20 #include "base/basictypes.h"
20 #include "base/file_path.h" 21 #include "base/file_path.h"
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet; 560 typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet;
560 561
561 struct EntryKernelMutation { 562 struct EntryKernelMutation {
562 EntryKernel original, mutated; 563 EntryKernel original, mutated;
563 }; 564 };
564 typedef std::map<int64, EntryKernelMutation> EntryKernelMutationMap; 565 typedef std::map<int64, EntryKernelMutation> EntryKernelMutationMap;
565 566
566 typedef browser_sync::Immutable<EntryKernelMutationMap> 567 typedef browser_sync::Immutable<EntryKernelMutationMap>
567 ImmutableEntryKernelMutationMap; 568 ImmutableEntryKernelMutationMap;
568 569
570 // A WriteTransaction has a writer tag describing which body of code is doing
571 // the write. This is defined up here since WriteTransactionInfo also contains
572 // one.
573 enum WriterTag {
574 INVALID,
575 SYNCER,
576 AUTHWATCHER,
577 UNITTEST,
578 VACUUM_AFTER_SAVE,
579 PURGE_ENTRIES,
580 SYNCAPI
581 };
582
583 // Make sure to update this if you update WriterTag.
584 std::string WriterTagToString(WriterTag writer_tag);
585
586 struct WriteTransactionInfo {
587 WriteTransactionInfo(int64 id,
588 tracked_objects::Location location,
589 WriterTag writer,
590 ImmutableEntryKernelMutationMap mutations);
591 WriteTransactionInfo();
592 ~WriteTransactionInfo();
593
594 // Caller owns the return value.
595 base::DictionaryValue* ToValue(size_t max_mutations_size) const;
596
597 int64 id;
598 // TODO(akalin): Use Location when it becomes assignable.
599 std::string location_string;
600 WriterTag writer;
601 ImmutableEntryKernelMutationMap mutations;
602 };
603
604 typedef
605 browser_sync::Immutable<WriteTransactionInfo>
606 ImmutableWriteTransactionInfo;
607
608 // Caller owns the return value.
609 base::DictionaryValue* EntryKernelMutationToValue(
610 const EntryKernelMutation& mutation);
611
569 // Caller owns the return value. 612 // Caller owns the return value.
570 base::ListValue* EntryKernelMutationMapToValue( 613 base::ListValue* EntryKernelMutationMapToValue(
571 const EntryKernelMutationMap& mutations); 614 const EntryKernelMutationMap& mutations);
572 615
573 // How syncable indices & Indexers work. 616 // How syncable indices & Indexers work.
574 // 617 //
575 // The syncable Directory maintains several indices on the Entries it tracks. 618 // The syncable Directory maintains several indices on the Entries it tracks.
576 // The indices follow a common pattern: 619 // The indices follow a common pattern:
577 // (a) The index allows efficient lookup of an Entry* with particular 620 // (a) The index allows efficient lookup of an Entry* with particular
578 // field values. This is done by use of a std::set<> and a custom 621 // field values. This is done by use of a std::set<> and a custom
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 static bool ShouldInclude(const EntryKernel* a); 676 static bool ShouldInclude(const EntryKernel* a);
634 }; 677 };
635 678
636 // Given an Indexer providing the semantics of an index, defines the 679 // Given an Indexer providing the semantics of an index, defines the
637 // set type used to actually contain the index. 680 // set type used to actually contain the index.
638 template <typename Indexer> 681 template <typename Indexer>
639 struct Index { 682 struct Index {
640 typedef std::set<EntryKernel*, typename Indexer::Comparator> Set; 683 typedef std::set<EntryKernel*, typename Indexer::Comparator> Set;
641 }; 684 };
642 685
643 // a WriteTransaction has a writer tag describing which body of code is doing
644 // the write. This is defined up here since DirectoryChangeEvent also contains
645 // one.
646 enum WriterTag {
647 INVALID,
648 SYNCER,
649 AUTHWATCHER,
650 UNITTEST,
651 VACUUM_AFTER_SAVE,
652 PURGE_ENTRIES,
653 SYNCAPI
654 };
655
656 // Make sure to update this if you update WriterTag.
657 std::string WriterTagToString(WriterTag writer_tag);
658
659 // The name Directory in this case means the entire directory 686 // The name Directory in this case means the entire directory
660 // structure within a single user account. 687 // structure within a single user account.
661 // 688 //
662 // Sqlite is a little goofy, in that each thread must access a database 689 // Sqlite is a little goofy, in that each thread must access a database
663 // via its own handle. So, a Directory object should only be accessed 690 // via its own handle. So, a Directory object should only be accessed
664 // from a single thread. Use DirectoryManager's Open() method to 691 // from a single thread. Use DirectoryManager's Open() method to
665 // always get a directory that has been properly initialized on the 692 // always get a directory that has been properly initialized on the
666 // current thread. 693 // current thread.
667 // 694 //
668 // The db is protected against concurrent modification by a reader/ 695 // The db is protected against concurrent modification by a reader/
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 void AddRef(); // For convenience. 1019 void AddRef(); // For convenience.
993 void Release(); 1020 void Release();
994 1021
995 FilePath const db_path; 1022 FilePath const db_path;
996 // TODO(timsteele): audit use of the member and remove if possible 1023 // TODO(timsteele): audit use of the member and remove if possible
997 volatile base::subtle::AtomicWord refcount; 1024 volatile base::subtle::AtomicWord refcount;
998 1025
999 // Implements ReadTransaction / WriteTransaction using a simple lock. 1026 // Implements ReadTransaction / WriteTransaction using a simple lock.
1000 base::Lock transaction_mutex; 1027 base::Lock transaction_mutex;
1001 1028
1029 // Protected by transaction_mutex. Used by WriteTransactions.
1030 int64 next_write_transaction_id;
1031
1002 // The name of this directory. 1032 // The name of this directory.
1003 std::string const name; 1033 std::string const name;
1004 1034
1005 // Protects all members below. 1035 // Protects all members below.
1006 // The mutex effectively protects all the indices, but not the 1036 // The mutex effectively protects all the indices, but not the
1007 // entries themselves. So once a pointer to an entry is pulled 1037 // entries themselves. So once a pointer to an entry is pulled
1008 // from the index, the mutex can be unlocked and entry read or written. 1038 // from the index, the mutex can be unlocked and entry read or written.
1009 // 1039 //
1010 // Never hold the mutex and do anything with the database or any 1040 // Never hold the mutex and do anything with the database or any
1011 // other buffered IO. Violating this rule will result in deadlock. 1041 // other buffered IO. Violating this rule will result in deadlock.
(...skipping 23 matching lines...) Expand all
1035 1065
1036 // These 3 members are backed in the share_info table, and 1066 // These 3 members are backed in the share_info table, and
1037 // their state is marked by the flag above. 1067 // their state is marked by the flag above.
1038 1068
1039 // A structure containing the Directory state that is written back into the 1069 // A structure containing the Directory state that is written back into the
1040 // database on SaveChanges. 1070 // database on SaveChanges.
1041 PersistedKernelInfo persisted_info; 1071 PersistedKernelInfo persisted_info;
1042 1072
1043 // A unique identifier for this account's cache db, used to generate 1073 // A unique identifier for this account's cache db, used to generate
1044 // unique server IDs. No need to lock, only written at init time. 1074 // unique server IDs. No need to lock, only written at init time.
1045 std::string cache_guid; 1075 const std::string cache_guid;
1046 1076
1047 // It doesn't make sense for two threads to run SaveChanges at the same 1077 // It doesn't make sense for two threads to run SaveChanges at the same
1048 // time; this mutex protects that activity. 1078 // time; this mutex protects that activity.
1049 base::Lock save_changes_mutex; 1079 base::Lock save_changes_mutex;
1050 1080
1051 // The next metahandle is protected by kernel mutex. 1081 // The next metahandle is protected by kernel mutex.
1052 int64 next_metahandle; 1082 int64 next_metahandle;
1053 1083
1054 // Keep a history of recently flushed metahandles for debugging 1084 // Keep a history of recently flushed metahandles for debugging
1055 // purposes. Protected by the save_changes_mutex. 1085 // purposes. Protected by the save_changes_mutex.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 1220
1191 // This is not a reset. It just sets the numeric fields which are not 1221 // This is not a reset. It just sets the numeric fields which are not
1192 // initialized by the constructor to zero. 1222 // initialized by the constructor to zero.
1193 void ZeroFields(EntryKernel* entry, int first_field); 1223 void ZeroFields(EntryKernel* entry, int first_field);
1194 1224
1195 } // namespace syncable 1225 } // namespace syncable
1196 1226
1197 std::ostream& operator <<(std::ostream&, const syncable::Blob&); 1227 std::ostream& operator <<(std::ostream&, const syncable::Blob&);
1198 1228
1199 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 1229 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/directory_change_delegate.h ('k') | chrome/browser/sync/syncable/syncable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698