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

Side by Side 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, 6 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 unified diff | Download patch
OLDNEW
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.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <limits> 8 #include <limits>
9 #include <memory> 9 #include <memory>
10 10
(...skipping 14 matching lines...) Expand all
25 void Clipboard::SetAllowedThreads( 25 void Clipboard::SetAllowedThreads(
26 const std::vector<base::PlatformThreadId>& allowed_threads) { 26 const std::vector<base::PlatformThreadId>& allowed_threads) {
27 base::AutoLock lock(clipboard_map_lock_.Get()); 27 base::AutoLock lock(clipboard_map_lock_.Get());
28 28
29 allowed_threads_.Get().clear(); 29 allowed_threads_.Get().clear();
30 std::copy(allowed_threads.begin(), allowed_threads.end(), 30 std::copy(allowed_threads.begin(), allowed_threads.end(),
31 std::back_inserter(allowed_threads_.Get())); 31 std::back_inserter(allowed_threads_.Get()));
32 } 32 }
33 33
34 // static 34 // static
35 void Clipboard::SetClipboardForCurrentThread(
36 std::unique_ptr<Clipboard> platform_clipboard) {
37 base::AutoLock lock(clipboard_map_lock_.Get());
38 base::PlatformThreadId id = Clipboard::GetAndValidateThreadID();
39
40 ClipboardMap* clipboard_map = clipboard_map_.Pointer();
41 ClipboardMap::const_iterator it = clipboard_map->find(id);
42 if (it != clipboard_map->end()) {
43 // This is suboptimal, but because the timing of how we create
44 // WindowManagerConnection, we can end up having created a Clipboard object
45 // 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.
46 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.
47 clipboard_map->erase(it);
48 }
49 clipboard_map->insert(std::make_pair(id, platform_clipboard.release()));
50 }
51
52 // static
35 Clipboard* Clipboard::GetForCurrentThread() { 53 Clipboard* Clipboard::GetForCurrentThread() {
36 base::AutoLock lock(clipboard_map_lock_.Get()); 54 base::AutoLock lock(clipboard_map_lock_.Get());
37 55 base::PlatformThreadId id = GetAndValidateThreadID();
38 base::PlatformThreadId id = base::PlatformThread::CurrentId();
39
40 AllowedThreadsVector* allowed_threads = allowed_threads_.Pointer();
41 if (!allowed_threads->empty()) {
42 bool found = false;
43 for (AllowedThreadsVector::const_iterator it = allowed_threads->begin();
44 it != allowed_threads->end(); ++it) {
45 if (*it == id) {
46 found = true;
47 break;
48 }
49 }
50
51 DCHECK(found);
52 }
53 56
54 ClipboardMap* clipboard_map = clipboard_map_.Pointer(); 57 ClipboardMap* clipboard_map = clipboard_map_.Pointer();
55 ClipboardMap::const_iterator it = clipboard_map->find(id); 58 ClipboardMap::const_iterator it = clipboard_map->find(id);
56 if (it != clipboard_map->end()) 59 if (it != clipboard_map->end())
57 return it->second; 60 return it->second;
58 61
59 Clipboard* clipboard = Clipboard::Create(); 62 Clipboard* clipboard = Clipboard::Create();
60 clipboard_map->insert(std::make_pair(id, clipboard)); 63 clipboard_map->insert(std::make_pair(id, clipboard));
61 return clipboard; 64 return clipboard;
62 } 65 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 std::string(&(params[0].front()), params[0].size())), 128 std::string(&(params[0].front()), params[0].size())),
126 &(params[1].front()), 129 &(params[1].front()),
127 params[1].size()); 130 params[1].size());
128 break; 131 break;
129 132
130 default: 133 default:
131 NOTREACHED(); 134 NOTREACHED();
132 } 135 }
133 } 136 }
134 137
138 base::PlatformThreadId Clipboard::GetAndValidateThreadID() {
139 base::PlatformThreadId id = base::PlatformThread::CurrentId();
140 #ifndef NDEBUG
141 AllowedThreadsVector* allowed_threads = allowed_threads_.Pointer();
142 if (!allowed_threads->empty()) {
143 bool found = false;
144 for (AllowedThreadsVector::const_iterator it = allowed_threads->begin();
145 it != allowed_threads->end(); ++it) {
146 if (*it == id) {
147 found = true;
148 break;
149 }
150 }
151
152 DCHECK(found);
153 }
154 #endif
155
156 return id;
157 }
158
135 } // namespace ui 159 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698