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

Unified Diff: components/drive/file_write_watcher.cc

Issue 2353053002: Remove use of stl_util in drive. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/drive/file_write_watcher.cc
diff --git a/components/drive/file_write_watcher.cc b/components/drive/file_write_watcher.cc
index b298adc7472423a5b85bff6eb2d8d543d539f825..44287b827ef6a85f7fb371c11edbddfa1efb1216 100644
--- a/components/drive/file_write_watcher.cc
+++ b/components/drive/file_write_watcher.cc
@@ -14,7 +14,7 @@
#include "base/callback.h"
#include "base/files/file_path_watcher.h"
#include "base/macros.h"
-#include "base/stl_util.h"
+#include "base/memory/ptr_util.h"
#include "base/timer/timer.h"
#include "google_apis/drive/task_util.h"
@@ -70,7 +70,7 @@ class FileWriteWatcher::FileWriteWatcherImpl {
};
base::TimeDelta delay_;
- std::map<base::FilePath, PathWatchInfo*> watchers_;
+ std::map<base::FilePath, std::unique_ptr<PathWatchInfo>> watchers_;
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
base::ThreadChecker thread_checker_;
@@ -114,9 +114,6 @@ void FileWriteWatcher::FileWriteWatcherImpl::StartWatch(
FileWriteWatcher::FileWriteWatcherImpl::~FileWriteWatcherImpl() {
DCHECK(file_task_runner_->BelongsToCurrentThread());
-
- base::STLDeleteContainerPairSecondPointers(watchers_.begin(),
- watchers_.end());
}
void FileWriteWatcher::FileWriteWatcherImpl::DestroyOnFileThread() {
@@ -131,7 +128,7 @@ void FileWriteWatcher::FileWriteWatcherImpl::StartWatchOnFileThread(
const base::Closure& on_write_callback) {
DCHECK(file_task_runner_->BelongsToCurrentThread());
- std::map<base::FilePath, PathWatchInfo*>::iterator it = watchers_.find(path);
+ auto it = watchers_.find(path);
if (it != watchers_.end()) {
// We are already watching the path.
on_start_callback.Run(true);
@@ -140,13 +137,14 @@ void FileWriteWatcher::FileWriteWatcherImpl::StartWatchOnFileThread(
}
// Start watching |path|.
- std::unique_ptr<PathWatchInfo> info(new PathWatchInfo(on_write_callback));
+ std::unique_ptr<PathWatchInfo> info =
+ base::MakeUnique<PathWatchInfo>(on_write_callback);
bool ok = info->watcher.Watch(
path,
false, // recursive
base::Bind(&FileWriteWatcherImpl::OnWriteEvent,
weak_ptr_factory_.GetWeakPtr()));
- watchers_[path] = info.release();
+ watchers_[path] = std::move(info);
on_start_callback.Run(ok);
}
@@ -158,7 +156,7 @@ void FileWriteWatcher::FileWriteWatcherImpl::OnWriteEvent(
if (error)
return;
- std::map<base::FilePath, PathWatchInfo*>::iterator it = watchers_.find(path);
+ auto it = watchers_.find(path);
DCHECK(it != watchers_.end());
// Heuristics for detecting the end of successive write operations.
@@ -176,16 +174,15 @@ void FileWriteWatcher::FileWriteWatcherImpl::InvokeCallback(
const base::FilePath& path) {
DCHECK(file_task_runner_->BelongsToCurrentThread());
- std::map<base::FilePath, PathWatchInfo*>::iterator it = watchers_.find(path);
+ auto it = watchers_.find(path);
DCHECK(it != watchers_.end());
std::vector<base::Closure> callbacks;
callbacks.swap(it->second->on_write_callbacks);
- delete it->second;
watchers_.erase(it);
- for (size_t i = 0; i < callbacks.size(); ++i)
- callbacks[i].Run();
+ for (const auto& callback : callbacks)
+ callback.Run();
}
FileWriteWatcher::FileWriteWatcher(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698