Index: content/child/background_sync/background_sync_provider_thread_proxy.cc |
diff --git a/content/child/background_sync/background_sync_provider_thread_proxy.cc b/content/child/background_sync/background_sync_provider_thread_proxy.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..29930cb04a9ebcae681afc29dfe164b4aabd07c8 |
--- /dev/null |
+++ b/content/child/background_sync/background_sync_provider_thread_proxy.cc |
@@ -0,0 +1,131 @@ |
+// Copyright 2015 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 "content/child/background_sync/background_sync_provider_thread_proxy.h" |
+ |
+#include "base/bind.h" |
+#include "base/bind_helpers.h" |
+#include "base/lazy_instance.h" |
+#include "base/location.h" |
+#include "base/single_thread_task_runner.h" |
+#include "base/threading/thread_local.h" |
+#include "content/child/background_sync/background_sync_provider.h" |
+ |
+using base::LazyInstance; |
+using base::ThreadLocalPointer; |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+LazyInstance<ThreadLocalPointer<BackgroundSyncProviderThreadProxy>>::Leaky |
+ g_sync_provider_tls = LAZY_INSTANCE_INITIALIZER; |
+ |
+} // anonymous namespace |
+ |
+BackgroundSyncProviderThreadProxy* |
+BackgroundSyncProviderThreadProxy::GetThreadInstance( |
+ base::SingleThreadTaskRunner* main_thread_task_runner, |
+ BackgroundSyncProvider* sync_provider) { |
+ if (g_sync_provider_tls.Pointer()->Get()) |
+ return g_sync_provider_tls.Pointer()->Get(); |
+ |
+ BackgroundSyncProviderThreadProxy* instance = |
+ new BackgroundSyncProviderThreadProxy(main_thread_task_runner, |
+ sync_provider); |
+ DCHECK(WorkerTaskRunner::Instance()->CurrentWorkerId()); |
+ WorkerTaskRunner::Instance()->AddStopObserver(instance); |
+ return instance; |
+} |
+ |
+void BackgroundSyncProviderThreadProxy::registerBackgroundSync( |
+ const blink::WebSyncRegistration* options, |
+ blink::WebServiceWorkerRegistration* service_worker_registration, |
+ blink::WebSyncRegistrationCallbacks* callbacks) { |
+ DCHECK(options); |
+ DCHECK(service_worker_registration); |
+ DCHECK(callbacks); |
+ scoped_ptr<blink::WebSyncRegistration> options_ptr( |
+ const_cast<blink::WebSyncRegistration*>(options)); |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BackgroundSyncProvider::RegisterBackgroundSyncForWorker, |
+ base::Unretained(sync_provider_), |
+ Passed(options_ptr.Pass()), |
jkarlin
2015/05/07 11:51:53
base::Passed?
This could be "base::Passed(make_sc
iclelland
2015/05/09 06:41:17
Yes; that's better -- but based on the other comme
|
+ service_worker_registration, |
+ base::Unretained(callbacks), |
+ WorkerTaskRunner::Instance()->CurrentWorkerId())); |
+} |
+ |
+void BackgroundSyncProviderThreadProxy::unregisterBackgroundSync( |
+ blink::WebSyncRegistration::Periodicity periodicity, |
+ int64_t id, |
+ const blink::WebString& tag, |
+ blink::WebServiceWorkerRegistration* service_worker_registration, |
+ blink::WebSyncUnregistrationCallbacks* callbacks) { |
+ DCHECK(service_worker_registration); |
+ DCHECK(callbacks); |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BackgroundSyncProvider::UnregisterBackgroundSyncForWorker, |
+ base::Unretained(sync_provider_), |
+ periodicity, |
+ id, |
+ tag, |
+ service_worker_registration, |
+ base::Unretained(callbacks), |
+ WorkerTaskRunner::Instance()->CurrentWorkerId())); |
+} |
+ |
+void BackgroundSyncProviderThreadProxy::getRegistration( |
+ blink::WebSyncRegistration::Periodicity periodicity, |
+ const blink::WebString& tag, |
+ blink::WebServiceWorkerRegistration* service_worker_registration, |
+ blink::WebSyncRegistrationCallbacks* callbacks) { |
+ DCHECK(service_worker_registration); |
+ DCHECK(callbacks); |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BackgroundSyncProvider::GetRegistrationForWorker, |
+ base::Unretained(sync_provider_), |
+ periodicity, |
+ tag, |
+ service_worker_registration, |
+ base::Unretained(callbacks), |
+ WorkerTaskRunner::Instance()->CurrentWorkerId())); |
+} |
+ |
+void BackgroundSyncProviderThreadProxy::getRegistrations( |
+ blink::WebSyncRegistration::Periodicity periodicity, |
+ blink::WebServiceWorkerRegistration* service_worker_registration, |
+ blink::WebSyncGetRegistrationsCallbacks* callbacks) { |
+ DCHECK(service_worker_registration); |
+ DCHECK(callbacks); |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&BackgroundSyncProvider::GetRegistrationsForWorker, |
+ base::Unretained(sync_provider_), |
+ periodicity, |
+ service_worker_registration, |
+ base::Unretained(callbacks), |
+ WorkerTaskRunner::Instance()->CurrentWorkerId())); |
+} |
+ |
+void BackgroundSyncProviderThreadProxy::OnWorkerRunLoopStopped() { |
+ delete this; |
+} |
+ |
+BackgroundSyncProviderThreadProxy::BackgroundSyncProviderThreadProxy( |
+ base::SingleThreadTaskRunner* main_thread_task_runner, |
+ BackgroundSyncProvider* sync_provider) |
+ : main_thread_task_runner_(main_thread_task_runner), |
+ sync_provider_(sync_provider) { |
+ g_sync_provider_tls.Pointer()->Set(this); |
+} |
+ |
+BackgroundSyncProviderThreadProxy::~BackgroundSyncProviderThreadProxy() { |
+ g_sync_provider_tls.Pointer()->Set(nullptr); |
+} |
+ |
+} // namespace content |