Commit c1eec15b authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

ClipboardNonBacked: Remove unused versioning support.

Removed unused versioning support in ClipboardInternal. This allowed for
multiple ClipboardData items on a clipboard stack, but the stack size
was limited to 1, and no logic existed to exercise use of any stack
items except the top item on the stack. Therefore, this essentially
amounted to extra logic that wasn't actually needed or used.

Versioning support has been available since at least 2012, when
https://crrev.com/10829341 first introduced this file as a "sketch of
a clipboard implementation for linux_aura".

Change-Id: I7615a97bdd4ef038b0684c75536d2417d746bffe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309549
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790406}
parent 519d03fe
...@@ -33,14 +33,8 @@ ...@@ -33,14 +33,8 @@
namespace ui { namespace ui {
namespace {
const size_t kMaxClipboardSize = 1;
} // namespace
// Simple, internal implementation of a clipboard, handling things like format // Simple, internal implementation of a clipboard, handling things like format
// conversion, versioning, etc. // conversion, sequence numbers, etc.
class ClipboardInternal { class ClipboardInternal {
public: public:
ClipboardInternal() = default; ClipboardInternal() = default;
...@@ -48,41 +42,35 @@ class ClipboardInternal { ...@@ -48,41 +42,35 @@ class ClipboardInternal {
~ClipboardInternal() = default; ~ClipboardInternal() = default;
void Clear() { void Clear() {
sequence_number_++; ++sequence_number_;
data_list_.clear(); data_.reset();
ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged();
} }
uint64_t sequence_number() const { return sequence_number_; } uint64_t sequence_number() const { return sequence_number_; }
// Returns the data currently on the top of the clipboard stack, nullptr if // Returns the current clipboard data, which may be nullptr if nothing has
// the clipboard stack is empty. // been written since the last Clear().
const ClipboardData* GetData() const { const ClipboardData* GetData() const { return data_.get(); }
if (data_list_.empty())
return nullptr;
return data_list_.front().get();
}
// Returns true if the data on top of the clipboard stack has format |format| // Returns true if the data on top of the clipboard stack has format |format|
// or another format that can be converted to |format|. // or another format that can be converted to |format|.
bool IsFormatAvailable(ClipboardInternalFormat format) const { bool IsFormatAvailable(ClipboardInternalFormat format) const {
switch (format) { if (format == ClipboardInternalFormat::kText) {
case ClipboardInternalFormat::kText: return HasFormat(ClipboardInternalFormat::kText) ||
return HasFormat(ClipboardInternalFormat::kText) || HasFormat(ClipboardInternalFormat::kBookmark);
HasFormat(ClipboardInternalFormat::kBookmark);
default:
return HasFormat(format);
} }
return HasFormat(format);
} }
// Reads text from the data at the top of clipboard stack. // Reads text from the ClipboardData.
void ReadText(base::string16* result) const { void ReadText(base::string16* result) const {
std::string utf8_result; std::string utf8_result;
ReadAsciiText(&utf8_result); ReadAsciiText(&utf8_result);
*result = base::UTF8ToUTF16(utf8_result); *result = base::UTF8ToUTF16(utf8_result);
} }
// Reads ASCII text from the data at the top of clipboard stack. // Reads ASCII text from the ClipboardData.
void ReadAsciiText(std::string* result) const { void ReadAsciiText(std::string* result) const {
result->clear(); result->clear();
const ClipboardData* data = GetData(); const ClipboardData* data = GetData();
...@@ -96,7 +84,7 @@ class ClipboardInternal { ...@@ -96,7 +84,7 @@ class ClipboardInternal {
*result = data->bookmark_url(); *result = data->bookmark_url();
} }
// Reads HTML from the data at the top of clipboard stack. // Reads HTML from the ClipboardData.
void ReadHTML(base::string16* markup, void ReadHTML(base::string16* markup,
std::string* src_url, std::string* src_url,
uint32_t* fragment_start, uint32_t* fragment_start,
...@@ -119,7 +107,7 @@ class ClipboardInternal { ...@@ -119,7 +107,7 @@ class ClipboardInternal {
*fragment_end = static_cast<uint32_t>(markup->length()); *fragment_end = static_cast<uint32_t>(markup->length());
} }
// Reads RTF from the data at the top of clipboard stack. // Reads RTF from the ClipboardData.
void ReadRTF(std::string* result) const { void ReadRTF(std::string* result) const {
result->clear(); result->clear();
const ClipboardData* data = GetData(); const ClipboardData* data = GetData();
...@@ -129,7 +117,7 @@ class ClipboardInternal { ...@@ -129,7 +117,7 @@ class ClipboardInternal {
*result = data->rtf_data(); *result = data->rtf_data();
} }
// Reads image from the data at the top of clipboard stack. // Reads image from the ClipboardData.
SkBitmap ReadImage() const { SkBitmap ReadImage() const {
SkBitmap img; SkBitmap img;
if (!HasFormat(ClipboardInternalFormat::kBitmap)) if (!HasFormat(ClipboardInternalFormat::kBitmap))
...@@ -144,7 +132,7 @@ class ClipboardInternal { ...@@ -144,7 +132,7 @@ class ClipboardInternal {
return img; return img;
} }
// Reads data of type |type| from the data at the top of clipboard stack. // Reads data of type |type| from the ClipboardData.
void ReadCustomData(const base::string16& type, void ReadCustomData(const base::string16& type,
base::string16* result) const { base::string16* result) const {
result->clear(); result->clear();
...@@ -156,7 +144,7 @@ class ClipboardInternal { ...@@ -156,7 +144,7 @@ class ClipboardInternal {
data->custom_data_data().size(), type, result); data->custom_data_data().size(), type, result);
} }
// Reads bookmark from the data at the top of clipboard stack. // Reads bookmark from the ClipboardData.
void ReadBookmark(base::string16* title, std::string* url) const { void ReadBookmark(base::string16* title, std::string* url) const {
if (title) if (title)
title->clear(); title->clear();
...@@ -182,10 +170,11 @@ class ClipboardInternal { ...@@ -182,10 +170,11 @@ class ClipboardInternal {
*result = data->custom_data_data(); *result = data->custom_data_data();
} }
// Writes |data| to the top of the clipboard stack. // Writes |data| to the ClipboardData.
void WriteData(std::unique_ptr<ClipboardData> data) { void WriteData(std::unique_ptr<ClipboardData> data) {
DCHECK(data); DCHECK(data);
AddToListEnsuringSize(std::move(data)); ++sequence_number_;
data_ = std::move(data);
ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged(); ClipboardMonitor::GetInstance()->NotifyClipboardDataChanged();
} }
...@@ -201,26 +190,14 @@ class ClipboardInternal { ...@@ -201,26 +190,14 @@ class ClipboardInternal {
} }
private: private:
// True if the data on top of the clipboard stack has format |format|. // True if the ClipboardData has format |format|.
bool HasFormat(ClipboardInternalFormat format) const { bool HasFormat(ClipboardInternalFormat format) const {
const ClipboardData* data = GetData(); const ClipboardData* data = GetData();
return data ? data->format() & static_cast<int>(format) : false; return data ? data->format() & static_cast<int>(format) : false;
} }
void AddToListEnsuringSize(std::unique_ptr<ClipboardData> data) { // Current ClipboardData.
DCHECK(data); std::unique_ptr<ClipboardData> data_;
sequence_number_++;
data_list_.push_front(std::move(data));
// If the size of list becomes more than the maximum allowed, we delete the
// last element.
if (data_list_.size() > kMaxClipboardSize) {
data_list_.pop_back();
}
}
// Stack containing various versions of ClipboardData.
std::list<std::unique_ptr<ClipboardData>> data_list_;
// Sequence number uniquely identifying clipboard state. // Sequence number uniquely identifying clipboard state.
uint64_t sequence_number_ = 0; uint64_t sequence_number_ = 0;
......
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