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

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

Issue 340055: String cleanup in sync code (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 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>
11 #include <map> 11 #include <map>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/atomicops.h" 16 #include "base/atomicops.h"
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/file_path.h"
18 #include "base/lock.h" 19 #include "base/lock.h"
19 #include "base/time.h" 20 #include "base/time.h"
20 #include "chrome/browser/sync/syncable/blob.h" 21 #include "chrome/browser/sync/syncable/blob.h"
21 #include "chrome/browser/sync/syncable/dir_open_result.h" 22 #include "chrome/browser/sync/syncable/dir_open_result.h"
22 #include "chrome/browser/sync/syncable/directory_event.h" 23 #include "chrome/browser/sync/syncable/directory_event.h"
23 #include "chrome/browser/sync/syncable/path_name_cmp.h" 24 #include "chrome/browser/sync/syncable/path_name_cmp.h"
24 #include "chrome/browser/sync/syncable/syncable_id.h" 25 #include "chrome/browser/sync/syncable/syncable_id.h"
25 #include "chrome/browser/sync/util/compat_file.h"
26 #include "chrome/browser/sync/util/dbgq.h" 26 #include "chrome/browser/sync/util/dbgq.h"
27 #include "chrome/browser/sync/util/event_sys.h" 27 #include "chrome/browser/sync/util/event_sys.h"
28 #include "chrome/browser/sync/util/path_helpers.h" 28 #include "chrome/browser/sync/util/path_helpers.h"
29 #include "chrome/browser/sync/util/row_iterator.h" 29 #include "chrome/browser/sync/util/row_iterator.h"
30 #include "chrome/browser/sync/util/sync_types.h" 30 #include "chrome/browser/sync/util/sync_types.h"
31 31
32 struct PurgeInfo; 32 struct PurgeInfo;
33 33
34 namespace sync_api { 34 namespace sync_api {
35 class ReadTransaction; 35 class ReadTransaction;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 non_unique_value_ = value_; 312 non_unique_value_ = value_;
313 } 313 }
314 // TODO(ncarter): Handle server's other requirement: truncation to 256 314 // TODO(ncarter): Handle server's other requirement: truncation to 256
315 // bytes in Unicode NFC. 315 // bytes in Unicode NFC.
316 } 316 }
317 317
318 const PathString& value() const { return value_; } 318 const PathString& value() const { return value_; }
319 PathString& value() { return value_; } 319 PathString& value() { return value_; }
320 const PathString& non_unique_value() const { return non_unique_value_; } 320 const PathString& non_unique_value() const { return non_unique_value_; }
321 PathString& non_unique_value() { return non_unique_value_; } 321 PathString& non_unique_value() { return non_unique_value_; }
322 void set_non_unique_value(const PathString& value) {
323 non_unique_value_ = value;
324 }
322 325
323 inline bool operator==(const SyncName& right_hand_side) const { 326 inline bool operator==(const SyncName& right_hand_side) const {
324 return value_ == right_hand_side.value_ && 327 return value_ == right_hand_side.value_ &&
325 non_unique_value_ == right_hand_side.non_unique_value_; 328 non_unique_value_ == right_hand_side.non_unique_value_;
326 } 329 }
327 inline bool operator!=(const SyncName& right_hand_side) const { 330 inline bool operator!=(const SyncName& right_hand_side) const {
328 return !(*this == right_hand_side); 331 return !(*this == right_hand_side);
329 } 332 }
330 private: 333 private:
331 PathString value_; 334 PathString value_;
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 PersistedKernelInfo kernel_info; 882 PersistedKernelInfo kernel_info;
880 OriginalEntries dirty_metas; 883 OriginalEntries dirty_metas;
881 ExtendedAttributes dirty_xattrs; 884 ExtendedAttributes dirty_xattrs;
882 SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { 885 SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) {
883 } 886 }
884 }; 887 };
885 888
886 Directory(); 889 Directory();
887 virtual ~Directory(); 890 virtual ~Directory();
888 891
889 DirOpenResult Open(const PathString& file_path, const PathString& name); 892 DirOpenResult Open(const FilePath& file_path, const PathString& name);
890 893
891 void Close(); 894 void Close();
892 895
893 int64 NextMetahandle(); 896 int64 NextMetahandle();
894 // Always returns a negative id. Positive client ids are generated 897 // Always returns a negative id. Positive client ids are generated
895 // by the server only. 898 // by the server only.
896 Id NextId(); 899 Id NextId();
897 900
898 PathString file_path() const { return kernel_->db_path; } 901 const FilePath& file_path() const { return kernel_->db_path; }
899 bool good() const { return NULL != store_; } 902 bool good() const { return NULL != store_; }
900 903
901 // The sync timestamp is an index into the list of changes for an account. 904 // The sync timestamp is an index into the list of changes for an account.
902 // It doesn't actually map to any time scale, it's name is an historical 905 // It doesn't actually map to any time scale, it's name is an historical
903 // anomaly. 906 // anomaly.
904 int64 last_sync_timestamp() const; 907 int64 last_sync_timestamp() const;
905 void set_last_sync_timestamp(int64 timestamp); 908 void set_last_sync_timestamp(int64 timestamp);
906 909
907 bool initial_sync_ended() const; 910 bool initial_sync_ended() const;
908 void set_initial_sync_ended(bool value); 911 void set_initial_sync_ended(bool value);
(...skipping 22 matching lines...) Expand all
931 bool ReindexParentIdAndName(EntryKernel* const entry, const Id& new_parent_id, 934 bool ReindexParentIdAndName(EntryKernel* const entry, const Id& new_parent_id,
932 const PathString& new_name); 935 const PathString& new_name);
933 // These don't do the semantic checking that the redirector needs. 936 // These don't do the semantic checking that the redirector needs.
934 // The semantic checking is implemented higher up. 937 // The semantic checking is implemented higher up.
935 bool Undelete(EntryKernel* const entry); 938 bool Undelete(EntryKernel* const entry);
936 bool Delete(EntryKernel* const entry); 939 bool Delete(EntryKernel* const entry);
937 940
938 // Overridden by tests. 941 // Overridden by tests.
939 virtual DirectoryBackingStore* CreateBackingStore( 942 virtual DirectoryBackingStore* CreateBackingStore(
940 const PathString& dir_name, 943 const PathString& dir_name,
941 const PathString& backing_filepath); 944 const FilePath& backing_filepath);
942 945
943 private: 946 private:
944 // These private versions expect the kernel lock to already be held 947 // These private versions expect the kernel lock to already be held
945 // before calling. 948 // before calling.
946 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); 949 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock);
947 EntryKernel* GetChildWithName(const Id& parent_id, 950 EntryKernel* GetChildWithName(const Id& parent_id,
948 const PathString& name, 951 const PathString& name,
949 ScopedKernelLock* const lock); 952 ScopedKernelLock* const lock);
950 EntryKernel* GetChildWithNameImpl(const Id& parent_id, 953 EntryKernel* GetChildWithNameImpl(const Id& parent_id,
951 const PathString& name, 954 const PathString& name,
952 ScopedKernelLock* const lock); 955 ScopedKernelLock* const lock);
953 956
954 DirOpenResult OpenImpl(const PathString& file_path, const PathString& name); 957 DirOpenResult OpenImpl(const FilePath& file_path, const PathString& name);
955 958
956 struct DirectoryEventTraits { 959 struct DirectoryEventTraits {
957 typedef DirectoryEvent EventType; 960 typedef DirectoryEvent EventType;
958 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { 961 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) {
959 return DIRECTORY_DESTROYED == event; 962 return DIRECTORY_DESTROYED == event;
960 } 963 }
961 }; 964 };
962 public: 965 public:
963 typedef EventChannel<DirectoryEventTraits, Lock> Channel; 966 typedef EventChannel<DirectoryEventTraits, Lock> Channel;
964 typedef EventChannel<DirectoryChangeEvent, Lock> ChangesChannel; 967 typedef EventChannel<DirectoryChangeEvent, Lock> ChangesChannel;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 // All entries in memory must be in both the MetahandlesIndex and 1082 // All entries in memory must be in both the MetahandlesIndex and
1080 // the IdsIndex, but only non-deleted entries will be the 1083 // the IdsIndex, but only non-deleted entries will be the
1081 // ParentIdAndNamesIndex, because there can be multiple deleted 1084 // ParentIdAndNamesIndex, because there can be multiple deleted
1082 // entries with the same parent id and name. 1085 // entries with the same parent id and name.
1083 typedef std::set<EntryKernel*, LessParentIdAndNames> ParentIdAndNamesIndex; 1086 typedef std::set<EntryKernel*, LessParentIdAndNames> ParentIdAndNamesIndex;
1084 typedef std::vector<int64> MetahandlesToPurge; 1087 typedef std::vector<int64> MetahandlesToPurge;
1085 1088
1086 private: 1089 private:
1087 1090
1088 struct Kernel { 1091 struct Kernel {
1089 Kernel(const PathString& db_path, const PathString& name, 1092 Kernel(const FilePath& db_path, const PathString& name,
1090 const KernelLoadInfo& info); 1093 const KernelLoadInfo& info);
1091 1094
1092 ~Kernel(); 1095 ~Kernel();
1093 1096
1094 PathString const db_path; 1097 FilePath const db_path;
1095 // TODO(timsteele): audit use of the member and remove if possible 1098 // TODO(timsteele): audit use of the member and remove if possible
1096 volatile base::subtle::AtomicWord refcount; 1099 volatile base::subtle::AtomicWord refcount;
1097 void AddRef(); // For convenience. 1100 void AddRef(); // For convenience.
1098 void Release(); 1101 void Release();
1099 1102
1100 // Implements ReadTransaction / WriteTransaction using a simple lock. 1103 // Implements ReadTransaction / WriteTransaction using a simple lock.
1101 Lock transaction_mutex; 1104 Lock transaction_mutex;
1102 1105
1103 // The name of this directory, used as a key into open_files_; 1106 // The name of this directory, used as a key into open_files_;
1104 PathString const name_; 1107 PathString const name_;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 1250
1248 // Exposed in header as this is used as a sqlite3 callback. 1251 // Exposed in header as this is used as a sqlite3 callback.
1249 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, 1252 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes,
1250 const void* b); 1253 const void* b);
1251 1254
1252 int64 Now(); 1255 int64 Now();
1253 1256
1254 // Does wildcard processing. 1257 // Does wildcard processing.
1255 BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec); 1258 BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec);
1256 1259
1257 PathString GetFullPath(BaseTransaction* trans, const Entry& e);
1258
1259 inline void ReverseAppend(const PathString& s, PathString* target) {
1260 target->append(s.rbegin(), s.rend());
1261 }
1262
1263 class ExtendedAttribute { 1260 class ExtendedAttribute {
1264 public: 1261 public:
1265 ExtendedAttribute(BaseTransaction* trans, GetByHandle, 1262 ExtendedAttribute(BaseTransaction* trans, GetByHandle,
1266 const ExtendedAttributeKey& key); 1263 const ExtendedAttributeKey& key);
1267 int64 metahandle() const { return i_->first.metahandle; } 1264 int64 metahandle() const { return i_->first.metahandle; }
1268 const PathString& key() const { return i_->first.key; } 1265 const PathString& key() const { return i_->first.key; }
1269 const Blob& value() const { return i_->second.value; } 1266 const Blob& value() const { return i_->second.value; }
1270 bool is_deleted() const { return i_->second.is_deleted; } 1267 bool is_deleted() const { return i_->second.is_deleted; }
1271 bool good() const { return good_; } 1268 bool good() const { return good_; }
1272 bool operator < (const ExtendedAttribute& x) const { 1269 bool operator < (const ExtendedAttribute& x) const {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 void ZeroFields(EntryKernel* entry, int first_field); 1313 void ZeroFields(EntryKernel* entry, int first_field);
1317 1314
1318 } // namespace syncable 1315 } // namespace syncable
1319 1316
1320 std::ostream& operator <<(std::ostream&, const syncable::Blob&); 1317 std::ostream& operator <<(std::ostream&, const syncable::Blob&);
1321 1318
1322 browser_sync::FastDump& operator << 1319 browser_sync::FastDump& operator <<
1323 (browser_sync::FastDump&, const syncable::Blob&); 1320 (browser_sync::FastDump&, const syncable::Blob&);
1324 1321
1325 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 1322 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/directory_manager.cc ('k') | chrome/browser/sync/syncable/syncable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698