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

Unified Diff: chrome/browser/sync_file_system/drive_backend/callback_tracker.cc

Issue 310383002: [SyncFS] Introduce CallbackTracker to handle callback abortion (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
Index: chrome/browser/sync_file_system/drive_backend/callback_tracker.cc
diff --git a/chrome/browser/sync_file_system/drive_backend/callback_tracker.cc b/chrome/browser/sync_file_system/drive_backend/callback_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..42e14c79d165a20651ffd0228bfe1928ab5c886c
--- /dev/null
+++ b/chrome/browser/sync_file_system/drive_backend/callback_tracker.cc
@@ -0,0 +1,37 @@
+// Copyright 2014 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.
+
+#include "chrome/browser/sync_file_system/drive_backend/callback_tracker.h"
+
+#include <algorithm>
+
+namespace sync_file_system {
+namespace drive_backend {
+
+CallbackTracker::CallbackTracker() {
+}
+
+CallbackTracker::~CallbackTracker() {
+ AbortAll();
+}
+
+void CallbackTracker::AbortAll() {
+ AbortClosureByHelper helpers;
+ std::swap(helpers, helpers_);
+ for (AbortClosureByHelper::iterator itr = helpers.begin();
+ itr != helpers.end(); ++itr) {
+ delete itr->first;
+ itr->second.Run();
+ }
+}
+
+scoped_ptr<internal::AbortHelper> CallbackTracker::PassAbortHelper(
+ internal::AbortHelper* helper) {
+ if (helpers_.erase(helper) == 1)
+ return scoped_ptr<internal::AbortHelper>(helper);
+ return scoped_ptr<internal::AbortHelper>();
+}
+
+} // namespace drive_backend
+} // namespace sync_file_system

Powered by Google App Engine
This is Rietveld 408576698