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

Side by Side Diff: ui/base/clipboard/clipboard.h

Issue 720373003: Add FakeClipboard implementation for unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WINDOWS!!! Created 6 years, 1 month 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
« no previous file with comments | « ui/base/BUILD.gn ('k') | ui/base/clipboard/clipboard.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_ 5 #ifndef UI_BASE_CLIPBOARD_CLIPBOARD_H_
6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_ 6 #define UI_BASE_CLIPBOARD_CLIPBOARD_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/lazy_instance.h"
13 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
14 #include "base/process/process.h" 15 #include "base/process/process.h"
15 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "base/synchronization/lock.h"
16 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
17 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
18 #include "ui/base/clipboard/clipboard_types.h" 20 #include "ui/base/clipboard/clipboard_types.h"
19 #include "ui/base/ui_base_export.h" 21 #include "ui/base/ui_base_export.h"
20 22
21 #if defined(OS_WIN) 23 #if defined(OS_WIN)
22 #include <objidl.h> 24 #include <objidl.h>
23 #endif 25 #endif
24 26
25 namespace base { 27 namespace base {
(...skipping 17 matching lines...) Expand all
43 45
44 #ifdef __OBJC__ 46 #ifdef __OBJC__
45 @class NSString; 47 @class NSString;
46 #else 48 #else
47 class NSString; 49 class NSString;
48 #endif 50 #endif
49 51
50 namespace ui { 52 namespace ui {
51 template <typename T> 53 template <typename T>
52 class ClipboardTest; 54 class ClipboardTest;
55 class TestClipboard;
53 class ScopedClipboardWriter; 56 class ScopedClipboardWriter;
54 57
55 class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) { 58 class UI_BASE_EXPORT Clipboard : NON_EXPORTED_BASE(public base::ThreadChecker) {
56 public: 59 public:
57 // MIME type constants. 60 // MIME type constants.
58 static const char kMimeTypeText[]; 61 static const char kMimeTypeText[];
59 static const char kMimeTypeURIList[]; 62 static const char kMimeTypeURIList[];
60 static const char kMimeTypeDownloadURL[]; 63 static const char kMimeTypeDownloadURL[];
61 static const char kMimeTypeHTML[]; 64 static const char kMimeTypeHTML[];
62 static const char kMimeTypeRTF[]; 65 static const char kMimeTypeRTF[];
63 static const char kMimeTypePNG[]; 66 static const char kMimeTypePNG[];
64 67
65 // Platform neutral holder for native data representation of a clipboard type. 68 // Platform neutral holder for native data representation of a clipboard type.
66 struct UI_BASE_EXPORT FormatType { 69 struct UI_BASE_EXPORT FormatType {
67 FormatType(); 70 FormatType();
68 ~FormatType(); 71 ~FormatType();
69 72
70 // Serializes and deserializes a FormatType for use in IPC messages. 73 // Serializes and deserializes a FormatType for use in IPC messages.
71 std::string Serialize() const; 74 std::string Serialize() const;
72 static FormatType Deserialize(const std::string& serialization); 75 static FormatType Deserialize(const std::string& serialization);
73 76
74 #if !defined(OS_ANDROID)
75 // FormatType can be used in a set on some platforms. 77 // FormatType can be used in a set on some platforms.
76 bool operator<(const FormatType& other) const; 78 bool operator<(const FormatType& other) const;
77 #endif
78 79
79 #if defined(OS_WIN) 80 #if defined(OS_WIN)
80 const FORMATETC& ToFormatEtc() const { return data_; } 81 const FORMATETC& ToFormatEtc() const { return data_; }
81 #elif defined(USE_AURA) || defined(OS_ANDROID) 82 #elif defined(USE_AURA) || defined(OS_ANDROID)
82 const std::string& ToString() const { return data_; } 83 const std::string& ToString() const { return data_; }
83 #elif defined(OS_MACOSX) 84 #elif defined(OS_MACOSX)
84 NSString* ToNSString() const { return data_; } 85 NSString* ToNSString() const { return data_; }
85 // Custom copy and assignment constructor to handle NSString. 86 // Custom copy and assignment constructor to handle NSString.
86 FormatType(const FormatType& other); 87 FormatType(const FormatType& other);
87 FormatType& operator=(const FormatType& other); 88 FormatType& operator=(const FormatType& other);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 static Clipboard* GetForCurrentThread(); 189 static Clipboard* GetForCurrentThread();
189 190
190 // Destroys the clipboard for the current thread. Usually, this will clean up 191 // Destroys the clipboard for the current thread. Usually, this will clean up
191 // all clipboards, except on Windows. (Previous code leaks the IO thread 192 // all clipboards, except on Windows. (Previous code leaks the IO thread
192 // clipboard, so it shouldn't be a problem.) 193 // clipboard, so it shouldn't be a problem.)
193 static void DestroyClipboardForCurrentThread(); 194 static void DestroyClipboardForCurrentThread();
194 195
195 // Returns a sequence number which uniquely identifies clipboard state. 196 // Returns a sequence number which uniquely identifies clipboard state.
196 // This can be used to version the data on the clipboard and determine 197 // This can be used to version the data on the clipboard and determine
197 // whether it has changed. 198 // whether it has changed.
198 virtual uint64 GetSequenceNumber(ClipboardType type) = 0; 199 virtual uint64 GetSequenceNumber(ClipboardType type) const = 0;
199 200
200 // Tests whether the clipboard contains a certain format 201 // Tests whether the clipboard contains a certain format
201 virtual bool IsFormatAvailable(const FormatType& format, 202 virtual bool IsFormatAvailable(const FormatType& format,
202 ClipboardType type) const = 0; 203 ClipboardType type) const = 0;
203 204
204 // Clear the clipboard data. 205 // Clear the clipboard data.
205 virtual void Clear(ClipboardType type) = 0; 206 virtual void Clear(ClipboardType type) = 0;
206 207
207 virtual void ReadAvailableTypes(ClipboardType type, 208 virtual void ReadAvailableTypes(ClipboardType type,
208 std::vector<base::string16>* types, 209 std::vector<base::string16>* types,
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 const char* data_data, 319 const char* data_data,
319 size_t data_len) = 0; 320 size_t data_len) = 0;
320 321
321 private: 322 private:
322 template <typename T> 323 template <typename T>
323 friend class ClipboardTest; 324 friend class ClipboardTest;
324 // For access to WriteObjects(). 325 // For access to WriteObjects().
325 // TODO(dcheng): Remove the temporary exception for content. 326 // TODO(dcheng): Remove the temporary exception for content.
326 friend class content::ClipboardMessageFilter; 327 friend class content::ClipboardMessageFilter;
327 friend class ScopedClipboardWriter; 328 friend class ScopedClipboardWriter;
329 friend class TestClipboard;
330
331 // A list of allowed threads. By default, this is empty and no thread checking
332 // is done (in the unit test case), but a user (like content) can set which
333 // threads are allowed to call this method.
334 typedef std::vector<base::PlatformThreadId> AllowedThreadsVector;
335 static base::LazyInstance<AllowedThreadsVector> allowed_threads_;
336
337 // Mapping from threads to clipboard objects.
338 typedef std::map<base::PlatformThreadId, Clipboard*> ClipboardMap;
339 static base::LazyInstance<ClipboardMap> clipboard_map_;
340
341 // Mutex that controls access to |g_clipboard_map|.
342 static base::LazyInstance<base::Lock>::Leaky clipboard_map_lock_;
328 343
329 DISALLOW_COPY_AND_ASSIGN(Clipboard); 344 DISALLOW_COPY_AND_ASSIGN(Clipboard);
330 }; 345 };
331 346
332 } // namespace ui 347 } // namespace ui
333 348
334 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_ 349 #endif // UI_BASE_CLIPBOARD_CLIPBOARD_H_
OLDNEW
« no previous file with comments | « ui/base/BUILD.gn ('k') | ui/base/clipboard/clipboard.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698