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 "remoting/host/clipboard.h" | 5 #include "remoting/host/clipboard.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
| 11 |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/macros.h" | 13 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/ptr_util.h" |
13 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
14 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
15 #include "remoting/base/constants.h" | 17 #include "remoting/base/constants.h" |
16 #include "remoting/base/util.h" | 18 #include "remoting/base/util.h" |
17 #include "remoting/proto/event.pb.h" | 19 #include "remoting/proto/event.pb.h" |
18 #include "remoting/protocol/clipboard_stub.h" | 20 #include "remoting/protocol/clipboard_stub.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 // Clipboard polling interval in milliseconds. | 24 // Clipboard polling interval in milliseconds. |
23 const int64_t kClipboardPollingIntervalMs = 500; | 25 const int64_t kClipboardPollingIntervalMs = 500; |
24 | 26 |
25 } // namespace | 27 } // namespace |
26 | 28 |
27 namespace remoting { | 29 namespace remoting { |
28 | 30 |
29 class ClipboardMac : public Clipboard { | 31 class ClipboardMac : public Clipboard { |
30 public: | 32 public: |
31 ClipboardMac(); | 33 ClipboardMac(); |
32 ~ClipboardMac() override; | 34 ~ClipboardMac() override; |
33 | 35 |
34 void Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) override; | 36 void Start( |
| 37 std::unique_ptr<protocol::ClipboardStub> client_clipboard) override; |
35 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; | 38 void InjectClipboardEvent(const protocol::ClipboardEvent& event) override; |
36 | 39 |
37 private: | 40 private: |
38 void CheckClipboardForChanges(); | 41 void CheckClipboardForChanges(); |
39 | 42 |
40 scoped_ptr<protocol::ClipboardStub> client_clipboard_; | 43 std::unique_ptr<protocol::ClipboardStub> client_clipboard_; |
41 scoped_ptr<base::RepeatingTimer> clipboard_polling_timer_; | 44 std::unique_ptr<base::RepeatingTimer> clipboard_polling_timer_; |
42 NSInteger current_change_count_; | 45 NSInteger current_change_count_; |
43 | 46 |
44 DISALLOW_COPY_AND_ASSIGN(ClipboardMac); | 47 DISALLOW_COPY_AND_ASSIGN(ClipboardMac); |
45 }; | 48 }; |
46 | 49 |
47 ClipboardMac::ClipboardMac() : current_change_count_(0) {} | 50 ClipboardMac::ClipboardMac() : current_change_count_(0) {} |
48 | 51 |
49 ClipboardMac::~ClipboardMac() {} | 52 ClipboardMac::~ClipboardMac() {} |
50 | 53 |
51 void ClipboardMac::Start(scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 54 void ClipboardMac::Start( |
| 55 std::unique_ptr<protocol::ClipboardStub> client_clipboard) { |
52 client_clipboard_.reset(client_clipboard.release()); | 56 client_clipboard_.reset(client_clipboard.release()); |
53 | 57 |
54 // Synchronize local change-count with the pasteboard's. The change-count is | 58 // Synchronize local change-count with the pasteboard's. The change-count is |
55 // used to detect clipboard changes. | 59 // used to detect clipboard changes. |
56 current_change_count_ = [[NSPasteboard generalPasteboard] changeCount]; | 60 current_change_count_ = [[NSPasteboard generalPasteboard] changeCount]; |
57 | 61 |
58 // OS X doesn't provide a clipboard-changed notification. The only way to | 62 // OS X doesn't provide a clipboard-changed notification. The only way to |
59 // detect clipboard changes is by polling. | 63 // detect clipboard changes is by polling. |
60 clipboard_polling_timer_.reset(new base::RepeatingTimer()); | 64 clipboard_polling_timer_.reset(new base::RepeatingTimer()); |
61 clipboard_polling_timer_->Start(FROM_HERE, | 65 clipboard_polling_timer_->Start(FROM_HERE, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (data == nil) { | 100 if (data == nil) { |
97 return; | 101 return; |
98 } | 102 } |
99 | 103 |
100 protocol::ClipboardEvent event; | 104 protocol::ClipboardEvent event; |
101 event.set_mime_type(kMimeTypeTextUtf8); | 105 event.set_mime_type(kMimeTypeTextUtf8); |
102 event.set_data(base::SysNSStringToUTF8(data)); | 106 event.set_data(base::SysNSStringToUTF8(data)); |
103 client_clipboard_->InjectClipboardEvent(event); | 107 client_clipboard_->InjectClipboardEvent(event); |
104 } | 108 } |
105 | 109 |
106 scoped_ptr<Clipboard> Clipboard::Create() { | 110 std::unique_ptr<Clipboard> Clipboard::Create() { |
107 return make_scoped_ptr(new ClipboardMac()); | 111 return base::WrapUnique(new ClipboardMac()); |
108 } | 112 } |
109 | 113 |
110 } // namespace remoting | 114 } // namespace remoting |
OLD | NEW |