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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync_file_system/drive_backend/callback_tracker.h"
6
7 #include <algorithm>
8
9 namespace sync_file_system {
10 namespace drive_backend {
11
12 namespace internal {
13
14 AbortHelper::AbortHelper(CallbackTracker* tracker)
nhiroki 2014/06/04 09:16:47 Why don't you move these definitions of AbortHelpe
tzik 2014/06/04 09:45:24 Done.
15 : tracker_(tracker), weak_ptr_factory_(this) {
16 }
17
18 AbortHelper::~AbortHelper() {}
19
20 base::WeakPtr<AbortHelper> AbortHelper::AsWeakPtr() {
21 return weak_ptr_factory_.GetWeakPtr();
22 }
23
24 // static
25 scoped_ptr<AbortHelper> AbortHelper::TakeOwnership(
26 const base::WeakPtr<AbortHelper>& abort_helper) {
27 if (!abort_helper)
28 return scoped_ptr<AbortHelper>();
29 scoped_ptr<AbortHelper> result =
30 abort_helper->tracker_->PassAbortHelper(abort_helper.get());
31 abort_helper->weak_ptr_factory_.InvalidateWeakPtrs();
32 return result.Pass();
33 }
34
35 } // namespace internal
36
37 CallbackTracker::CallbackTracker() {
38 }
39
40 CallbackTracker::~CallbackTracker() {
41 AbortAll();
42 }
43
44 void CallbackTracker::AbortAll() {
45 AbortClosureByHelper helpers;
46 std::swap(helpers, helpers_);
47 for (AbortClosureByHelper::iterator itr = helpers.begin();
48 itr != helpers.end(); ++itr) {
49 delete itr->first;
50 itr->second.Run();
51 }
52 }
53
54 scoped_ptr<internal::AbortHelper> CallbackTracker::PassAbortHelper(
55 internal::AbortHelper* helper) {
56 if (helpers_.erase(helper) == 1)
57 return scoped_ptr<internal::AbortHelper>(helper);
58 return scoped_ptr<internal::AbortHelper>();
59 }
60
61 } // namespace drive_backend
62 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698