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

Side by Side Diff: content/child/background_sync/background_sync_provider_thread_proxy.cc

Issue 1139643008: [BackgroundSync] Fix lifetime issues with callbacks pointer in CallbackThreadAdapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/background_sync/background_sync_provider_thread_proxy.h" 5 #include "content/child/background_sync/background_sync_provider_thread_proxy.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 22 matching lines...) Expand all
33 : worker_thread_id_(worker_thread_id) { 33 : worker_thread_id_(worker_thread_id) {
34 callbacks_.reset(callbacks.release()); 34 callbacks_.reset(callbacks.release());
35 } 35 }
36 36
37 virtual void onSuccess(S* results) { 37 virtual void onSuccess(S* results) {
38 // If the worker thread has been destroyed, then this task will be 38 // If the worker thread has been destroyed, then this task will be
39 // silently discarded. 39 // silently discarded.
40 WorkerTaskRunner::Instance()->PostTask( 40 WorkerTaskRunner::Instance()->PostTask(
41 worker_thread_id_, 41 worker_thread_id_,
42 base::Bind(&blink::WebCallbacks<S, T>::onSuccess, 42 base::Bind(&blink::WebCallbacks<S, T>::onSuccess,
43 base::Unretained(callbacks_.get()), results)); 43 base::Owned(callbacks_.release()), results));
44 } 44 }
45 45
46 virtual void onError(T* error) { 46 virtual void onError(T* error) {
47 // If the worker thread has been destroyed, then this task will be 47 // If the worker thread has been destroyed, then this task will be
48 // silently discarded. 48 // silently discarded.
49 WorkerTaskRunner::Instance()->PostTask( 49 WorkerTaskRunner::Instance()->PostTask(
50 worker_thread_id_, 50 worker_thread_id_,
51 base::Bind(&blink::WebCallbacks<S, T>::onError, 51 base::Bind(&blink::WebCallbacks<S, T>::onError,
52 base::Unretained(callbacks_.get()), error)); 52 base::Owned(callbacks_.release()), error));
53 } 53 }
54 54
55 private: 55 private:
56 scoped_ptr<blink::WebCallbacks<S, T>> callbacks_; 56 scoped_ptr<blink::WebCallbacks<S, T>> callbacks_;
57 int worker_thread_id_; 57 int worker_thread_id_;
58 }; 58 };
59 59
60 LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky 60 LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky
61 g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER; 61 g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER;
62 62
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 : main_thread_task_runner_(main_thread_task_runner), 159 : main_thread_task_runner_(main_thread_task_runner),
160 sync_provider_(sync_provider) { 160 sync_provider_(sync_provider) {
161 g_sync_provider_tls.Pointer()->Set(this); 161 g_sync_provider_tls.Pointer()->Set(this);
162 } 162 }
163 163
164 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() { 164 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
165 g_sync_provider_tls.Pointer()->Set(nullptr); 165 g_sync_provider_tls.Pointer()->Set(nullptr);
166 } 166 }
167 167
168 } // namespace content 168 } // namespace content
OLDNEW
« 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