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

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

Issue 1302543002: Support calling BackgroundSyncProviderThreadProxy::GetThreadInstance after the worker has stopped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
63 } // anonymous namespace 63 } // anonymous namespace
64 64
65 // static
65 BackgroundSyncProviderThreadProxy* 66 BackgroundSyncProviderThreadProxy*
66 BackgroundSyncProviderThreadProxy::GetThreadInstance( 67 BackgroundSyncProviderThreadProxy::GetThreadInstance(
67 base::SingleThreadTaskRunner* main_thread_task_runner, 68 base::SingleThreadTaskRunner* main_thread_task_runner,
68 BackgroundSyncProvider* sync_provider) { 69 BackgroundSyncProvider* sync_provider) {
69 if (g_sync_provider_tls.Pointer()->Get()) 70 if (g_sync_provider_tls.Pointer()->Get())
70 return g_sync_provider_tls.Pointer()->Get(); 71 return g_sync_provider_tls.Pointer()->Get();
71 72
73 if (!WorkerTaskRunner::Instance()->CurrentWorkerId()) {
74 // This could happen if GetThreadInstance is called very late (say by a
75 // garbage collected SyncRegistration).
76 return nullptr;
77 }
78
72 BackgroundSyncProviderThreadProxy* instance = 79 BackgroundSyncProviderThreadProxy* instance =
73 new BackgroundSyncProviderThreadProxy(main_thread_task_runner, 80 new BackgroundSyncProviderThreadProxy(main_thread_task_runner,
74 sync_provider); 81 sync_provider);
75 DCHECK(WorkerTaskRunner::Instance()->CurrentWorkerId());
76 WorkerTaskRunner::Instance()->AddStopObserver(instance); 82 WorkerTaskRunner::Instance()->AddStopObserver(instance);
77 return instance; 83 return instance;
78 } 84 }
79 85
80 void BackgroundSyncProviderThreadProxy::registerBackgroundSync( 86 void BackgroundSyncProviderThreadProxy::registerBackgroundSync(
81 const blink::WebSyncRegistration* options, 87 const blink::WebSyncRegistration* options,
82 blink::WebServiceWorkerRegistration* service_worker_registration, 88 blink::WebServiceWorkerRegistration* service_worker_registration,
83 blink::WebSyncRegistrationCallbacks* callbacks) { 89 blink::WebSyncRegistrationCallbacks* callbacks) {
84 DCHECK(options); 90 DCHECK(options);
85 DCHECK(service_worker_registration); 91 DCHECK(service_worker_registration);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 : main_thread_task_runner_(main_thread_task_runner), 186 : main_thread_task_runner_(main_thread_task_runner),
181 sync_provider_(sync_provider) { 187 sync_provider_(sync_provider) {
182 g_sync_provider_tls.Pointer()->Set(this); 188 g_sync_provider_tls.Pointer()->Set(this);
183 } 189 }
184 190
185 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() { 191 BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() {
186 g_sync_provider_tls.Pointer()->Set(nullptr); 192 g_sync_provider_tls.Pointer()->Set(nullptr);
187 } 193 }
188 194
189 } // namespace content 195 } // 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