Chromium Code Reviews| Index: components/invalidation/impl/sync_system_resources.cc |
| diff --git a/components/invalidation/impl/sync_system_resources.cc b/components/invalidation/impl/sync_system_resources.cc |
| index 3cd65e74e0d0dbfb6d95fc93e73247a653a14109..d67276412e49c15d9a80e45dd6fa64e27cee733a 100644 |
| --- a/components/invalidation/impl/sync_system_resources.cc |
| +++ b/components/invalidation/impl/sync_system_resources.cc |
| @@ -4,6 +4,7 @@ |
| #include "components/invalidation/impl/sync_system_resources.h" |
| +#include <algorithm> |
| #include <cstdlib> |
| #include <cstring> |
| #include <string> |
| @@ -14,7 +15,6 @@ |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/single_thread_task_runner.h" |
| -#include "base/stl_util.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| @@ -93,7 +93,7 @@ void SyncInvalidationScheduler::Stop() { |
| is_stopped_ = true; |
| is_started_ = false; |
| weak_factory_.InvalidateWeakPtrs(); |
| - base::STLDeleteElements(&posted_tasks_); |
| + posted_tasks_.clear(); |
| } |
| void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay, |
| @@ -106,7 +106,7 @@ void SyncInvalidationScheduler::Schedule(invalidation::TimeDelta delay, |
| return; |
| } |
| - posted_tasks_.insert(task); |
| + posted_tasks_.insert(base::WrapUnique(task)); |
| base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| FROM_HERE, base::Bind(&SyncInvalidationScheduler::RunPostedTask, |
| weak_factory_.GetWeakPtr(), task), |
| @@ -130,8 +130,12 @@ void SyncInvalidationScheduler::SetSystemResources( |
| void SyncInvalidationScheduler::RunPostedTask(invalidation::Closure* task) { |
| CHECK(IsRunningOnThread()); |
| task->Run(); |
| - posted_tasks_.erase(task); |
| - delete task; |
| + auto it = |
| + std::find_if(posted_tasks_.begin(), posted_tasks_.end(), |
|
dcheng
2016/10/31 00:19:29
Part of me almost feels like we should just have a
Avi (use Gerrit)
2016/10/31 15:21:04
Acknowledged.
|
| + [task](const std::unique_ptr<invalidation::Closure>& ptr) { |
| + return ptr.get() == task; |
| + }); |
| + posted_tasks_.erase(it); |
| } |
| SyncNetworkChannel::SyncNetworkChannel() |
| @@ -139,7 +143,6 @@ SyncNetworkChannel::SyncNetworkChannel() |
| received_messages_count_(0) {} |
| SyncNetworkChannel::~SyncNetworkChannel() { |
| - base::STLDeleteElements(&network_status_receivers_); |
| } |
| void SyncNetworkChannel::SetMessageReceiver( |
| @@ -150,7 +153,8 @@ void SyncNetworkChannel::SetMessageReceiver( |
| void SyncNetworkChannel::AddNetworkStatusReceiver( |
| invalidation::NetworkStatusCallback* network_status_receiver) { |
| network_status_receiver->Run(last_network_status_); |
| - network_status_receivers_.push_back(network_status_receiver); |
| + network_status_receivers_.push_back( |
| + base::WrapUnique(network_status_receiver)); |
| } |
| void SyncNetworkChannel::SetSystemResources( |
| @@ -184,10 +188,8 @@ void SyncNetworkChannel::NotifyNetworkStatusChange(bool online) { |
| // Remember network state for future NetworkStatusReceivers. |
| last_network_status_ = online; |
| // Notify NetworkStatusReceivers in cacheinvalidation. |
| - for (NetworkStatusReceiverList::const_iterator it = |
| - network_status_receivers_.begin(); |
| - it != network_status_receivers_.end(); ++it) { |
| - (*it)->Run(online); |
| + for (const auto& receiver : network_status_receivers_) { |
| + receiver->Run(online); |
| } |
| } |
| @@ -230,7 +232,7 @@ void SyncStorage::WriteKey(const std::string& key, const std::string& value, |
| cached_state_ = value; |
| // According to the cache invalidation API folks, we can do this as |
| // long as we make sure to clear the persistent state that we start |
| - // up the cache invalidation client with. However, we musn't do it |
| + // up the cache invalidation client with. However, we mustn't do it |
| // right away, as we may be called under a lock that the callback |
| // uses. |
| scheduler_->Schedule( |