diff options
author | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 18:20:37 +0000 |
---|---|---|
committer | munjal@chromium.org <munjal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 18:20:37 +0000 |
commit | 01f42660659e45edd7c0a4ad8ecd7a6bb00e370e (patch) | |
tree | 3f41d81dce4744debf35d70898d24cbfa19dbbca /chrome/browser/sync | |
parent | c9d9b528c1b181f9b4bcf82947b10327b4759b2d (diff) | |
download | chromium_src-01f42660659e45edd7c0a4ad8ecd7a6bb00e370e.zip chromium_src-01f42660659e45edd7c0a4ad8ecd7a6bb00e370e.tar.gz chromium_src-01f42660659e45edd7c0a4ad8ecd7a6bb00e370e.tar.bz2 |
Part 1 of making sync work on Mac:
- Add high res timer class for mac (we might eventually replace all timer classes with Chrome ones)
- Define POSIX for OS==mac where needed
- Add new liens at the end of some files since otherwise they produce errors on Mac
- Rearrange initializer list of constructors to match declaration order in header; these become warning as error.
- Some chrome.gyp magic
At this point the code compiles but doesn't link due to some missing code on Mac like SSL stuff. But
I thought this was a good check point.
Note that chrome.gyp magic might change in future.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/255053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r-- | chrome/browser/sync/engine/sync_process_state.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/engine/sync_process_state.h | 6 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_pthreads.cc | 20 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_pthreads.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_timed_stop.cc | 2 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread_timed_stop.h | 2 | ||||
-rw-r--r-- | chrome/browser/sync/notifier/base/nethelpers.cc | 5 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/syncable.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/syncable.h | 13 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer.h | 2 | ||||
-rwxr-xr-x | chrome/browser/sync/util/highres_timer_mac.cc | 53 | ||||
-rw-r--r-- | chrome/browser/sync/util/highres_timer_mac.h | 69 | ||||
-rw-r--r-- | chrome/browser/sync/util/path_helpers_posix.cc | 4 |
14 files changed, 150 insertions, 36 deletions
diff --git a/chrome/browser/sync/engine/sync_process_state.cc b/chrome/browser/sync/engine/sync_process_state.cc index 34028a2..0171a19 100644 --- a/chrome/browser/sync/engine/sync_process_state.cc +++ b/chrome/browser/sync/engine/sync_process_state.cc @@ -38,13 +38,13 @@ SyncProcessState::SyncProcessState(syncable::DirectoryManager* dirman, SyncerEventChannel* syncer_event_channel, ModelSafeWorker* model_safe_worker) : num_sync_cycles_(0), - silenced_until_(0), connection_manager_(connection_manager), account_name_(account_name), dirman_(dirman), resolver_(resolver), model_safe_worker_(model_safe_worker), syncer_event_channel_(syncer_event_channel), + silenced_until_(0), error_rate_(0), current_sync_timestamp_(0), servers_latest_timestamp_(0), diff --git a/chrome/browser/sync/engine/sync_process_state.h b/chrome/browser/sync/engine/sync_process_state.h index 3fbcf89..9e0d2ff 100644 --- a/chrome/browser/sync/engine/sync_process_state.h +++ b/chrome/browser/sync/engine/sync_process_state.h @@ -291,13 +291,13 @@ class SyncProcessState { // For testing. SyncProcessState() : num_sync_cycles_(0), - silenced_until_(0), connection_manager_(NULL), account_name_(PSTR("")), dirman_(NULL), resolver_(NULL), model_safe_worker_(NULL), syncer_event_channel_(NULL), + silenced_until_(0), error_rate_(0), current_sync_timestamp_(0), servers_latest_timestamp_(0), @@ -316,6 +316,8 @@ class SyncProcessState { auth_dirty_(false), auth_failed_(false) {} + int num_sync_cycles_; + ServerConnectionManager* connection_manager_; const PathString account_name_; syncable::DirectoryManager* const dirman_; @@ -332,8 +334,6 @@ class SyncProcessState { std::map<syncable::Id, ConflictSet*> id_to_conflict_set_; std::set<ConflictSet*> conflict_sets_; - int num_sync_cycles_; - // When we're over bandwidth quota, we don't update until past this time. time_t silenced_until_; diff --git a/chrome/browser/sync/engine/syncer_thread.h b/chrome/browser/sync/engine/syncer_thread.h index 4d1ae95..e699b49 100644 --- a/chrome/browser/sync/engine/syncer_thread.h +++ b/chrome/browser/sync/engine/syncer_thread.h @@ -282,4 +282,4 @@ public: } // namespace browser_sync -#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_
\ No newline at end of file +#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_H_ diff --git a/chrome/browser/sync/engine/syncer_thread_pthreads.cc b/chrome/browser/sync/engine/syncer_thread_pthreads.cc index 9fdfb21..4088694 100644 --- a/chrome/browser/sync/engine/syncer_thread_pthreads.cc +++ b/chrome/browser/sync/engine/syncer_thread_pthreads.cc @@ -138,20 +138,24 @@ SyncerThreadPthreadImpl::SyncerThreadPthreadImpl( ServerConnectionManager* connection_manager, AllStatus* all_status, ModelSafeWorker* model_safe_worker) - : dirman_(mgr), scm_(connection_manager), - syncer_(NULL), syncer_events_(NULL), thread_running_(false), + : stop_syncer_thread_(false), + thread_running_(false), + connected_(false), + p2p_authenticated_(false), + p2p_subscribed_(false), + allstatus_(all_status), + syncer_(NULL), + dirman_(mgr), + scm_(connection_manager), syncer_short_poll_interval_seconds_( SyncerThread::kDefaultShortPollIntervalSeconds), syncer_long_poll_interval_seconds_( SyncerThread::kDefaultLongPollIntervalSeconds), syncer_polling_interval_(SyncerThread::kDefaultShortPollIntervalSeconds), syncer_max_interval_(SyncerThread::kDefaultMaxPollIntervalMs), - stop_syncer_thread_(false), connected_(false), conn_mgr_hookup_(NULL), - p2p_authenticated_(false), p2p_subscribed_(false), - allstatus_(all_status), talk_mediator_hookup_(NULL), - command_channel_(command_channel), directory_manager_hookup_(NULL), + command_channel_(command_channel), model_safe_worker_(model_safe_worker), - client_command_hookup_(NULL), disable_idle_detection_(false) { + disable_idle_detection_(false) { SyncerEvent shutdown = { SyncerEvent::SHUTDOWN_USE_WITH_CARE }; syncer_event_channel_.reset(new SyncerEventChannel(shutdown)); @@ -575,4 +579,4 @@ void SyncerThreadPthreadImpl::HandleTalkMediatorEvent( } } -} // namespace browser_sync
\ No newline at end of file +} // namespace browser_sync diff --git a/chrome/browser/sync/engine/syncer_thread_pthreads.h b/chrome/browser/sync/engine/syncer_thread_pthreads.h index bebd8ed..fb70982 100644 --- a/chrome/browser/sync/engine/syncer_thread_pthreads.h +++ b/chrome/browser/sync/engine/syncer_thread_pthreads.h @@ -281,4 +281,4 @@ class SyncerThreadPthreads : public SyncerThread { } // namespace browser_sync -#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_PTHREADS_H_
\ No newline at end of file +#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_PTHREADS_H_ diff --git a/chrome/browser/sync/engine/syncer_thread_timed_stop.cc b/chrome/browser/sync/engine/syncer_thread_timed_stop.cc index a396dd0..2ae8cd5 100644 --- a/chrome/browser/sync/engine/syncer_thread_timed_stop.cc +++ b/chrome/browser/sync/engine/syncer_thread_timed_stop.cc @@ -116,4 +116,4 @@ void SyncerThreadTimedStop::ThreadMain() { LOG(INFO) << "Syncer thread ThreadMain is done."; } -} // namespace browser_sync
\ No newline at end of file +} // namespace browser_sync diff --git a/chrome/browser/sync/engine/syncer_thread_timed_stop.h b/chrome/browser/sync/engine/syncer_thread_timed_stop.h index e1037a1..e9b260a 100644 --- a/chrome/browser/sync/engine/syncer_thread_timed_stop.h +++ b/chrome/browser/sync/engine/syncer_thread_timed_stop.h @@ -50,4 +50,4 @@ class SyncerThreadTimedStop : public SyncerThread { } // namespace browser_sync -#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_TIMED_STOP_H_
\ No newline at end of file +#endif // CHROME_BROWSER_SYNC_ENGINE_SYNCER_THREAD_TIMED_STOP_H_ diff --git a/chrome/browser/sync/notifier/base/nethelpers.cc b/chrome/browser/sync/notifier/base/nethelpers.cc index 23fc8d2..e342479 100644 --- a/chrome/browser/sync/notifier/base/nethelpers.cc +++ b/chrome/browser/sync/notifier/base/nethelpers.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "build/build_config.h" #include "chrome/browser/sync/notifier/base/nethelpers.h" namespace notifier { @@ -17,7 +18,7 @@ hostent* SafeGetHostByName(const char* hostname, hostent* host, } #elif OS_LINUX gethostbyname_r(hostname, host, buffer, buffer_len, &result, herrno); -#elif OSX +#elif OS_MACOSX result = getipnodebyname(hostname, AF_INET, AI_DEFAULT, herrno); #else #error "I don't know how to do gethostbyname safely on your system." @@ -32,7 +33,7 @@ void FreeHostEnt(hostent* host) { // No need to free anything, struct returned is static memory. #elif OS_LINUX // No need to free anything, we pass in a pointer to a struct. -#elif OSX +#elif OS_MACOSX freehostent(host); #else #error "I don't know how to free a hostent on your system." diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc index e8373a88..aa4832e 100644 --- a/chrome/browser/sync/syncable/syncable.cc +++ b/chrome/browser/sync/syncable/syncable.cc @@ -7,7 +7,7 @@ #include "build/build_config.h" #include <sys/stat.h> -#ifdef OS_LINUX +#ifdef OS_POSIX #include <sys/time.h> #endif #include <sys/types.h> @@ -1870,4 +1870,4 @@ FastDump& operator<<(FastDump& dump, const syncable::Blob& blob) { string buffer(HexEncode(&blob[0], blob.size())); dump.out_->sputn(buffer.c_str(), buffer.size()); return dump; -}
\ No newline at end of file +} diff --git a/chrome/browser/sync/syncable/syncable.h b/chrome/browser/sync/syncable/syncable.h index 9af42f2..086d169 100644 --- a/chrome/browser/sync/syncable/syncable.h +++ b/chrome/browser/sync/syncable/syncable.h @@ -301,19 +301,6 @@ class SyncName { const PathString& non_unique_sync_name) : value_(unique_sync_name), non_unique_value_(non_unique_sync_name) { } -#ifdef OS_MACOSX - // Translate [':' -> '/'] within the sync name. Used on OSX. - void ConvertColonsToSlashes() { - DCHECK_EQ(value_, non_unique_value_) - << "Deriving value_ will overwrite non_unique_value_."; - std::string temporary_copy; - temporary_copy.reserve(value_.size()); - StringReplace(value_, ":", "/", true, &temporary_copy); - value_.swap(temporary_copy); - non_unique_value_ = value_; - } -#endif - // Transform |value_| so that it's a legal server name. void MakeServerLegal() { DCHECK_EQ(value_, non_unique_value_) diff --git a/chrome/browser/sync/util/highres_timer.h b/chrome/browser/sync/util/highres_timer.h index 138da04..2c6513d 100644 --- a/chrome/browser/sync/util/highres_timer.h +++ b/chrome/browser/sync/util/highres_timer.h @@ -9,7 +9,7 @@ #if defined(OS_WIN) #include "chrome/browser/sync/util/highres_timer_win.h" #elif defined(OS_MACOSX) -#error "Mac timer functions are missing." +#include "chrome/browser/sync/util/highres_timer_mac.h" #else #include "chrome/browser/sync/util/highres_timer_linux.h" #endif diff --git a/chrome/browser/sync/util/highres_timer_mac.cc b/chrome/browser/sync/util/highres_timer_mac.cc new file mode 100755 index 0000000..faad058 --- /dev/null +++ b/chrome/browser/sync/util/highres_timer_mac.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// High resolution timer functions for use on Mac OS. + +#include "chrome/browser/sync/util/highres_timer.h" + +bool HighresTimer::perf_ratio_collected_ = false; +mach_timebase_info_data_t HighresTimer::perf_ratio_ = {0}; + +static const uint64 kNanosInMilli = 1000000L; +static const uint64 kNanosInHalfMilli = 500000L; +static const uint64 kNanosInSecond = 1000000000L; +static const uint64 kNanosInHalfSecond = 500000000L; + +uint64 HighresTimer::GetElapsedMs() const { + uint64 end_time = GetCurrentTicks(); + + // Scale to ms and round to nearest ms - rounding is important + // because otherwise the truncation error may accumulate e.g. in sums. + // + GetTimerFrequency(); + return ((end_time - start_ticks_) * perf_ratio_.numer + + kNanosInHalfMilli * perf_ratio_.denom) / + (kNanosInMilli * perf_ratio_.denom); +} + +uint64 HighresTimer::GetElapsedSec() const { + uint64 end_time = GetCurrentTicks(); + + // Scale to ms and round to nearest ms - rounding is important + // because otherwise the truncation error may accumulate e.g. in sums. + // + GetTimerFrequency(); + return ((end_time - start_ticks_) * perf_ratio_.numer + + kNanosInHalfSecond * perf_ratio_.denom) / + (kNanosInSecond * perf_ratio_.denom); +} + +void HighresTimer::CollectPerfRatio() { + mach_timebase_info(&perf_ratio_); + perf_ratio_collected_ = true; +} + +uint64 HighresTimer::GetTimerFrequency() { + if (!perf_ratio_collected_) + CollectPerfRatio(); + // we're losing precision by doing the division here, but this value is only + // used to estimate tick time by the unit tests, so we're ok. + return static_cast<uint64>( + perf_ratio_.denom * 1000000000ULL / perf_ratio_.numer); +} diff --git a/chrome/browser/sync/util/highres_timer_mac.h b/chrome/browser/sync/util/highres_timer_mac.h new file mode 100644 index 0000000..3a35622 --- /dev/null +++ b/chrome/browser/sync/util/highres_timer_mac.h @@ -0,0 +1,69 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// High resolution timer functions for use on Mac OS. + +#ifndef CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_MAC_H_ +#define CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_MAC_H_ + +#include <mach/mach.h> +#include <mach/mach_time.h> + +#include "base/basictypes.h" + +// A handy class for reliably measuring wall-clock time with decent resolution. +class HighresTimer { + public: + // Captures the current start time + HighresTimer(); + + // Captures the current tick, can be used to reset a timer for reuse. + void Start(); + + // Returns the elapsed ticks with full resolution. + uint64 GetElapsedTicks() const; + + // Returns the elapsed time in milliseconds, rounded to the nearest + // millisecond. + uint64 GetElapsedMs() const; + + // Returns the elapsed time in seconds, rounded to the nearest second. + uint64 GetElapsedSec() const; + + uint64 start_ticks() const { return start_ticks_; } + + // Returns timer frequency from cache, should be less overhead than + // ::QueryPerformanceFrequency. + static uint64 GetTimerFrequency(); + // Returns current ticks. + static uint64 GetCurrentTicks(); + + private: + static void CollectPerfRatio(); + + // Captured start time. + uint64 start_ticks_; + + // Captured performance counter frequency. + static bool perf_ratio_collected_; + static mach_timebase_info_data_t perf_ratio_; +}; + +inline HighresTimer::HighresTimer() { + Start(); +} + +inline void HighresTimer::Start() { + start_ticks_ = GetCurrentTicks(); +} + +inline uint64 HighresTimer::GetCurrentTicks() { + return mach_absolute_time(); +} + +inline uint64 HighresTimer::GetElapsedTicks() const { + return start_ticks_ - GetCurrentTicks(); +} + +#endif // CHROME_BROWSER_SYNC_UTIL_HIGHRES_TIMER_MAC_H_ diff --git a/chrome/browser/sync/util/path_helpers_posix.cc b/chrome/browser/sync/util/path_helpers_posix.cc index 5c68177..9da1adb 100644 --- a/chrome/browser/sync/util/path_helpers_posix.cc +++ b/chrome/browser/sync/util/path_helpers_posix.cc @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <algorithm> #include <pwd.h> #include <string.h> -#include "chrome/browser/sync/notifier/base/string.h" #include "chrome/browser/sync/util/path_helpers.h" #if ((!defined(OS_LINUX)) && (!defined(OS_MACOSX))) @@ -91,6 +91,6 @@ PathString MakePathComponentOSLegal(const PathString& component) { if (PathString::npos == component.find("/")) return PSTR(""); PathString new_name(component); - notifier::StringReplace(&new_name, "/", ":", true); + std::replace(new_name.begin(), new_name.end(), '/', ':'); return new_name; } |