| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "android_webview/native/aw_contents_io_thread_client_impl.h" | 5 #include "android_webview/native/aw_contents_io_thread_client_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "android_webview/common/devtools_instrumentation.h" | 10 #include "android_webview/common/devtools_instrumentation.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 static LazyInstance<RfhToIoThreadClientMap> g_instance_; | 78 static LazyInstance<RfhToIoThreadClientMap> g_instance_; |
| 79 base::Lock map_lock_; | 79 base::Lock map_lock_; |
| 80 RenderFrameHostToIoThreadClientType rfh_to_io_thread_client_; | 80 RenderFrameHostToIoThreadClientType rfh_to_io_thread_client_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 // static | 83 // static |
| 84 LazyInstance<RfhToIoThreadClientMap> RfhToIoThreadClientMap::g_instance_ = | 84 LazyInstance<RfhToIoThreadClientMap> RfhToIoThreadClientMap::g_instance_ = |
| 85 LAZY_INSTANCE_INITIALIZER; | 85 LAZY_INSTANCE_INITIALIZER; |
| 86 | 86 |
| 87 // static | 87 // static |
| 88 LazyInstance<JavaObjectWeakGlobalRef> g_sw_instance_ = |
| 89 LAZY_INSTANCE_INITIALIZER; |
| 90 |
| 91 // static |
| 88 RfhToIoThreadClientMap* RfhToIoThreadClientMap::GetInstance() { | 92 RfhToIoThreadClientMap* RfhToIoThreadClientMap::GetInstance() { |
| 89 return g_instance_.Pointer(); | 93 return g_instance_.Pointer(); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void RfhToIoThreadClientMap::Set(pair<int, int> rfh_id, | 96 void RfhToIoThreadClientMap::Set(pair<int, int> rfh_id, |
| 93 const IoThreadClientData& client) { | 97 const IoThreadClientData& client) { |
| 94 base::AutoLock lock(map_lock_); | 98 base::AutoLock lock(map_lock_); |
| 95 rfh_to_io_thread_client_[rfh_id] = client; | 99 rfh_to_io_thread_client_[rfh_id] = client; |
| 96 } | 100 } |
| 97 | 101 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 | 251 |
| 248 // static | 252 // static |
| 249 void AwContentsIoThreadClientImpl::Associate( | 253 void AwContentsIoThreadClientImpl::Associate( |
| 250 WebContents* web_contents, | 254 WebContents* web_contents, |
| 251 const JavaRef<jobject>& jclient) { | 255 const JavaRef<jobject>& jclient) { |
| 252 JNIEnv* env = AttachCurrentThread(); | 256 JNIEnv* env = AttachCurrentThread(); |
| 253 // The ClientMapEntryUpdater lifespan is tied to the WebContents. | 257 // The ClientMapEntryUpdater lifespan is tied to the WebContents. |
| 254 new ClientMapEntryUpdater(env, web_contents, jclient.obj()); | 258 new ClientMapEntryUpdater(env, web_contents, jclient.obj()); |
| 255 } | 259 } |
| 256 | 260 |
| 261 // static |
| 262 void AwContentsIoThreadClientImpl::SetServiceWorkerIoThreadClient( |
| 263 const base::android::JavaRef<jobject>& jclient) { |
| 264 JavaObjectWeakGlobalRef temp(AttachCurrentThread(), jclient.obj()); |
| 265 g_sw_instance_.Get() = temp; |
| 266 } |
| 267 |
| 268 // static |
| 269 scoped_ptr<AwContentsIoThreadClient> |
| 270 AwContentsIoThreadClient::GetServiceWorkerIoThreadClient() { |
| 271 if (g_sw_instance_.Get().is_empty()) |
| 272 return scoped_ptr<AwContentsIoThreadClient>(); |
| 273 |
| 274 JNIEnv* env = AttachCurrentThread(); |
| 275 ScopedJavaLocalRef<jobject> java_delegate = g_sw_instance_.Get().get(env); |
| 276 |
| 277 DCHECK(!java_delegate.is_null()); |
| 278 return scoped_ptr<AwContentsIoThreadClient>(new AwContentsIoThreadClientImpl( |
| 279 false, java_delegate)); |
| 280 } |
| 281 |
| 257 AwContentsIoThreadClientImpl::AwContentsIoThreadClientImpl( | 282 AwContentsIoThreadClientImpl::AwContentsIoThreadClientImpl( |
| 258 bool pending_association, | 283 bool pending_association, |
| 259 const JavaRef<jobject>& obj) | 284 const JavaRef<jobject>& obj) |
| 260 : pending_association_(pending_association), | 285 : pending_association_(pending_association), |
| 261 java_object_(obj) { | 286 java_object_(obj) { |
| 262 } | 287 } |
| 263 | 288 |
| 264 AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() { | 289 AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() { |
| 265 // explict, out-of-line destructor. | 290 // explict, out-of-line destructor. |
| 266 } | 291 } |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 jstring_reason.obj(), | 529 jstring_reason.obj(), |
| 505 jstringArray_response_header_names.obj(), | 530 jstringArray_response_header_names.obj(), |
| 506 jstringArray_response_header_values.obj()); | 531 jstringArray_response_header_values.obj()); |
| 507 } | 532 } |
| 508 | 533 |
| 509 bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) { | 534 bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) { |
| 510 return RegisterNativesImpl(env); | 535 return RegisterNativesImpl(env); |
| 511 } | 536 } |
| 512 | 537 |
| 513 } // namespace android_webview | 538 } // namespace android_webview |
| OLD | NEW |