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 #include "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
6 | 6 |
| 7 #include "build/build_config.h" |
| 8 |
7 #include <sys/stat.h> | 9 #include <sys/stat.h> |
8 #include <sys/types.h> | 10 #include <sys/types.h> |
9 #include <time.h> | 11 #include <time.h> |
10 #ifdef OS_MACOSX | 12 #ifdef OS_MACOSX |
11 #include <CoreFoundation/CoreFoundation.h> | 13 #include <CoreFoundation/CoreFoundation.h> |
12 #elif defined(OS_LINUX) | 14 #elif defined(OS_LINUX) |
13 #include <glib.h> | 15 #include <glib.h> |
14 #elif defined(OS_WINDOWS) | 16 #elif defined(OS_WIN) |
15 #include <shlwapi.h> // for PathMatchSpec | 17 #include <shlwapi.h> // for PathMatchSpec |
16 #endif | 18 #endif |
17 | 19 |
18 #include <algorithm> | 20 #include <algorithm> |
19 #include <functional> | 21 #include <functional> |
20 #include <iomanip> | 22 #include <iomanip> |
21 #include <iterator> | 23 #include <iterator> |
22 #include <set> | 24 #include <set> |
23 #include <string> | 25 #include <string> |
24 | 26 |
25 #include "base/hash_tables.h" | 27 #include "base/hash_tables.h" |
26 #include "base/logging.h" | 28 #include "base/logging.h" |
27 #include "base/perftimer.h" | 29 #include "base/perftimer.h" |
28 #include "base/scoped_ptr.h" | 30 #include "base/scoped_ptr.h" |
29 #include "base/time.h" | 31 #include "base/time.h" |
30 #include "chrome/browser/sync/engine/syncer.h" | 32 #include "chrome/browser/sync/engine/syncer.h" |
31 #include "chrome/browser/sync/engine/syncer_util.h" | 33 #include "chrome/browser/sync/engine/syncer_util.h" |
32 #include "chrome/browser/sync/protocol/service_constants.h" | 34 #include "chrome/browser/sync/protocol/service_constants.h" |
33 #include "chrome/browser/sync/syncable/directory_backing_store.h" | 35 #include "chrome/browser/sync/syncable/directory_backing_store.h" |
34 #include "chrome/browser/sync/syncable/directory_manager.h" | 36 #include "chrome/browser/sync/syncable/directory_manager.h" |
35 #include "chrome/browser/sync/syncable/syncable-inl.h" | 37 #include "chrome/browser/sync/syncable/syncable-inl.h" |
36 #include "chrome/browser/sync/syncable/syncable_changes_version.h" | 38 #include "chrome/browser/sync/syncable/syncable_changes_version.h" |
37 #include "chrome/browser/sync/syncable/syncable_columns.h" | 39 #include "chrome/browser/sync/syncable/syncable_columns.h" |
38 #include "chrome/browser/sync/util/character_set_converters.h" | 40 #include "chrome/browser/sync/util/character_set_converters.h" |
39 #include "chrome/browser/sync/util/compat-file.h" | 41 #include "chrome/browser/sync/util/compat_file.h" |
40 #include "chrome/browser/sync/util/crypto_helpers.h" | 42 #include "chrome/browser/sync/util/crypto_helpers.h" |
41 #include "chrome/browser/sync/util/event_sys-inl.h" | 43 #include "chrome/browser/sync/util/event_sys-inl.h" |
42 #include "chrome/browser/sync/util/fast_dump.h" | 44 #include "chrome/browser/sync/util/fast_dump.h" |
43 #include "chrome/browser/sync/util/path_helpers.h" | 45 #include "chrome/browser/sync/util/path_helpers.h" |
44 | 46 |
45 namespace { | 47 namespace { |
46 enum InvariantCheckLevel { | 48 enum InvariantCheckLevel { |
47 OFF = 0, | 49 OFF = 0, |
48 VERIFY_IN_MEMORY = 1, | 50 VERIFY_IN_MEMORY = 1, |
49 FULL_DB_VERIFICATION = 2 | 51 FULL_DB_VERIFICATION = 2 |
(...skipping 10 matching lines...) Expand all Loading... |
60 COMPILE_ASSERT(sizeof(time_t) == sizeof(int32), time_t_is_not_int32); | 62 COMPILE_ASSERT(sizeof(time_t) == sizeof(int32), time_t_is_not_int32); |
61 | 63 |
62 using browser_sync::FastDump; | 64 using browser_sync::FastDump; |
63 using browser_sync::SyncerUtil; | 65 using browser_sync::SyncerUtil; |
64 using std::string; | 66 using std::string; |
65 | 67 |
66 | 68 |
67 namespace syncable { | 69 namespace syncable { |
68 | 70 |
69 int64 Now() { | 71 int64 Now() { |
70 #ifdef OS_WINDOWS | 72 #ifdef OS_WIN |
71 FILETIME filetime; | 73 FILETIME filetime; |
72 SYSTEMTIME systime; | 74 SYSTEMTIME systime; |
73 GetSystemTime(&systime); | 75 GetSystemTime(&systime); |
74 SystemTimeToFileTime(&systime, &filetime); | 76 SystemTimeToFileTime(&systime, &filetime); |
75 // MSDN recommends converting via memcpy like this. | 77 // MSDN recommends converting via memcpy like this. |
76 LARGE_INTEGER n; | 78 LARGE_INTEGER n; |
77 memcpy(&n, &filetime, sizeof(filetime)); | 79 memcpy(&n, &filetime, sizeof(filetime)); |
78 return n.QuadPart; | 80 return n.QuadPart; |
79 #elif (defined(OS_LINUX) || defined(OS_MACOSX)) | 81 #elif (defined(OS_LINUX) || defined(OS_MACOSX)) |
80 struct timeval tv; | 82 struct timeval tv; |
81 gettimeofday(&tv, NULL); | 83 gettimeofday(&tv, NULL); |
82 return static_cast<int64>(tv.tv_sec); | 84 return static_cast<int64>(tv.tv_sec); |
83 #else | 85 #else |
84 #error NEED OS SPECIFIC Now() implementation | 86 #error NEED OS SPECIFIC Now() implementation |
85 #endif | 87 #endif |
86 } | 88 } |
87 | 89 |
88 /////////////////////////////////////////////////////////////////////////// | 90 /////////////////////////////////////////////////////////////////////////// |
89 // Compare functions and hashes for the indices. | 91 // Compare functions and hashes for the indices. |
90 | 92 |
91 // Callback for sqlite3 | 93 // Callback for sqlite3 |
92 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, | 94 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, |
93 const void* b) { | 95 const void* b) { |
94 #ifdef OS_WINDOWS | 96 #ifdef OS_WIN |
95 DCHECK_EQ(0, a_bytes % 2); | 97 DCHECK_EQ(0, a_bytes % 2); |
96 DCHECK_EQ(0, b_bytes % 2); | 98 DCHECK_EQ(0, b_bytes % 2); |
97 int result = CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, | 99 int result = CompareString(LOCALE_INVARIANT, NORM_IGNORECASE, |
98 static_cast<const PathChar*>(a), a_bytes / 2, | 100 static_cast<const PathChar*>(a), a_bytes / 2, |
99 static_cast<const PathChar*>(b), b_bytes / 2); | 101 static_cast<const PathChar*>(b), b_bytes / 2); |
100 CHECK(0 != result) << "Error comparing strings: " << GetLastError(); | 102 CHECK(0 != result) << "Error comparing strings: " << GetLastError(); |
101 return result - 2; // Convert to -1, 0, 1 | 103 return result - 2; // Convert to -1, 0, 1 |
102 #elif defined(OS_LINUX) | 104 #elif defined(OS_LINUX) |
103 // misnomer for Linux. These are already utf8 bit strings. | 105 // misnomer for Linux. These are already utf8 bit strings. |
104 gchar *case_folded_a; | 106 gchar *case_folded_a; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 247 } |
246 | 248 |
247 Directory::Directory() : kernel_(NULL), store_(NULL) { | 249 Directory::Directory() : kernel_(NULL), store_(NULL) { |
248 } | 250 } |
249 | 251 |
250 Directory::~Directory() { | 252 Directory::~Directory() { |
251 Close(); | 253 Close(); |
252 } | 254 } |
253 | 255 |
254 BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec) { | 256 BOOL PathNameMatch(const PathString& pathname, const PathString& pathspec) { |
255 #ifdef OS_WINDOWS | 257 #ifdef OS_WIN |
256 // Note that if we go Vista only this is easier: | 258 // Note that if we go Vista only this is easier: |
257 // http://msdn2.microsoft.com/en-us/library/ms628611.aspx | 259 // http://msdn2.microsoft.com/en-us/library/ms628611.aspx |
258 | 260 |
259 // PathMatchSpec strips spaces from the start of pathspec, so we compare those | 261 // PathMatchSpec strips spaces from the start of pathspec, so we compare those |
260 // ourselves. | 262 // ourselves. |
261 const PathChar* pathname_ptr = pathname.c_str(); | 263 const PathChar* pathname_ptr = pathname.c_str(); |
262 const PathChar* pathspec_ptr = pathspec.c_str(); | 264 const PathChar* pathspec_ptr = pathspec.c_str(); |
263 | 265 |
264 while (*pathname_ptr == ' ' && *pathspec_ptr == ' ') | 266 while (*pathname_ptr == ' ' && *pathspec_ptr == ' ') |
265 ++pathname_ptr, ++pathspec_ptr; | 267 ++pathname_ptr, ++pathspec_ptr; |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 // There was a collision, so fix the name. | 1861 // There was a collision, so fix the name. |
1860 basename = FixBasenameInCollision(basename); | 1862 basename = FixBasenameInCollision(basename); |
1861 } | 1863 } |
1862 // Set our value to the new value. This invalidates desired_name. | 1864 // Set our value to the new value. This invalidates desired_name. |
1863 PathString new_value = basename + dotextension; | 1865 PathString new_value = basename + dotextension; |
1864 swap(new_value); | 1866 swap(new_value); |
1865 } | 1867 } |
1866 | 1868 |
1867 PathString GetFullPath(BaseTransaction* trans, const Entry& e) { | 1869 PathString GetFullPath(BaseTransaction* trans, const Entry& e) { |
1868 PathString result; | 1870 PathString result; |
1869 #ifdef STL_MSVC | 1871 #ifdef COMPILER_MSVC |
1870 result.reserve(MAX_PATH); | 1872 result.reserve(MAX_PATH); |
1871 #endif | 1873 #endif |
1872 ReverseAppend(e.Get(NAME), &result); | 1874 ReverseAppend(e.Get(NAME), &result); |
1873 Id id = e.Get(PARENT_ID); | 1875 Id id = e.Get(PARENT_ID); |
1874 while (!id.IsRoot()) { | 1876 while (!id.IsRoot()) { |
1875 result.push_back(kPathSeparator[0]); | 1877 result.push_back(kPathSeparator[0]); |
1876 Entry ancestor(trans, GET_BY_ID, id); | 1878 Entry ancestor(trans, GET_BY_ID, id); |
1877 if (!ancestor.good()) { | 1879 if (!ancestor.good()) { |
1878 // This can happen if the parent folder got deleted before the entry. | 1880 // This can happen if the parent folder got deleted before the entry. |
1879 LOG(WARNING) << "Cannot get full path of " << e | 1881 LOG(WARNING) << "Cannot get full path of " << e |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 return dump; | 1995 return dump; |
1994 } | 1996 } |
1995 | 1997 |
1996 std::ostream& operator<<(std::ostream& s, const syncable::ThreadNode& node) { | 1998 std::ostream& operator<<(std::ostream& s, const syncable::ThreadNode& node) { |
1997 s << "thread id: " << std::hex << node.id << "\n" | 1999 s << "thread id: " << std::hex << node.id << "\n" |
1998 << "file: " << node.file << "\n" | 2000 << "file: " << node.file << "\n" |
1999 << "line: " << std::dec << node.line << "\n" | 2001 << "line: " << std::dec << node.line << "\n" |
2000 << "wait_started: " << node.wait_started.ToInternalValue(); | 2002 << "wait_started: " << node.wait_started.ToInternalValue(); |
2001 return s; | 2003 return s; |
2002 } | 2004 } |
OLD | NEW |