| 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 "ui/base/clipboard/clipboard_android.h" | 5 #include "ui/base/clipboard/clipboard_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; | 64 base::LazyInstance<ClipboardMap>::Leaky g_map = LAZY_INSTANCE_INITIALIZER; |
| 65 | 65 |
| 66 ClipboardMap::ClipboardMap() { | 66 ClipboardMap::ClipboardMap() { |
| 67 JNIEnv* env = AttachCurrentThread(); | 67 JNIEnv* env = AttachCurrentThread(); |
| 68 DCHECK(env); | 68 DCHECK(env); |
| 69 | 69 |
| 70 // Get the context. | 70 // Get the context. |
| 71 jobject context = base::android::GetApplicationContext(); | 71 jobject context = base::android::GetApplicationContext(); |
| 72 DCHECK(context); | 72 DCHECK(context); |
| 73 | 73 |
| 74 ScopedJavaLocalRef<jobject> local_ref = | 74 clipboard_manager_.Reset(Java_Clipboard_create(env, context)); |
| 75 Java_Clipboard_create(env, context); | 75 DCHECK(clipboard_manager_.obj()); |
| 76 DCHECK(local_ref.obj()); | |
| 77 clipboard_manager_.Reset(env, local_ref.Release()); | |
| 78 } | 76 } |
| 79 | 77 |
| 80 std::string ClipboardMap::Get(const std::string& format) { | 78 std::string ClipboardMap::Get(const std::string& format) { |
| 81 base::AutoLock lock(lock_); | 79 base::AutoLock lock(lock_); |
| 82 SyncWithAndroidClipboard(); | 80 SyncWithAndroidClipboard(); |
| 83 std::map<std::string, std::string>::const_iterator it = map_.find(format); | 81 std::map<std::string, std::string>::const_iterator it = map_.find(format); |
| 84 return it == map_.end() ? std::string() : it->second; | 82 return it == map_.end() ? std::string() : it->second; |
| 85 } | 83 } |
| 86 | 84 |
| 87 bool ClipboardMap::HasFormat(const std::string& format) { | 85 bool ClipboardMap::HasFormat(const std::string& format) { |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 const char* data_data, | 464 const char* data_data, |
| 467 size_t data_len) { | 465 size_t data_len) { |
| 468 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); | 466 g_map.Get().Set(format.ToString(), std::string(data_data, data_len)); |
| 469 } | 467 } |
| 470 | 468 |
| 471 bool RegisterClipboardAndroid(JNIEnv* env) { | 469 bool RegisterClipboardAndroid(JNIEnv* env) { |
| 472 return RegisterNativesImpl(env); | 470 return RegisterNativesImpl(env); |
| 473 } | 471 } |
| 474 | 472 |
| 475 } // namespace ui | 473 } // namespace ui |
| OLD | NEW |