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

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 242118: Change the Windows build to statically link the sync library. (Closed)
Patch Set: Created 11 years, 2 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
OLDNEW
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 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #include <iphlpapi.h> 11 #include <iphlpapi.h>
12 #endif 12 #endif
13 13
14 #include <iomanip> 14 #include <iomanip>
15 #include <list> 15 #include <list>
16 #include <string> 16 #include <string>
17 #include <vector> 17 #include <vector>
18 18
19 #include "base/at_exit.h"
20 #include "base/basictypes.h" 19 #include "base/basictypes.h"
21 #include "base/command_line.h" 20 #include "base/command_line.h"
22 #include "base/scoped_ptr.h" 21 #include "base/scoped_ptr.h"
23 #include "base/string_util.h" 22 #include "base/string_util.h"
24 #include "chrome/browser/sync/engine/all_status.h" 23 #include "chrome/browser/sync/engine/all_status.h"
25 #include "chrome/browser/sync/engine/auth_watcher.h" 24 #include "chrome/browser/sync/engine/auth_watcher.h"
26 #include "chrome/browser/sync/engine/change_reorder_buffer.h" 25 #include "chrome/browser/sync/engine/change_reorder_buffer.h"
27 #include "chrome/browser/sync/engine/client_command_channel.h" 26 #include "chrome/browser/sync/engine/client_command_channel.h"
28 #include "chrome/browser/sync/engine/model_safe_worker.h" 27 #include "chrome/browser/sync/engine/model_safe_worker.h"
29 #include "chrome/browser/sync/engine/net/gaia_authenticator.h" 28 #include "chrome/browser/sync/engine/net/gaia_authenticator.h"
30 #include "chrome/browser/sync/engine/net/server_connection_manager.h" 29 #include "chrome/browser/sync/engine/net/server_connection_manager.h"
31 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h" 30 #include "chrome/browser/sync/engine/net/syncapi_server_connection_manager.h"
32 #include "chrome/browser/sync/engine/syncer.h" 31 #include "chrome/browser/sync/engine/syncer.h"
33 #include "chrome/browser/sync/engine/syncer_thread.h" 32 #include "chrome/browser/sync/engine/syncer_thread.h"
34 #include "chrome/browser/sync/notifier/listener/talk_mediator.h" 33 #include "chrome/browser/sync/notifier/listener/talk_mediator.h"
35 #include "chrome/browser/sync/notifier/listener/talk_mediator_impl.h" 34 #include "chrome/browser/sync/notifier/listener/talk_mediator_impl.h"
36 #include "chrome/browser/sync/protocol/service_constants.h" 35 #include "chrome/browser/sync/protocol/service_constants.h"
37 #include "chrome/browser/sync/syncable/directory_manager.h" 36 #include "chrome/browser/sync/syncable/directory_manager.h"
38 #include "chrome/browser/sync/syncable/syncable.h" 37 #include "chrome/browser/sync/syncable/syncable.h"
39 #include "chrome/browser/sync/util/character_set_converters.h" 38 #include "chrome/browser/sync/util/character_set_converters.h"
40 #include "chrome/browser/sync/util/closure.h" 39 #include "chrome/browser/sync/util/closure.h"
41 #include "chrome/browser/sync/util/crypto_helpers.h" 40 #include "chrome/browser/sync/util/crypto_helpers.h"
42 #include "chrome/browser/sync/util/event_sys.h" 41 #include "chrome/browser/sync/util/event_sys.h"
43 #include "chrome/browser/sync/util/path_helpers.h" 42 #include "chrome/browser/sync/util/path_helpers.h"
44 #include "chrome/browser/sync/util/pthread_helpers.h" 43 #include "chrome/browser/sync/util/pthread_helpers.h"
45 #include "chrome/browser/sync/util/user_settings.h" 44 #include "chrome/browser/sync/util/user_settings.h"
46 #include "googleurl/src/gurl.h" 45 #include "googleurl/src/gurl.h"
47 46
47 #if defined(OS_WIN)
48 #pragma comment(lib, "iphlpapi.lib")
49 #endif
50
48 using browser_sync::AllStatus; 51 using browser_sync::AllStatus;
49 using browser_sync::AllStatusEvent; 52 using browser_sync::AllStatusEvent;
50 using browser_sync::AuthWatcher; 53 using browser_sync::AuthWatcher;
51 using browser_sync::AuthWatcherEvent; 54 using browser_sync::AuthWatcherEvent;
52 using browser_sync::ClientCommandChannel; 55 using browser_sync::ClientCommandChannel;
53 using browser_sync::Syncer; 56 using browser_sync::Syncer;
54 using browser_sync::SyncerEvent; 57 using browser_sync::SyncerEvent;
55 using browser_sync::SyncerStatus; 58 using browser_sync::SyncerStatus;
56 using browser_sync::SyncerThread; 59 using browser_sync::SyncerThread;
57 using browser_sync::SyncerThreadFactory; 60 using browser_sync::SyncerThreadFactory;
58 using browser_sync::UserSettings; 61 using browser_sync::UserSettings;
59 using browser_sync::TalkMediator; 62 using browser_sync::TalkMediator;
60 using browser_sync::TalkMediatorImpl; 63 using browser_sync::TalkMediatorImpl;
61 using std::list; 64 using std::list;
62 using std::hex; 65 using std::hex;
63 using std::string; 66 using std::string;
64 using std::vector; 67 using std::vector;
65 using syncable::Directory; 68 using syncable::Directory;
66 using syncable::DirectoryManager; 69 using syncable::DirectoryManager;
67 70
68 static const int kServerReachablePollingIntervalMsec = 60000 * 60; 71 static const int kServerReachablePollingIntervalMsec = 60000 * 60;
69 static const int kThreadExitTimeoutMsec = 60000; 72 static const int kThreadExitTimeoutMsec = 60000;
70 static const int kSSLPort = 443; 73 static const int kSSLPort = 443;
71 74
72 // We shouldn't call InitLogFiles more than once since that will cause a crash.
73 // So we use a global state variable to avoid that. This doesn't work in case
74 // of multiple threads, and if some other part also tries to call InitLogFiles
75 // apart from this file. But this is okay for now since this is the only place
76 // we call InitLogFiles.
77 namespace {
78 static bool g_log_files_initialized = false;
79 static base::AtExitManager g_at_exit_manager; // Necessary for NewCallback.
80 } // namespace
81
82 struct ThreadParams { 75 struct ThreadParams {
83 browser_sync::ServerConnectionManager* conn_mgr; 76 browser_sync::ServerConnectionManager* conn_mgr;
84 #if defined(OS_WIN) 77 #if defined(OS_WIN)
85 HANDLE exit_flag; 78 HANDLE exit_flag;
86 #endif 79 #endif
87 }; 80 };
88 81
89 // This thread calls CheckServerReachable() whenever a change occurs in the 82 // This thread calls CheckServerReachable() whenever a change occurs in the
90 // table that maps IP addresses to interfaces, for example when the user 83 // table that maps IP addresses to interfaces, for example when the user
91 // unplugs his network cable. 84 // unplugs his network cable.
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 const std::string& sync_server_and_path, 978 const std::string& sync_server_and_path,
986 int port, 979 int port,
987 const char* gaia_service_id, 980 const char* gaia_service_id,
988 const char* gaia_source, 981 const char* gaia_source,
989 bool use_ssl, HttpPostProviderFactory* post_factory, 982 bool use_ssl, HttpPostProviderFactory* post_factory,
990 HttpPostProviderFactory* auth_post_factory, 983 HttpPostProviderFactory* auth_post_factory,
991 ModelSafeWorkerInterface* model_safe_worker, 984 ModelSafeWorkerInterface* model_safe_worker,
992 bool attempt_last_user_authentication, 985 bool attempt_last_user_authentication,
993 const char* user_agent) { 986 const char* user_agent) {
994 987
995 if (!g_log_files_initialized) {
996 // TODO(timsteele): Call InitLogFiles() or equivalent.
997 g_log_files_initialized = true;
998 }
999
1000 // TODO(timsteele): We need to do this for syncapi.dll, but should remove
1001 // once we link statically. On windows this will set up the correct command
1002 // line, on posix it will be create an empty command line.
1003 CommandLine::Init(0, NULL);
1004
1005 // Set up UserSettings, creating the db if necessary. We need this to 988 // Set up UserSettings, creating the db if necessary. We need this to
1006 // instantiate a URLFactory to give to the Syncer. 989 // instantiate a URLFactory to give to the Syncer.
1007 PathString settings_db_file = AppendSlash(database_location) + 990 PathString settings_db_file = AppendSlash(database_location) +
1008 kBookmarkSyncUserSettingsDatabase; 991 kBookmarkSyncUserSettingsDatabase;
1009 user_settings_.reset(new UserSettings()); 992 user_settings_.reset(new UserSettings());
1010 if (!user_settings_->Init(settings_db_file)) 993 if (!user_settings_->Init(settings_db_file))
1011 return false; 994 return false;
1012 995
1013 share_.dir_manager.reset(new DirectoryManager(database_location)); 996 share_.dir_manager.reset(new DirectoryManager(database_location));
1014 997
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 // Stop the address watch thread by signaling the exit flag. 1205 // Stop the address watch thread by signaling the exit flag.
1223 // TODO(timsteele): Same as todo in Init(). 1206 // TODO(timsteele): Same as todo in Init().
1224 SetEvent(address_watch_params_.exit_flag); 1207 SetEvent(address_watch_params_.exit_flag);
1225 const DWORD wait_result = WaitForSingleObject(address_watch_thread_, 1208 const DWORD wait_result = WaitForSingleObject(address_watch_thread_,
1226 kThreadExitTimeoutMsec); 1209 kThreadExitTimeoutMsec);
1227 LOG_IF(ERROR, WAIT_FAILED == wait_result) << "Waiting for addr change thread " 1210 LOG_IF(ERROR, WAIT_FAILED == wait_result) << "Waiting for addr change thread "
1228 "to exit failed. GetLastError(): " << hex << GetLastError(); 1211 "to exit failed. GetLastError(): " << hex << GetLastError();
1229 LOG_IF(ERROR, WAIT_TIMEOUT == wait_result) << "Thread exit timeout expired"; 1212 LOG_IF(ERROR, WAIT_TIMEOUT == wait_result) << "Thread exit timeout expired";
1230 CloseHandle(address_watch_params_.exit_flag); 1213 CloseHandle(address_watch_params_.exit_flag);
1231 #endif 1214 #endif
1232
1233 CommandLine::Terminate();
1234 } 1215 }
1235 1216
1236 // Listen to model changes, filter out ones initiated by the sync API, and 1217 // Listen to model changes, filter out ones initiated by the sync API, and
1237 // saves the rest (hopefully just backend Syncer changes resulting from 1218 // saves the rest (hopefully just backend Syncer changes resulting from
1238 // ApplyUpdates) to data_->changelist. 1219 // ApplyUpdates) to data_->changelist.
1239 void SyncManager::SyncInternal::HandleChangeEvent( 1220 void SyncManager::SyncInternal::HandleChangeEvent(
1240 const syncable::DirectoryChangeEvent& event) { 1221 const syncable::DirectoryChangeEvent& event) {
1241 if (event.todo == syncable::DirectoryChangeEvent::TRANSACTION_COMPLETE) { 1222 if (event.todo == syncable::DirectoryChangeEvent::TRANSACTION_COMPLETE) {
1242 HandleTransactionCompleteChangeEvent(event); 1223 HandleTransactionCompleteChangeEvent(event);
1243 return; 1224 return;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 BaseTransaction::~BaseTransaction() { 1550 BaseTransaction::~BaseTransaction() {
1570 delete lookup_; 1551 delete lookup_;
1571 } 1552 }
1572 1553
1573 UserShare* SyncManager::GetUserShare() const { 1554 UserShare* SyncManager::GetUserShare() const {
1574 DCHECK(data_->initialized()) << "GetUserShare requires initialization!"; 1555 DCHECK(data_->initialized()) << "GetUserShare requires initialization!";
1575 return data_->GetUserShare(); 1556 return data_->GetUserShare();
1576 } 1557 }
1577 1558
1578 } // namespace sync_api 1559 } // namespace sync_api
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698