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

Unified Diff: ui/base/clipboard/clipboard.cc

Issue 2011833003: Implement ui::ClipboardMus. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix cast_linux. Created 4 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/clipboard/clipboard.cc
diff --git a/ui/base/clipboard/clipboard.cc b/ui/base/clipboard/clipboard.cc
index d43954bbc31d39fc7db5bcbc7fe645ae34599f8e..ec6bb321a5fe27499dd1234aa46d544dc6be1133 100644
--- a/ui/base/clipboard/clipboard.cc
+++ b/ui/base/clipboard/clipboard.cc
@@ -32,24 +32,27 @@ void Clipboard::SetAllowedThreads(
}
// static
-Clipboard* Clipboard::GetForCurrentThread() {
+void Clipboard::SetClipboardForCurrentThread(
+ std::unique_ptr<Clipboard> platform_clipboard) {
base::AutoLock lock(clipboard_map_lock_.Get());
+ base::PlatformThreadId id = Clipboard::GetAndValidateThreadID();
- base::PlatformThreadId id = base::PlatformThread::CurrentId();
-
- AllowedThreadsVector* allowed_threads = allowed_threads_.Pointer();
- if (!allowed_threads->empty()) {
- bool found = false;
- for (AllowedThreadsVector::const_iterator it = allowed_threads->begin();
- it != allowed_threads->end(); ++it) {
- if (*it == id) {
- found = true;
- break;
- }
- }
-
- DCHECK(found);
+ ClipboardMap* clipboard_map = clipboard_map_.Pointer();
+ ClipboardMap::const_iterator it = clipboard_map->find(id);
+ if (it != clipboard_map->end()) {
+ // This is suboptimal, but because the timing of how we create
+ // WindowManagerConnection, we can end up having created a Clipboard object
+ // before we've established our first mojo connection to mus.
dcheng 2016/06/04 06:14:00 I'm a little worried about potential side effects
Elliot Glaysher 2016/06/06 20:10:12 This was entirely my fault. Fixed.
+ delete it->second;
dcheng 2016/06/04 06:14:00 We may as well fix the clipboard map to store uniq
Elliot Glaysher 2016/06/06 20:10:12 Done.
+ clipboard_map->erase(it);
}
+ clipboard_map->insert(std::make_pair(id, platform_clipboard.release()));
+}
+
+// static
+Clipboard* Clipboard::GetForCurrentThread() {
+ base::AutoLock lock(clipboard_map_lock_.Get());
+ base::PlatformThreadId id = GetAndValidateThreadID();
ClipboardMap* clipboard_map = clipboard_map_.Pointer();
ClipboardMap::const_iterator it = clipboard_map->find(id);
@@ -132,4 +135,25 @@ void Clipboard::DispatchObject(ObjectType type, const ObjectMapParams& params) {
}
}
+base::PlatformThreadId Clipboard::GetAndValidateThreadID() {
+ base::PlatformThreadId id = base::PlatformThread::CurrentId();
+#ifndef NDEBUG
+ AllowedThreadsVector* allowed_threads = allowed_threads_.Pointer();
+ if (!allowed_threads->empty()) {
+ bool found = false;
+ for (AllowedThreadsVector::const_iterator it = allowed_threads->begin();
+ it != allowed_threads->end(); ++it) {
+ if (*it == id) {
+ found = true;
+ break;
+ }
+ }
+
+ DCHECK(found);
+ }
+#endif
+
+ return id;
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698