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

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: Patch cleanup. 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..59b032bbfe672598a4317e45a8e82daa9df03073 100644
--- a/ui/base/clipboard/clipboard.cc
+++ b/ui/base/clipboard/clipboard.cc
@@ -32,24 +32,26 @@ void Clipboard::SetAllowedThreads(
}
// static
-Clipboard* Clipboard::GetForCurrentThread() {
+void Clipboard::SetClipboardForCurrentThread(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.
+ delete it->second;
+ clipboard_map->erase(it);
}
+ clipboard_map->insert(std::make_pair(id, platform_clipboard));
+}
+
+// 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 +134,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