Define static members outside the template class.
When defining a static const member of a template class,
MyClass<T1>::some_static_member and MyClass<T2>::some_static_member
could be different values. We define these values inline in the class,
but ASan complains about an undefined reference.
Since those constants don't depend on the type, This patch moves them
to plain constants in the anonymous namespace.
Bug: chromium:611405
TEST=USE="clang asan" emerge-link update_engine
(cherry picked from commit 857ded125104a6e8dc7cabb3035a1fa42ccbd166)
Change-Id: Iee4d8d0b919f2a4707d13872f9602f88c9c9fabb
diff --git a/update_manager/real_system_provider.cc b/update_manager/real_system_provider.cc
index 294a947..fde6bfa 100644
--- a/update_manager/real_system_provider.cc
+++ b/update_manager/real_system_provider.cc
@@ -32,6 +32,13 @@
namespace {
+// The maximum number of consecutive failures before returning the default
+// constructor value for T instead of failure.
+const int kRetryPollVariableMaxRetry = 5;
+
+// The polling interval to be used whenever GetValue() returns an error.
+const int kRetryPollVariableRetryIntervalSeconds = 5 * 60;
+
// The RetryPollVariable variable is a polling variable that allows the function
// returning the value to fail a few times and shortens the polling rate when
// that happens.
@@ -44,7 +51,8 @@
: Variable<T>(name, poll_interval),
func_(func),
base_interval_(poll_interval) {
- DCHECK_LT(kRetryIntervalSeconds, base_interval_.InSeconds());
+ DCHECK_LT(kRetryPollVariableRetryIntervalSeconds,
+ base_interval_.InSeconds());
}
protected:
@@ -53,14 +61,14 @@
string* /* errmsg */) override {
std::unique_ptr<T> result(new T());
if (!func_.Run(result.get())) {
- if (failed_attempts_ >= kMaxRetry) {
+ if (failed_attempts_ >= kRetryPollVariableMaxRetry) {
// Give up on the retries, set back the desired polling interval and
// return the default.
this->SetPollInterval(base_interval_);
return result.release();
}
this->SetPollInterval(
- base::TimeDelta::FromSeconds(kRetryIntervalSeconds));
+ base::TimeDelta::FromSeconds(kRetryPollVariableRetryIntervalSeconds));
failed_attempts_++;
return nullptr;
}
@@ -79,13 +87,6 @@
// The number of consecutive failed attempts made.
int failed_attempts_ = 0;
- // The maximum number of consecutive failures before returning the default
- // constructor value for T instead of failure.
- static const int kMaxRetry = 5;
-
- // The polling interval to be used whenever GetValue() returns an error.
- static const int kRetryIntervalSeconds = 5 * 60;
-
DISALLOW_COPY_AND_ASSIGN(RetryPollVariable);
};