Commit e610b2a6 authored by avi's avatar avi Committed by Commit bot

Remove some uses of stl_util's STLDeleteContainerPointers.

BUG=555865

Review-Url: https://codereview.chromium.org/2314833002
Cr-Commit-Position: refs/heads/master@{#419253}
parent 89e88e32
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/safe_browsing/permission_reporter.h" #include "chrome/browser/safe_browsing/permission_reporter.h"
...@@ -74,9 +73,6 @@ SafeBrowsingPingManager::SafeBrowsingPingManager( ...@@ -74,9 +73,6 @@ SafeBrowsingPingManager::SafeBrowsingPingManager(
} }
SafeBrowsingPingManager::~SafeBrowsingPingManager() { SafeBrowsingPingManager::~SafeBrowsingPingManager() {
// Delete in-progress safebrowsing reports (hits and details).
base::STLDeleteContainerPointers(safebrowsing_reports_.begin(),
safebrowsing_reports_.end());
} }
// net::URLFetcherDelegate implementation ---------------------------------- // net::URLFetcherDelegate implementation ----------------------------------
...@@ -84,43 +80,44 @@ SafeBrowsingPingManager::~SafeBrowsingPingManager() { ...@@ -84,43 +80,44 @@ SafeBrowsingPingManager::~SafeBrowsingPingManager() {
// All SafeBrowsing request responses are handled here. // All SafeBrowsing request responses are handled here.
void SafeBrowsingPingManager::OnURLFetchComplete( void SafeBrowsingPingManager::OnURLFetchComplete(
const net::URLFetcher* source) { const net::URLFetcher* source) {
Reports::iterator sit = safebrowsing_reports_.find(source); auto it =
DCHECK(sit != safebrowsing_reports_.end()); std::find_if(safebrowsing_reports_.begin(), safebrowsing_reports_.end(),
delete *sit; [source](const std::unique_ptr<net::URLFetcher>& ptr) {
safebrowsing_reports_.erase(sit); return ptr.get() == source;
});
DCHECK(it != safebrowsing_reports_.end());
safebrowsing_reports_.erase(it);
} }
// Sends a SafeBrowsing "hit" report. // Sends a SafeBrowsing "hit" report.
void SafeBrowsingPingManager::ReportSafeBrowsingHit( void SafeBrowsingPingManager::ReportSafeBrowsingHit(
const safe_browsing::HitReport& hit_report) { const safe_browsing::HitReport& hit_report) {
GURL report_url = SafeBrowsingHitUrl(hit_report); GURL report_url = SafeBrowsingHitUrl(hit_report);
net::URLFetcher* report = std::unique_ptr<net::URLFetcher> report_ptr = net::URLFetcher::Create(
net::URLFetcher::Create(report_url, hit_report.post_data.empty() report_url, hit_report.post_data.empty() ? net::URLFetcher::GET
? net::URLFetcher::GET : net::URLFetcher::POST,
: net::URLFetcher::POST, this);
this) net::URLFetcher* report = report_ptr.get();
.release(); report_ptr->SetLoadFlags(net::LOAD_DISABLE_CACHE);
report->SetLoadFlags(net::LOAD_DISABLE_CACHE); report_ptr->SetRequestContext(request_context_getter_.get());
report->SetRequestContext(request_context_getter_.get());
if (!hit_report.post_data.empty()) if (!hit_report.post_data.empty())
report->SetUploadData("text/plain", hit_report.post_data); report_ptr->SetUploadData("text/plain", hit_report.post_data);
safebrowsing_reports_.insert(report); safebrowsing_reports_.insert(std::move(report_ptr));
report->Start(); report->Start();
} }
// Sends threat details for users who opt-in. // Sends threat details for users who opt-in.
void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) { void SafeBrowsingPingManager::ReportThreatDetails(const std::string& report) {
GURL report_url = ThreatDetailsUrl(); GURL report_url = ThreatDetailsUrl();
net::URLFetcher* fetcher = std::unique_ptr<net::URLFetcher> fetcher =
net::URLFetcher::Create(report_url, net::URLFetcher::POST, this) net::URLFetcher::Create(report_url, net::URLFetcher::POST, this);
.release();
fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE); fetcher->SetLoadFlags(net::LOAD_DISABLE_CACHE);
fetcher->SetRequestContext(request_context_getter_.get()); fetcher->SetRequestContext(request_context_getter_.get());
fetcher->SetUploadData("application/octet-stream", report); fetcher->SetUploadData("application/octet-stream", report);
// Don't try too hard to send reports on failures. // Don't try too hard to send reports on failures.
fetcher->SetAutomaticallyRetryOn5xx(false); fetcher->SetAutomaticallyRetryOn5xx(false);
fetcher->Start(); fetcher->Start();
safebrowsing_reports_.insert(fetcher); safebrowsing_reports_.insert(std::move(fetcher));
} }
void SafeBrowsingPingManager::ReportInvalidCertificateChain( void SafeBrowsingPingManager::ReportInvalidCertificateChain(
......
...@@ -73,7 +73,7 @@ class SafeBrowsingPingManager : public net::URLFetcherDelegate { ...@@ -73,7 +73,7 @@ class SafeBrowsingPingManager : public net::URLFetcherDelegate {
TestSafeBrowsingHitUrl); TestSafeBrowsingHitUrl);
FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, TestThreatDetailsUrl); FRIEND_TEST_ALL_PREFIXES(SafeBrowsingPingManagerTest, TestThreatDetailsUrl);
typedef std::set<const net::URLFetcher*> Reports; typedef std::set<std::unique_ptr<net::URLFetcher>> Reports;
// Constructs a SafeBrowsingPingManager that issues network requests // Constructs a SafeBrowsingPingManager that issues network requests
// using |request_context_getter|. // using |request_context_getter|.
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <stddef.h> #include <stddef.h>
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/stl_util.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
namespace sync_file_system { namespace sync_file_system {
...@@ -42,18 +41,16 @@ void TaskLogger::RecordLog(std::unique_ptr<TaskLog> log) { ...@@ -42,18 +41,16 @@ void TaskLogger::RecordLog(std::unique_ptr<TaskLog> log) {
return; return;
if (log_history_.size() >= kMaxLogSize) { if (log_history_.size() >= kMaxLogSize) {
delete log_history_.front();
log_history_.pop_front(); log_history_.pop_front();
} }
log_history_.push_back(log.release()); log_history_.push_back(std::move(log));
FOR_EACH_OBSERVER(Observer, observers_, FOR_EACH_OBSERVER(Observer, observers_,
OnLogRecorded(*log_history_.back())); OnLogRecorded(*log_history_.back()));
} }
void TaskLogger::ClearLog() { void TaskLogger::ClearLog() {
base::STLDeleteContainerPointers(log_history_.begin(), log_history_.end());
log_history_.clear(); log_history_.clear();
} }
......
...@@ -31,7 +31,7 @@ class TaskLogger : public base::SupportsWeakPtr<TaskLogger> { ...@@ -31,7 +31,7 @@ class TaskLogger : public base::SupportsWeakPtr<TaskLogger> {
~TaskLog(); ~TaskLog();
}; };
typedef std::deque<TaskLog*> LogList; using LogList = std::deque<std::unique_ptr<TaskLog>>;
class Observer { class Observer {
public: public:
...@@ -57,7 +57,7 @@ class TaskLogger : public base::SupportsWeakPtr<TaskLogger> { ...@@ -57,7 +57,7 @@ class TaskLogger : public base::SupportsWeakPtr<TaskLogger> {
const LogList& GetLog() const; const LogList& GetLog() const;
private: private:
std::deque<TaskLog*> log_history_; LogList log_history_;
base::ObserverList<Observer> observers_; base::ObserverList<Observer> observers_;
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#include "base/callback_helpers.h" #include "base/callback_helpers.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/values.h" #include "base/values.h"
#include "components/safe_json/safe_json_parser.h" #include "components/safe_json/safe_json_parser.h"
...@@ -397,8 +397,6 @@ LogProofFetcher::LogProofFetcher(net::URLRequestContext* request_context) ...@@ -397,8 +397,6 @@ LogProofFetcher::LogProofFetcher(net::URLRequestContext* request_context)
} }
LogProofFetcher::~LogProofFetcher() { LogProofFetcher::~LogProofFetcher() {
base::STLDeleteContainerPointers(inflight_fetches_.begin(),
inflight_fetches_.end());
} }
void LogProofFetcher::FetchSignedTreeHead( void LogProofFetcher::FetchSignedTreeHead(
...@@ -407,8 +405,8 @@ void LogProofFetcher::FetchSignedTreeHead( ...@@ -407,8 +405,8 @@ void LogProofFetcher::FetchSignedTreeHead(
const SignedTreeHeadFetchedCallback& fetched_callback, const SignedTreeHeadFetchedCallback& fetched_callback,
const FetchFailedCallback& failed_callback) { const FetchFailedCallback& failed_callback) {
GURL request_url = base_log_url.Resolve("ct/v1/get-sth"); GURL request_url = base_log_url.Resolve("ct/v1/get-sth");
StartFetch(request_url, new GetSTHLogResponseHandler(log_id, fetched_callback, StartFetch(request_url, base::MakeUnique<GetSTHLogResponseHandler>(
failed_callback)); log_id, fetched_callback, failed_callback));
} }
void LogProofFetcher::FetchConsistencyProof( void LogProofFetcher::FetchConsistencyProof(
...@@ -421,24 +419,30 @@ void LogProofFetcher::FetchConsistencyProof( ...@@ -421,24 +419,30 @@ void LogProofFetcher::FetchConsistencyProof(
GURL request_url = base_log_url.Resolve(base::StringPrintf( GURL request_url = base_log_url.Resolve(base::StringPrintf(
"ct/v1/get-sth-consistency?first=%" PRIu64 "&second=%" PRIu64, "ct/v1/get-sth-consistency?first=%" PRIu64 "&second=%" PRIu64,
old_tree_size, new_tree_size)); old_tree_size, new_tree_size));
StartFetch(request_url, new GetConsistencyProofLogResponseHandler( StartFetch(request_url,
log_id, fetched_callback, failed_callback)); base::MakeUnique<GetConsistencyProofLogResponseHandler>(
log_id, fetched_callback, failed_callback));
} }
void LogProofFetcher::StartFetch(const GURL& request_url, void LogProofFetcher::StartFetch(
LogResponseHandler* log_request) { const GURL& request_url,
log_request->StartFetch(request_context_, request_url, std::unique_ptr<LogResponseHandler> log_request) {
base::Bind(&LogProofFetcher::OnFetchDone, log_request->StartFetch(
weak_factory_.GetWeakPtr(), log_request)); request_context_, request_url,
inflight_fetches_.insert(log_request); base::Bind(&LogProofFetcher::OnFetchDone, weak_factory_.GetWeakPtr(),
log_request.get()));
inflight_fetches_.insert(std::move(log_request));
} }
void LogProofFetcher::OnFetchDone(LogResponseHandler* log_handler, void LogProofFetcher::OnFetchDone(LogResponseHandler* log_handler,
const base::Closure& requestor_callback) { const base::Closure& requestor_callback) {
auto it = inflight_fetches_.find(log_handler); auto it = std::find_if(
inflight_fetches_.begin(), inflight_fetches_.end(),
[log_handler](const std::unique_ptr<LogResponseHandler>& ptr) {
return ptr.get() == log_handler;
});
DCHECK(it != inflight_fetches_.end()); DCHECK(it != inflight_fetches_.end());
delete *it;
inflight_fetches_.erase(it); inflight_fetches_.erase(it);
requestor_callback.Run(); requestor_callback.Run();
} }
......
...@@ -108,7 +108,8 @@ class LogProofFetcher { ...@@ -108,7 +108,8 @@ class LogProofFetcher {
// Starts the fetch (by delegating to the LogResponseHandler) // Starts the fetch (by delegating to the LogResponseHandler)
// and stores the |log_handler| in |inflight_fetches_| for later // and stores the |log_handler| in |inflight_fetches_| for later
// cleanup. // cleanup.
void StartFetch(const GURL& request_url, LogResponseHandler* log_handler); void StartFetch(const GURL& request_url,
std::unique_ptr<LogResponseHandler> log_request);
// Callback for when the fetch was done (successfully or not). // Callback for when the fetch was done (successfully or not).
// Deletes, and removes, the |log_handler| from the |inflight_fetches_|. // Deletes, and removes, the |log_handler| from the |inflight_fetches_|.
...@@ -120,7 +121,7 @@ class LogProofFetcher { ...@@ -120,7 +121,7 @@ class LogProofFetcher {
net::URLRequestContext* const request_context_; net::URLRequestContext* const request_context_;
std::set<LogResponseHandler*> inflight_fetches_; std::set<std::unique_ptr<LogResponseHandler>> inflight_fetches_;
base::WeakPtrFactory<LogProofFetcher> weak_factory_; base::WeakPtrFactory<LogProofFetcher> weak_factory_;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -219,8 +220,6 @@ HistoryBackend::HistoryBackend( ...@@ -219,8 +220,6 @@ HistoryBackend::HistoryBackend(
HistoryBackend::~HistoryBackend() { HistoryBackend::~HistoryBackend() {
DCHECK(!scheduled_commit_) << "Deleting without cleanup"; DCHECK(!scheduled_commit_) << "Deleting without cleanup";
base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(),
queued_history_db_tasks_.end());
queued_history_db_tasks_.clear(); queued_history_db_tasks_.clear();
// Release stashed embedder object before cleaning up the databases. // Release stashed embedder object before cleaning up the databases.
...@@ -2263,26 +2262,24 @@ void HistoryBackend::CancelScheduledCommit() { ...@@ -2263,26 +2262,24 @@ void HistoryBackend::CancelScheduledCommit() {
void HistoryBackend::ProcessDBTaskImpl() { void HistoryBackend::ProcessDBTaskImpl() {
if (!db_) { if (!db_) {
// db went away, release all the refs. // db went away, release all the refs.
base::STLDeleteContainerPointers(queued_history_db_tasks_.begin(),
queued_history_db_tasks_.end());
queued_history_db_tasks_.clear(); queued_history_db_tasks_.clear();
return; return;
} }
// Remove any canceled tasks. // Remove any canceled tasks.
while (!queued_history_db_tasks_.empty()) { while (!queued_history_db_tasks_.empty()) {
QueuedHistoryDBTask* task = queued_history_db_tasks_.front(); QueuedHistoryDBTask* task = queued_history_db_tasks_.front().get();
if (!task->is_canceled()) if (!task->is_canceled())
break; break;
delete task;
queued_history_db_tasks_.pop_front(); queued_history_db_tasks_.pop_front();
} }
if (queued_history_db_tasks_.empty()) if (queued_history_db_tasks_.empty())
return; return;
// Run the first task. // Run the first task.
std::unique_ptr<QueuedHistoryDBTask> task(queued_history_db_tasks_.front()); std::unique_ptr<QueuedHistoryDBTask> task =
std::move(queued_history_db_tasks_.front());
queued_history_db_tasks_.pop_front(); queued_history_db_tasks_.pop_front();
if (task->Run(this, db_.get())) { if (task->Run(this, db_.get())) {
// The task is done, notify the callback. // The task is done, notify the callback.
...@@ -2290,7 +2287,7 @@ void HistoryBackend::ProcessDBTaskImpl() { ...@@ -2290,7 +2287,7 @@ void HistoryBackend::ProcessDBTaskImpl() {
} else { } else {
// The task wants to run some more. Schedule it at the end of the current // The task wants to run some more. Schedule it at the end of the current
// tasks, and process it after an invoke later. // tasks, and process it after an invoke later.
queued_history_db_tasks_.push_back(task.release()); queued_history_db_tasks_.push_back(std::move(task));
task_runner_->PostTask( task_runner_->PostTask(
FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this)); FROM_HERE, base::Bind(&HistoryBackend::ProcessDBTaskImpl, this));
} }
...@@ -2485,8 +2482,8 @@ void HistoryBackend::ProcessDBTask( ...@@ -2485,8 +2482,8 @@ void HistoryBackend::ProcessDBTask(
scoped_refptr<base::SingleThreadTaskRunner> origin_loop, scoped_refptr<base::SingleThreadTaskRunner> origin_loop,
const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) {
bool scheduled = !queued_history_db_tasks_.empty(); bool scheduled = !queued_history_db_tasks_.empty();
queued_history_db_tasks_.push_back( queued_history_db_tasks_.push_back(base::MakeUnique<QueuedHistoryDBTask>(
new QueuedHistoryDBTask(std::move(task), origin_loop, is_canceled)); std::move(task), origin_loop, is_canceled));
if (!scheduled) if (!scheduled)
ProcessDBTaskImpl(); ProcessDBTaskImpl();
} }
......
...@@ -863,7 +863,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>, ...@@ -863,7 +863,7 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
bool segment_queried_; bool segment_queried_;
// List of QueuedHistoryDBTasks to run; // List of QueuedHistoryDBTasks to run;
std::list<QueuedHistoryDBTask*> queued_history_db_tasks_; std::list<std::unique_ptr<QueuedHistoryDBTask>> queued_history_db_tasks_;
// Used to determine if a URL is bookmarked; may be null. // Used to determine if a URL is bookmarked; may be null.
std::unique_ptr<HistoryBackendClient> backend_client_; std::unique_ptr<HistoryBackendClient> backend_client_;
......
...@@ -3047,8 +3047,8 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3047,8 +3047,8 @@ class AppCacheUpdateJobTest : public testing::Test,
// Clean up everything that was created on the IO thread. // Clean up everything that was created on the IO thread.
protect_newest_cache_ = NULL; protect_newest_cache_ = NULL;
group_ = NULL; group_ = NULL;
base::STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); hosts_.clear();
base::STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); frontends_.clear();
response_infos_.clear(); response_infos_.clear();
service_.reset(NULL); service_.reset(NULL);
...@@ -3087,9 +3087,9 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3087,9 +3087,9 @@ class AppCacheUpdateJobTest : public testing::Test,
} }
AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) {
AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); hosts_.push_back(
hosts_.push_back(host); base::MakeUnique<AppCacheHost>(host_id, frontend, service_.get()));
return host; return hosts_.back().get();
} }
AppCacheResponseInfo* MakeAppCacheResponseInfo( AppCacheResponseInfo* MakeAppCacheResponseInfo(
...@@ -3106,9 +3106,8 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3106,9 +3106,8 @@ class AppCacheUpdateJobTest : public testing::Test,
} }
MockFrontend* MakeMockFrontend() { MockFrontend* MakeMockFrontend() {
MockFrontend* frontend = new MockFrontend(); frontends_.push_back(base::MakeUnique<MockFrontend>());
frontends_.push_back(frontend); return frontends_.back().get();
return frontend;
} }
// Verifies conditions about the group and notifications after an update // Verifies conditions about the group and notifications after an update
...@@ -3193,7 +3192,7 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3193,7 +3192,7 @@ class AppCacheUpdateJobTest : public testing::Test,
// Check expected events. // Check expected events.
for (size_t i = 0; i < frontends_.size(); ++i) { for (size_t i = 0; i < frontends_.size(); ++i) {
MockFrontend* frontend = frontends_[i]; MockFrontend* frontend = frontends_[i].get();
MockFrontend::RaisedEvents& expected_events = frontend->expected_events_; MockFrontend::RaisedEvents& expected_events = frontend->expected_events_;
MockFrontend::RaisedEvents& actual_events = frontend->raised_events_; MockFrontend::RaisedEvents& actual_events = frontend->raised_events_;
...@@ -3430,7 +3429,7 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3430,7 +3429,7 @@ class AppCacheUpdateJobTest : public testing::Test,
// Hosts used by an async test that need to live until update job finishes. // Hosts used by an async test that need to live until update job finishes.
// Otherwise, test can put host on the stack instead of here. // Otherwise, test can put host on the stack instead of here.
std::vector<AppCacheHost*> hosts_; std::vector<std::unique_ptr<AppCacheHost>> hosts_;
// Response infos used by an async test that need to live until update job // Response infos used by an async test that need to live until update job
// finishes. // finishes.
...@@ -3448,7 +3447,8 @@ class AppCacheUpdateJobTest : public testing::Test, ...@@ -3448,7 +3447,8 @@ class AppCacheUpdateJobTest : public testing::Test,
AppCache* expect_old_cache_; AppCache* expect_old_cache_;
AppCache* expect_newest_cache_; AppCache* expect_newest_cache_;
bool expect_non_null_update_time_; bool expect_non_null_update_time_;
std::vector<MockFrontend*> frontends_; // to check expected events std::vector<std::unique_ptr<MockFrontend>>
frontends_; // to check expected events
TestedManifest tested_manifest_; TestedManifest tested_manifest_;
const char* tested_manifest_path_override_; const char* tested_manifest_path_override_;
AppCache::EntryMap expect_extra_entries_; AppCache::EntryMap expect_extra_entries_;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/sparse_histogram.h" #include "base/metrics/sparse_histogram.h"
#include "base/stl_util.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/display_compositor/gl_helper.h" #include "components/display_compositor/gl_helper.h"
#include "content/browser/renderer_host/media/media_stream_manager.h" #include "content/browser/renderer_host/media/media_stream_manager.h"
...@@ -192,12 +191,12 @@ void VideoCaptureController::AddClient( ...@@ -192,12 +191,12 @@ void VideoCaptureController::AddClient(
if (FindClient(id, event_handler, controller_clients_)) if (FindClient(id, event_handler, controller_clients_))
return; return;
ControllerClient* client = new ControllerClient( std::unique_ptr<ControllerClient> client = base::MakeUnique<ControllerClient>(
id, event_handler, render_process, session_id, params); id, event_handler, render_process, session_id, params);
// If we already have gotten frame_info from the device, repeat it to the new // If we already have gotten frame_info from the device, repeat it to the new
// client. // client.
if (state_ == VIDEO_CAPTURE_STATE_STARTED) { if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
controller_clients_.push_back(client); controller_clients_.push_back(std::move(client));
return; return;
} }
} }
...@@ -218,8 +217,10 @@ int VideoCaptureController::RemoveClient( ...@@ -218,8 +217,10 @@ int VideoCaptureController::RemoveClient(
client->active_buffers.clear(); client->active_buffers.clear();
int session_id = client->session_id; int session_id = client->session_id;
controller_clients_.remove(client); controller_clients_.remove_if(
delete client; [client](const std::unique_ptr<ControllerClient>& ptr) {
return ptr.get() == client;
});
return session_id; return session_id;
} }
...@@ -265,7 +266,7 @@ int VideoCaptureController::GetClientCount() const { ...@@ -265,7 +266,7 @@ int VideoCaptureController::GetClientCount() const {
bool VideoCaptureController::HasActiveClient() const { bool VideoCaptureController::HasActiveClient() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
for (ControllerClient* client : controller_clients_) { for (const auto& client : controller_clients_) {
if (!client->paused) if (!client->paused)
return true; return true;
} }
...@@ -274,7 +275,7 @@ bool VideoCaptureController::HasActiveClient() const { ...@@ -274,7 +275,7 @@ bool VideoCaptureController::HasActiveClient() const {
bool VideoCaptureController::HasPausedClient() const { bool VideoCaptureController::HasPausedClient() const {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
for (ControllerClient* client : controller_clients_) { for (const auto& client : controller_clients_) {
if (client->paused) if (client->paused)
return true; return true;
} }
...@@ -350,8 +351,6 @@ VideoCaptureController::GetVideoCaptureFormat() const { ...@@ -350,8 +351,6 @@ VideoCaptureController::GetVideoCaptureFormat() const {
} }
VideoCaptureController::~VideoCaptureController() { VideoCaptureController::~VideoCaptureController() {
base::STLDeleteContainerPointers(controller_clients_.begin(),
controller_clients_.end());
} }
void VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread( void VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread(
...@@ -386,14 +385,14 @@ void VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread( ...@@ -386,14 +385,14 @@ void VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread(
buffer->mapped_size()))) buffer->mapped_size())))
<< "VideoFrame does not appear to be backed by Buffer"; << "VideoFrame does not appear to be backed by Buffer";
for (auto* client : controller_clients_) { for (const auto& client : controller_clients_) {
if (client->session_closed || client->paused) if (client->session_closed || client->paused)
continue; continue;
// On the first use of a buffer on a client, share the memory handles. // On the first use of a buffer on a client, share the memory handles.
const bool is_new_buffer = client->known_buffers.insert(buffer_id).second; const bool is_new_buffer = client->known_buffers.insert(buffer_id).second;
if (is_new_buffer) if (is_new_buffer)
DoNewBufferOnIOThread(client, buffer.get(), frame); DoNewBufferOnIOThread(client.get(), buffer.get(), frame);
client->event_handler->OnBufferReady(client->controller_id, buffer_id, client->event_handler->OnBufferReady(client->controller_id, buffer_id,
frame); frame);
...@@ -429,7 +428,7 @@ void VideoCaptureController::DoErrorOnIOThread() { ...@@ -429,7 +428,7 @@ void VideoCaptureController::DoErrorOnIOThread() {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
state_ = VIDEO_CAPTURE_STATE_ERROR; state_ = VIDEO_CAPTURE_STATE_ERROR;
for (const auto* client : controller_clients_) { for (const auto& client : controller_clients_) {
if (client->session_closed) if (client->session_closed)
continue; continue;
client->event_handler->OnError(client->controller_id); client->event_handler->OnError(client->controller_id);
...@@ -445,7 +444,7 @@ void VideoCaptureController::DoBufferDestroyedOnIOThread( ...@@ -445,7 +444,7 @@ void VideoCaptureController::DoBufferDestroyedOnIOThread(
int buffer_id_to_drop) { int buffer_id_to_drop) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
for (auto* client : controller_clients_) { for (const auto& client : controller_clients_) {
if (client->session_closed) if (client->session_closed)
continue; continue;
...@@ -496,21 +495,21 @@ VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( ...@@ -496,21 +495,21 @@ VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
VideoCaptureControllerID id, VideoCaptureControllerID id,
VideoCaptureControllerEventHandler* handler, VideoCaptureControllerEventHandler* handler,
const ControllerClients& clients) { const ControllerClients& clients) {
for (auto* client : clients) { for (const auto& client : clients) {
if (client->controller_id == id && client->event_handler == handler) if (client->controller_id == id && client->event_handler == handler)
return client; return client.get();
} }
return NULL; return nullptr;
} }
VideoCaptureController::ControllerClient* VideoCaptureController::FindClient( VideoCaptureController::ControllerClient* VideoCaptureController::FindClient(
int session_id, int session_id,
const ControllerClients& clients) { const ControllerClients& clients) {
for (auto* client : clients) { for (const auto& client : clients) {
if (client->session_id == session_id) if (client->session_id == session_id)
return client; return client.get();
} }
return NULL; return nullptr;
} }
} // namespace content } // namespace content
...@@ -135,7 +135,7 @@ class CONTENT_EXPORT VideoCaptureController { ...@@ -135,7 +135,7 @@ class CONTENT_EXPORT VideoCaptureController {
private: private:
struct ControllerClient; struct ControllerClient;
typedef std::list<ControllerClient*> ControllerClients; typedef std::list<std::unique_ptr<ControllerClient>> ControllerClients;
// Notify renderer that a new buffer has been created. // Notify renderer that a new buffer has been created.
void DoNewBufferOnIOThread(ControllerClient* client, void DoNewBufferOnIOThread(ControllerClient* client,
......
...@@ -6,7 +6,10 @@ ...@@ -6,7 +6,10 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm>
#include "base/bind.h" #include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "content/browser/bad_message.h" #include "content/browser/bad_message.h"
#include "content/browser/renderer_host/p2p/socket_host.h" #include "content/browser/renderer_host/p2p/socket_host.h"
#include "content/common/p2p_messages.h" #include "content/common/p2p_messages.h"
...@@ -122,7 +125,6 @@ void P2PSocketDispatcherHost::OnChannelClosing() { ...@@ -122,7 +125,6 @@ void P2PSocketDispatcherHost::OnChannelClosing() {
// Since the IPC sender is gone, close pending connections. // Since the IPC sender is gone, close pending connections.
sockets_.clear(); sockets_.clear();
base::STLDeleteContainerPointers(dns_requests_.begin(), dns_requests_.end());
dns_requests_.clear(); dns_requests_.clear();
if (monitoring_networks_) { if (monitoring_networks_) {
...@@ -226,12 +228,13 @@ void P2PSocketDispatcherHost::OnStopNetworkNotifications() { ...@@ -226,12 +228,13 @@ void P2PSocketDispatcherHost::OnStopNetworkNotifications() {
void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name, void P2PSocketDispatcherHost::OnGetHostAddress(const std::string& host_name,
int32_t request_id) { int32_t request_id) {
DnsRequest* request = new DnsRequest(request_id, std::unique_ptr<DnsRequest> request = base::MakeUnique<DnsRequest>(
resource_context_->GetHostResolver()); request_id, resource_context_->GetHostResolver());
dns_requests_.insert(request); DnsRequest* request_ptr = request.get();
request->Resolve(host_name, base::Bind( dns_requests_.insert(std::move(request));
&P2PSocketDispatcherHost::OnAddressResolved, request_ptr->Resolve(host_name,
base::Unretained(this), request)); base::Bind(&P2PSocketDispatcherHost::OnAddressResolved,
base::Unretained(this), request_ptr));
} }
void P2PSocketDispatcherHost::OnCreateSocket( void P2PSocketDispatcherHost::OnCreateSocket(
...@@ -393,8 +396,11 @@ void P2PSocketDispatcherHost::OnAddressResolved( ...@@ -393,8 +396,11 @@ void P2PSocketDispatcherHost::OnAddressResolved(
const net::IPAddressList& addresses) { const net::IPAddressList& addresses) {
Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses)); Send(new P2PMsg_GetHostAddressResult(request->request_id(), addresses));
dns_requests_.erase(request); dns_requests_.erase(
delete request; std::find_if(dns_requests_.begin(), dns_requests_.end(),
[request](const std::unique_ptr<DnsRequest>& ptr) {
return ptr.get() == request;
}));
} }
void P2PSocketDispatcherHost::StopRtpDumpOnIOThread(bool incoming, void P2PSocketDispatcherHost::StopRtpDumpOnIOThread(bool incoming,
......
...@@ -116,7 +116,7 @@ class P2PSocketDispatcherHost ...@@ -116,7 +116,7 @@ class P2PSocketDispatcherHost
bool monitoring_networks_; bool monitoring_networks_;
std::set<DnsRequest*> dns_requests_; std::set<std::unique_ptr<DnsRequest>> dns_requests_;
P2PMessageThrottler throttler_; P2PMessageThrottler throttler_;
net::IPAddress default_ipv4_local_address_; net::IPAddress default_ipv4_local_address_;
......
...@@ -6,9 +6,9 @@ ...@@ -6,9 +6,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h"
#include "content/browser/web_contents/web_contents_impl.h" #include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -109,9 +109,6 @@ TestNavigationObserver::TestNavigationObserver( ...@@ -109,9 +109,6 @@ TestNavigationObserver::TestNavigationObserver(
TestNavigationObserver::~TestNavigationObserver() { TestNavigationObserver::~TestNavigationObserver() {
StopWatchingNewWebContents(); StopWatchingNewWebContents();
base::STLDeleteContainerPointers(web_contents_observers_.begin(),
web_contents_observers_.end());
} }
void TestNavigationObserver::Wait() { void TestNavigationObserver::Wait() {
...@@ -130,7 +127,7 @@ void TestNavigationObserver::StopWatchingNewWebContents() { ...@@ -130,7 +127,7 @@ void TestNavigationObserver::StopWatchingNewWebContents() {
void TestNavigationObserver::RegisterAsObserver(WebContents* web_contents) { void TestNavigationObserver::RegisterAsObserver(WebContents* web_contents) {
web_contents_observers_.insert( web_contents_observers_.insert(
new TestWebContentsObserver(this, web_contents)); base::MakeUnique<TestWebContentsObserver>(this, web_contents));
} }
void TestNavigationObserver::OnWebContentsCreated(WebContents* web_contents) { void TestNavigationObserver::OnWebContentsCreated(WebContents* web_contents) {
...@@ -140,8 +137,11 @@ void TestNavigationObserver::OnWebContentsCreated(WebContents* web_contents) { ...@@ -140,8 +137,11 @@ void TestNavigationObserver::OnWebContentsCreated(WebContents* web_contents) {
void TestNavigationObserver::OnWebContentsDestroyed( void TestNavigationObserver::OnWebContentsDestroyed(
TestWebContentsObserver* observer, TestWebContentsObserver* observer,
WebContents* web_contents) { WebContents* web_contents) {
web_contents_observers_.erase(observer); web_contents_observers_.erase(std::find_if(
delete observer; web_contents_observers_.begin(), web_contents_observers_.end(),
[observer](const std::unique_ptr<TestWebContentsObserver>& ptr) {
return ptr.get() == observer;
}));
} }
void TestNavigationObserver::OnNavigationEntryCommitted( void TestNavigationObserver::OnNavigationEntryCommitted(
......
...@@ -97,7 +97,7 @@ class TestNavigationObserver { ...@@ -97,7 +97,7 @@ class TestNavigationObserver {
base::Callback<void(WebContents*)> web_contents_created_callback_; base::Callback<void(WebContents*)> web_contents_created_callback_;
// Living TestWebContentsObservers created by this observer. // Living TestWebContentsObservers created by this observer.
std::set<TestWebContentsObserver*> web_contents_observers_; std::set<std::unique_ptr<TestWebContentsObserver>> web_contents_observers_;
DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver); DISALLOW_COPY_AND_ASSIGN(TestNavigationObserver);
}; };
......
...@@ -74,11 +74,6 @@ JingleSession::JingleSession(JingleSessionManager* session_manager) ...@@ -74,11 +74,6 @@ JingleSession::JingleSession(JingleSessionManager* session_manager)
} }
JingleSession::~JingleSession() { JingleSession::~JingleSession() {
base::STLDeleteContainerPointers(pending_requests_.begin(),
pending_requests_.end());
base::STLDeleteContainerPointers(transport_info_requests_.begin(),
transport_info_requests_.end());
session_manager_->SessionDestroyed(this); session_manager_->SessionDestroyed(this);
} }
...@@ -230,7 +225,7 @@ void JingleSession::SendTransportInfo( ...@@ -230,7 +225,7 @@ void JingleSession::SendTransportInfo(
base::Unretained(this))); base::Unretained(this)));
if (request) { if (request) {
request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout)); request->SetTimeout(base::TimeDelta::FromSeconds(kTransportInfoTimeout));
transport_info_requests_.push_back(request.release()); transport_info_requests_.push_back(std::move(request));
} else { } else {
LOG(ERROR) << "Failed to send a transport-info message"; LOG(ERROR) << "Failed to send a transport-info message";
} }
...@@ -299,7 +294,7 @@ void JingleSession::SendMessage(const JingleMessage& message) { ...@@ -299,7 +294,7 @@ void JingleSession::SendMessage(const JingleMessage& message) {
} }
if (request) { if (request) {
request->SetTimeout(base::TimeDelta::FromSeconds(timeout)); request->SetTimeout(base::TimeDelta::FromSeconds(timeout));
pending_requests_.insert(request.release()); pending_requests_.insert(std::move(request));
} else { } else {
LOG(ERROR) << "Failed to send a " LOG(ERROR) << "Failed to send a "
<< JingleMessage::GetActionName(message.action) << " message"; << JingleMessage::GetActionName(message.action) << " message";
...@@ -313,8 +308,11 @@ void JingleSession::OnMessageResponse( ...@@ -313,8 +308,11 @@ void JingleSession::OnMessageResponse(
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
// Delete the request from the list of pending requests. // Delete the request from the list of pending requests.
pending_requests_.erase(request); pending_requests_.erase(
delete request; std::find_if(pending_requests_.begin(), pending_requests_.end(),
[request](const std::unique_ptr<IqRequest>& ptr) {
return ptr.get() == request;
}));
// Ignore all responses after session was closed. // Ignore all responses after session was closed.
if (state_ == CLOSED || state_ == FAILED) if (state_ == CLOSED || state_ == FAILED)
...@@ -349,14 +347,12 @@ void JingleSession::OnTransportInfoResponse(IqRequest* request, ...@@ -349,14 +347,12 @@ void JingleSession::OnTransportInfoResponse(IqRequest* request,
// Consider transport-info requests sent before this one lost and delete // Consider transport-info requests sent before this one lost and delete
// corresponding IqRequest objects. // corresponding IqRequest objects.
while (transport_info_requests_.front() != request) { while (transport_info_requests_.front().get() != request) {
delete transport_info_requests_.front();
transport_info_requests_.pop_front(); transport_info_requests_.pop_front();
} }
// Delete the |request| itself. // Delete the |request| itself.
DCHECK_EQ(request, transport_info_requests_.front()); DCHECK_EQ(request, transport_info_requests_.front().get());
delete request;
transport_info_requests_.pop_front(); transport_info_requests_.pop_front();
// Ignore transport-info timeouts. // Ignore transport-info timeouts.
......
...@@ -130,10 +130,10 @@ class JingleSession : public Session { ...@@ -130,10 +130,10 @@ class JingleSession : public Session {
Transport* transport_ = nullptr; Transport* transport_ = nullptr;
// Pending Iq requests. Used for all messages except transport-info. // Pending Iq requests. Used for all messages except transport-info.
std::set<IqRequest*> pending_requests_; std::set<std::unique_ptr<IqRequest>> pending_requests_;
// Pending transport-info requests. // Pending transport-info requests.
std::list<IqRequest*> transport_info_requests_; std::list<std::unique_ptr<IqRequest>> transport_info_requests_;
base::WeakPtrFactory<JingleSession> weak_factory_; base::WeakPtrFactory<JingleSession> weak_factory_;
......
This diff is collapsed.
...@@ -45,16 +45,28 @@ struct MESSAGE_CENTER_EXPORT CompareTimestampSerial { ...@@ -45,16 +45,28 @@ struct MESSAGE_CENTER_EXPORT CompareTimestampSerial {
bool operator()(Notification* n1, Notification* n2); bool operator()(Notification* n1, Notification* n2);
}; };
// An adapter to allow use of the comparers above with std::unique_ptr.
template <typename PlainCompare>
struct UniquePtrCompare {
template <typename T>
bool operator()(const std::unique_ptr<T>& n1, const std::unique_ptr<T>& n2) {
return PlainCompare()(n1.get(), n2.get());
}
};
// A helper class to manage the list of notifications. // A helper class to manage the list of notifications.
class MESSAGE_CENTER_EXPORT NotificationList { class MESSAGE_CENTER_EXPORT NotificationList {
public: public:
// Auto-sorted set. Matches the order in which Notifications are shown in // Auto-sorted set. Matches the order in which Notifications are shown in
// Notification Center. // Notification Center.
typedef std::set<Notification*, ComparePriorityTimestampSerial> Notifications; using Notifications = std::set<Notification*, ComparePriorityTimestampSerial>;
using OwnedNotifications =
std::set<std::unique_ptr<Notification>,
UniquePtrCompare<ComparePriorityTimestampSerial>>;
// Auto-sorted set used to return the Notifications to be shown as popup // Auto-sorted set used to return the Notifications to be shown as popup
// toasts. // toasts.
typedef std::set<Notification*, CompareTimestampSerial> PopupNotifications; using PopupNotifications = std::set<Notification*, CompareTimestampSerial>;
explicit NotificationList(MessageCenter* message_center); explicit NotificationList(MessageCenter* message_center);
virtual ~NotificationList(); virtual ~NotificationList();
...@@ -142,14 +154,14 @@ class MESSAGE_CENTER_EXPORT NotificationList { ...@@ -142,14 +154,14 @@ class MESSAGE_CENTER_EXPORT NotificationList {
TestPushingShownNotification); TestPushingShownNotification);
// Iterates through the list and returns the first notification matching |id|. // Iterates through the list and returns the first notification matching |id|.
Notifications::iterator GetNotification(const std::string& id); OwnedNotifications::iterator GetNotification(const std::string& id);
void EraseNotification(Notifications::iterator iter); void EraseNotification(OwnedNotifications::iterator iter);
void PushNotification(std::unique_ptr<Notification> notification); void PushNotification(std::unique_ptr<Notification> notification);
MessageCenter* message_center_; // owner MessageCenter* message_center_; // owner
Notifications notifications_; OwnedNotifications notifications_;
bool quiet_mode_; bool quiet_mode_;
DISALLOW_COPY_AND_ASSIGN(NotificationList); DISALLOW_COPY_AND_ASSIGN(NotificationList);
......
...@@ -88,11 +88,10 @@ class NotificationListTest : public testing::Test { ...@@ -88,11 +88,10 @@ class NotificationListTest : public testing::Test {
} }
Notification* GetNotification(const std::string& id) { Notification* GetNotification(const std::string& id) {
NotificationList::Notifications::iterator iter = auto iter = notification_list()->GetNotification(id);
notification_list()->GetNotification(id);
if (iter == notification_list()->notifications_.end()) if (iter == notification_list()->notifications_.end())
return NULL; return NULL;
return *iter; return iter->get();
} }
NotificationList* notification_list() { return notification_list_.get(); } NotificationList* notification_list() { return notification_list_.get(); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment