Commit 1a95a175 authored by dcheng@chromium.org's avatar dcheng@chromium.org

Remove Task inheritance in clipboard code.

In one instance, we can simply use currying to remove the need to
inherit from Task; in the other, we retain the wrapper since it wraps an
Objective-C call. Also remove an overload of ui::Clipboard::WriteObjects
that's never used.

BUG=none
TEST=trybots


Review URL: http://codereview.chromium.org/8606002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111080 0039d316-1c4b-4281-b951-d872f2087c98
parent 5c5517c3
......@@ -11,6 +11,7 @@
#endif
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "content/common/clipboard_messages.h"
#include "content/public/browser/content_browser_client.h"
......@@ -24,24 +25,12 @@ using content::BrowserThread;
namespace {
// Completes a clipboard write initiated by the renderer. The write must be
// performed on the UI thread because the clipboard service from the IO thread
// cannot create windows so it cannot be the "owner" of the clipboard's
// contents.
class WriteClipboardTask : public Task {
public:
explicit WriteClipboardTask(ui::Clipboard::ObjectMap* objects)
: objects_(objects) {}
~WriteClipboardTask() {}
void Run() {
content::GetContentClient()->browser()->GetClipboard()->WriteObjects(
*objects_.get());
}
private:
scoped_ptr<ui::Clipboard::ObjectMap> objects_;
};
// This helper is needed because content::ContentBrowserClient::GetClipboard()
// must be called on the UI thread.
void WriteObjectsHelper(const ui::Clipboard::ObjectMap* objects) {
content::GetContentClient()->browser()->GetClipboard()->WriteObjects(
*objects);
}
} // namespace
......@@ -104,7 +93,7 @@ void ClipboardMessageFilter::OnWriteObjectsSync(
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
new WriteClipboardTask(long_living_objects));
base::Bind(&WriteObjectsHelper, base::Owned(long_living_objects)));
}
void ClipboardMessageFilter::OnWriteObjectsAsync(
......@@ -122,7 +111,7 @@ void ClipboardMessageFilter::OnWriteObjectsAsync(
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
new WriteClipboardTask(long_living_objects));
base::Bind(&WriteObjectsHelper, base::Owned(long_living_objects)));
}
void ClipboardMessageFilter::OnGetSequenceNumber(
......
......@@ -6,20 +6,25 @@
#import <Cocoa/Cocoa.h>
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/sys_string_conversions.h"
#import "content/browser/find_pasteboard.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
namespace {
// The number of utf16 code units that will be written to the find pasteboard,
// longer texts are silently ignored. This is to prevent that a compromised
// renderer can write unlimited amounts of data into the find pasteboard.
static const size_t kMaxFindPboardStringLength = 4096;
class WriteFindPboardTask : public Task {
class WriteFindPboardWrapper {
public:
explicit WriteFindPboardTask(NSString* text)
explicit WriteFindPboardWrapper(NSString* text)
: text_([text retain]) {}
void Run() {
......@@ -28,8 +33,12 @@ class WriteFindPboardTask : public Task {
private:
scoped_nsobject<NSString> text_;
DISALLOW_COPY_AND_ASSIGN(WriteFindPboardWrapper);
};
} // namespace
// Called on the IO thread.
void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) {
if (text.length() <= kMaxFindPboardStringLength) {
......@@ -37,7 +46,9 @@ void ClipboardMessageFilter::OnFindPboardWriteString(const string16& text) {
if (nsText) {
// FindPasteboard must be used on the UI thread.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, new WriteFindPboardTask(nsText));
BrowserThread::UI, FROM_HERE, base::Bind(
&WriteFindPboardWrapper::Run,
base::Owned(new WriteFindPboardWrapper(nsText))));
}
}
}
......@@ -116,12 +116,6 @@ class UI_EXPORT Clipboard {
// kept until the system clipboard is set again.
void WriteObjects(const ObjectMap& objects);
// Behaves as above. If there is some shared memory handle passed as one of
// the objects, it came from the process designated by |process|. This will
// assist in turning it into a shared memory region that the current process
// can use.
void WriteObjects(const ObjectMap& objects, base::ProcessHandle process);
// On Linux/BSD, we need to know when the clipboard is set to a URL. Most
// platforms don't care.
#if defined(OS_WIN) || defined(OS_MACOSX) || defined(USE_AURA)
......
......@@ -55,7 +55,6 @@ void Clipboard::WriteObjects(const ObjectMap& objects) {
iter != objects.end(); ++iter) {
DispatchObject(static_cast<ObjectType>(iter->first), iter->second);
}
}
void Clipboard::WriteText(const char* text_data, size_t text_len) {
......
......@@ -180,11 +180,6 @@ Clipboard::~Clipboard() {
}
void Clipboard::WriteObjects(const ObjectMap& objects) {
WriteObjects(objects, NULL);
}
void Clipboard::WriteObjects(const ObjectMap& objects,
base::ProcessHandle process) {
ScopedClipboard clipboard;
if (!clipboard.Acquire(GetClipboardWindow()))
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment