| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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/engine/syncapi.h" | 5 #include "chrome/browser/sync/engine/syncapi.h" |
| 6 | 6 |
| 7 #if defined(OS_WINDOWS) | 7 #include "build/build_config.h" |
| 8 |
| 9 #if defined(OS_WIN) |
| 8 #include <windows.h> | 10 #include <windows.h> |
| 9 #include <iphlpapi.h> | 11 #include <iphlpapi.h> |
| 10 #endif | 12 #endif |
| 11 | 13 |
| 12 #include <iomanip> | 14 #include <iomanip> |
| 13 #include <list> | 15 #include <list> |
| 14 #include <string> | 16 #include <string> |
| 15 #include <vector> | 17 #include <vector> |
| 16 | 18 |
| 17 #include "base/at_exit.h" | 19 #include "base/at_exit.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 // of multiple threads, and if some other part also tries to call InitLogFiles | 72 // of multiple threads, and if some other part also tries to call InitLogFiles |
| 71 // apart from this file. But this is okay for now since this is the only place | 73 // apart from this file. But this is okay for now since this is the only place |
| 72 // we call InitLogFiles. | 74 // we call InitLogFiles. |
| 73 namespace { | 75 namespace { |
| 74 static bool g_log_files_initialized = false; | 76 static bool g_log_files_initialized = false; |
| 75 static base::AtExitManager g_at_exit_manager; // Necessary for NewCallback. | 77 static base::AtExitManager g_at_exit_manager; // Necessary for NewCallback. |
| 76 } // namespace | 78 } // namespace |
| 77 | 79 |
| 78 struct ThreadParams { | 80 struct ThreadParams { |
| 79 browser_sync::ServerConnectionManager* conn_mgr; | 81 browser_sync::ServerConnectionManager* conn_mgr; |
| 80 #if defined(OS_WINDOWS) | 82 #if defined(OS_WIN) |
| 81 HANDLE exit_flag; | 83 HANDLE exit_flag; |
| 82 #endif | 84 #endif |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 // This thread calls CheckServerReachable() whenever a change occurs in the | 87 // This thread calls CheckServerReachable() whenever a change occurs in the |
| 86 // table that maps IP addresses to interfaces, for example when the user | 88 // table that maps IP addresses to interfaces, for example when the user |
| 87 // unplugs his network cable. | 89 // unplugs his network cable. |
| 88 void* AddressWatchThread(void* arg) { | 90 void* AddressWatchThread(void* arg) { |
| 89 NameCurrentThreadForDebugging("SyncEngine_AddressWatcher"); | 91 NameCurrentThreadForDebugging("SyncEngine_AddressWatcher"); |
| 90 LOG(INFO) << "starting the address watch thread"; | 92 LOG(INFO) << "starting the address watch thread"; |
| 91 const ThreadParams* const params = reinterpret_cast<const ThreadParams*>(arg); | 93 const ThreadParams* const params = reinterpret_cast<const ThreadParams*>(arg); |
| 92 #if defined(OS_WINDOWS) | 94 #if defined(OS_WIN) |
| 93 OVERLAPPED overlapped = {0}; | 95 OVERLAPPED overlapped = {0}; |
| 94 overlapped.hEvent = CreateEvent(NULL, FALSE, TRUE, NULL); | 96 overlapped.hEvent = CreateEvent(NULL, FALSE, TRUE, NULL); |
| 95 HANDLE file; | 97 HANDLE file; |
| 96 DWORD rc = WAIT_OBJECT_0; | 98 DWORD rc = WAIT_OBJECT_0; |
| 97 while (true) { | 99 while (true) { |
| 98 // Only call NotifyAddrChange() after the IP address has changed or if this | 100 // Only call NotifyAddrChange() after the IP address has changed or if this |
| 99 // is the first time through the loop. | 101 // is the first time through the loop. |
| 100 if (WAIT_OBJECT_0 == rc) { | 102 if (WAIT_OBJECT_0 == rc) { |
| 101 ResetEvent(overlapped.hEvent); | 103 ResetEvent(overlapped.hEvent); |
| 102 DWORD notify_result = NotifyAddrChange(&file, &overlapped); | 104 DWORD notify_result = NotifyAddrChange(&file, &overlapped); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 return false; | 163 return false; |
| 162 } | 164 } |
| 163 | 165 |
| 164 static bool EndsWithSpace(const string16& string) { | 166 static bool EndsWithSpace(const string16& string) { |
| 165 return !string.empty() && *string.rbegin() == ' '; | 167 return !string.empty() && *string.rbegin() == ' '; |
| 166 } | 168 } |
| 167 | 169 |
| 168 static inline void String16ToPathString(const sync_char16 *in, | 170 static inline void String16ToPathString(const sync_char16 *in, |
| 169 PathString *out) { | 171 PathString *out) { |
| 170 string16 in_str(in); | 172 string16 in_str(in); |
| 171 #if defined(OS_WINDOWS) | 173 #if defined(OS_WIN) |
| 172 out->assign(in_str); | 174 out->assign(in_str); |
| 173 #else | 175 #else |
| 174 UTF16ToUTF8(in_str.c_str(), in_str.length(), out); | 176 UTF16ToUTF8(in_str.c_str(), in_str.length(), out); |
| 175 #endif | 177 #endif |
| 176 } | 178 } |
| 177 | 179 |
| 178 static inline void PathStringToString16(const PathString& in, string16* out) { | 180 static inline void PathStringToString16(const PathString& in, string16* out) { |
| 179 #if defined(OS_WINDOWS) | 181 #if defined(OS_WIN) |
| 180 out->assign(in); | 182 out->assign(in); |
| 181 #else | 183 #else |
| 182 UTF8ToUTF16(in.c_str(), in.length(), out); | 184 UTF8ToUTF16(in.c_str(), in.length(), out); |
| 183 #endif | 185 #endif |
| 184 } | 186 } |
| 185 | 187 |
| 186 // When taking a name from the syncapi, append a space if it matches the | 188 // When taking a name from the syncapi, append a space if it matches the |
| 187 // pattern of a server-illegal name followed by zero or more spaces. | 189 // pattern of a server-illegal name followed by zero or more spaces. |
| 188 static void SyncAPINameToServerName(const sync_char16 *sync_api_name, | 190 static void SyncAPINameToServerName(const sync_char16 *sync_api_name, |
| 189 PathString* out) { | 191 PathString* out) { |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 string client_id = user_settings_->GetClientId(); | 1008 string client_id = user_settings_->GetClientId(); |
| 1007 connection_manager_.reset(new SyncAPIServerConnectionManager( | 1009 connection_manager_.reset(new SyncAPIServerConnectionManager( |
| 1008 sync_server_and_path, port, use_ssl, user_agent, client_id)); | 1010 sync_server_and_path, port, use_ssl, user_agent, client_id)); |
| 1009 | 1011 |
| 1010 // TODO(timsteele): This is temporary windows crap needed to listen for | 1012 // TODO(timsteele): This is temporary windows crap needed to listen for |
| 1011 // network status changes. We should either pump this up to the embedder to | 1013 // network status changes. We should either pump this up to the embedder to |
| 1012 // do (and call us in CheckServerReachable, for ex), or at least make this | 1014 // do (and call us in CheckServerReachable, for ex), or at least make this |
| 1013 // platform independent in here. | 1015 // platform independent in here. |
| 1014 // TODO(ncarter): When this gets cleaned up, the implementation of | 1016 // TODO(ncarter): When this gets cleaned up, the implementation of |
| 1015 // CreatePThread can also be removed. | 1017 // CreatePThread can also be removed. |
| 1016 #if defined(OS_WINDOWS) | 1018 #if defined(OS_WIN) |
| 1017 HANDLE exit_flag = CreateEvent(NULL, TRUE /*manual reset*/, FALSE, NULL); | 1019 HANDLE exit_flag = CreateEvent(NULL, TRUE /*manual reset*/, FALSE, NULL); |
| 1018 address_watch_params_.exit_flag = exit_flag; | 1020 address_watch_params_.exit_flag = exit_flag; |
| 1019 #endif | 1021 #endif |
| 1020 address_watch_params_.conn_mgr = connection_manager(); | 1022 address_watch_params_.conn_mgr = connection_manager(); |
| 1021 address_watch_thread_ = CreatePThread(AddressWatchThread, | 1023 address_watch_thread_ = CreatePThread(AddressWatchThread, |
| 1022 &address_watch_params_); | 1024 &address_watch_params_); |
| 1023 DCHECK(NULL != address_watch_thread_); | 1025 DCHECK(NULL != address_watch_thread_); |
| 1024 | 1026 |
| 1025 // Hand over the bridged POST factory to be owned by the connection | 1027 // Hand over the bridged POST factory to be owned by the connection |
| 1026 // dir_manager. | 1028 // dir_manager. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 // Reset the DirectoryManager and UserSettings so they relinquish sqlite | 1202 // Reset the DirectoryManager and UserSettings so they relinquish sqlite |
| 1201 // handles to backing files. | 1203 // handles to backing files. |
| 1202 share_.dir_manager.reset(); | 1204 share_.dir_manager.reset(); |
| 1203 user_settings_.reset(); | 1205 user_settings_.reset(); |
| 1204 | 1206 |
| 1205 // We don't want to process any more events. | 1207 // We don't want to process any more events. |
| 1206 dir_change_hookup_.reset(); | 1208 dir_change_hookup_.reset(); |
| 1207 syncer_event_.reset(); | 1209 syncer_event_.reset(); |
| 1208 authwatcher_hookup_.reset(); | 1210 authwatcher_hookup_.reset(); |
| 1209 | 1211 |
| 1210 #if defined(OS_WINDOWS) | 1212 #if defined(OS_WIN) |
| 1211 // Stop the address watch thread by signaling the exit flag. | 1213 // Stop the address watch thread by signaling the exit flag. |
| 1212 // TODO(timsteele): Same as todo in Init(). | 1214 // TODO(timsteele): Same as todo in Init(). |
| 1213 SetEvent(address_watch_params_.exit_flag); | 1215 SetEvent(address_watch_params_.exit_flag); |
| 1214 const DWORD wait_result = WaitForSingleObject(address_watch_thread_, | 1216 const DWORD wait_result = WaitForSingleObject(address_watch_thread_, |
| 1215 kThreadExitTimeoutMsec); | 1217 kThreadExitTimeoutMsec); |
| 1216 LOG_IF(ERROR, WAIT_FAILED == wait_result) << "Waiting for addr change thread " | 1218 LOG_IF(ERROR, WAIT_FAILED == wait_result) << "Waiting for addr change thread " |
| 1217 "to exit failed. GetLastError(): " << hex << GetLastError(); | 1219 "to exit failed. GetLastError(): " << hex << GetLastError(); |
| 1218 LOG_IF(ERROR, WAIT_TIMEOUT == wait_result) << "Thread exit timeout expired"; | 1220 LOG_IF(ERROR, WAIT_TIMEOUT == wait_result) << "Thread exit timeout expired"; |
| 1219 CloseHandle(address_watch_params_.exit_flag); | 1221 CloseHandle(address_watch_params_.exit_flag); |
| 1220 #endif | 1222 #endif |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 BaseTransaction::~BaseTransaction() { | 1558 BaseTransaction::~BaseTransaction() { |
| 1557 delete lookup_; | 1559 delete lookup_; |
| 1558 } | 1560 } |
| 1559 | 1561 |
| 1560 UserShare* SyncManager::GetUserShare() const { | 1562 UserShare* SyncManager::GetUserShare() const { |
| 1561 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; | 1563 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; |
| 1562 return data_->GetUserShare(); | 1564 return data_->GetUserShare(); |
| 1563 } | 1565 } |
| 1564 | 1566 |
| 1565 } // namespace sync_api | 1567 } // namespace sync_api |
| OLD | NEW |