summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 21:58:18 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 21:58:18 +0000
commit8c3dc79bc13ba84f418d3c135e1bf296a3e29722 (patch)
tree32eb9688d500a90eb74a7c4f8cb5a97e507dd0fc /chrome/browser/bookmarks
parentabaccb2cb8cff8138e5ea9daf420645e5852c9eb (diff)
downloadchromium_src-8c3dc79bc13ba84f418d3c135e1bf296a3e29722.zip
chromium_src-8c3dc79bc13ba84f418d3c135e1bf296a3e29722.tar.gz
chromium_src-8c3dc79bc13ba84f418d3c135e1bf296a3e29722.tar.bz2
Refactors OSExchangeData for easier portability.
BUG=none TEST=none Review URL: http://codereview.chromium.org/164401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23230 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu_controller.cc2
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu_controller.h1
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.cc56
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data.h11
-rw-r--r--chrome/browser/bookmarks/bookmark_drag_data_unittest.cc54
5 files changed, 63 insertions, 61 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc
index 4f6d941..81fbcc9 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc
+++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/views/bookmark_context_menu.h"
+#include "chrome/browser/bookmarks/bookmark_context_menu_controller.h"
#include "app/l10n_util.h"
#include "base/compiler_specific.h"
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.h b/chrome/browser/bookmarks/bookmark_context_menu_controller.h
index 4d611d8..03a57c4 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu_controller.h
+++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.h
@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "base/gfx/native_widget_types.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "views/controls/menu/chrome_menu.h"
class Browser;
class PageNavigator;
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.cc b/chrome/browser/bookmarks/bookmark_drag_data.cc
index 0ed2273..47ea0c0 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data.cc
@@ -13,29 +13,9 @@
#include "chrome/common/url_constants.h"
#include "chrome/browser/browser_process.h"
-// TODO(port): Port this file.
-#if defined(TOOLKIT_VIEWS)
-#include "app/os_exchange_data.h"
-#else
-#include "chrome/common/temp_scaffolding_stubs.h"
-#endif
-
const char* BookmarkDragData::kClipboardFormatString =
"chromium/x-bookmark-entries";
-#if defined(OS_WIN)
-static CLIPFORMAT clipboard_format = 0;
-
-static void RegisterFormat() {
- if (clipboard_format == 0) {
- clipboard_format =
- ::RegisterClipboardFormat(ASCIIToWide(
- BookmarkDragData::kClipboardFormatString).c_str());
- DCHECK(clipboard_format);
- }
-}
-#endif
-
BookmarkDragData::Element::Element(const BookmarkNode* node)
: is_url(node->is_url()),
url(node->GetURL()),
@@ -84,6 +64,21 @@ bool BookmarkDragData::Element::ReadFromPickle(Pickle* pickle,
return true;
}
+#if defined(TOOLKIT_VIEWS)
+// static
+OSExchangeData::CustomFormat BookmarkDragData::GetBookmarkCustomFormat() {
+ static OSExchangeData::CustomFormat format;
+ static bool format_valid = false;
+
+ if (!format_valid) {
+ format_valid = true;
+ format = OSExchangeData::RegisterCustomFormat(
+ BookmarkDragData::kClipboardFormatString);
+ }
+ return format;
+}
+#endif
+
BookmarkDragData::BookmarkDragData(const BookmarkNode* node) {
elements.push_back(Element(node));
}
@@ -139,10 +134,8 @@ bool BookmarkDragData::ReadFromClipboard() {
}
#endif // !defined(OS_MACOSX)
-#if defined(OS_WIN)
+#if defined(TOOLKIT_VIEWS)
void BookmarkDragData::Write(Profile* profile, OSExchangeData* data) const {
- RegisterFormat();
-
DCHECK(data);
// If there is only one element and it is a URL, write the URL to the
@@ -158,19 +151,17 @@ void BookmarkDragData::Write(Profile* profile, OSExchangeData* data) const {
Pickle data_pickle;
WriteToPickle(profile, &data_pickle);
- data->SetPickledData(clipboard_format, data_pickle);
+ data->SetPickledData(GetBookmarkCustomFormat(), data_pickle);
}
bool BookmarkDragData::Read(const OSExchangeData& data) {
- RegisterFormat();
-
elements.clear();
profile_path_.clear();
- if (data.HasFormat(clipboard_format)) {
+ if (data.HasCustomFormat(GetBookmarkCustomFormat())) {
Pickle drag_data_pickle;
- if (data.GetPickledData(clipboard_format, &drag_data_pickle)) {
+ if (data.GetPickledData(GetBookmarkCustomFormat(), &drag_data_pickle)) {
if (!ReadFromPickle(&drag_data_pickle))
return false;
}
@@ -186,15 +177,6 @@ bool BookmarkDragData::Read(const OSExchangeData& data) {
return is_valid();
}
-#elif defined(TOOLKIT_VIEWS)
-void BookmarkDragData::Write(Profile* profile, OSExchangeData* data) const {
- NOTIMPLEMENTED();
-}
-
-bool BookmarkDragData::Read(const OSExchangeData& data) {
- NOTIMPLEMENTED();
- return false;
-}
#endif
void BookmarkDragData::WriteToPickle(Profile* profile, Pickle* pickle) const {
diff --git a/chrome/browser/bookmarks/bookmark_drag_data.h b/chrome/browser/bookmarks/bookmark_drag_data.h
index 815e8e1d..0b9736c 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data.h
+++ b/chrome/browser/bookmarks/bookmark_drag_data.h
@@ -11,6 +11,13 @@
#include "chrome/browser/history/history.h"
#include "googleurl/src/gurl.h"
+// TODO(port): Port this file.
+#if defined(TOOLKIT_VIEWS)
+#include "app/os_exchange_data.h"
+#else
+#include "chrome/common/temp_scaffolding_stubs.h"
+#endif
+
class BookmarkModel;
class BookmarkNode;
class OSExchangeData;
@@ -67,6 +74,10 @@ struct BookmarkDragData {
BookmarkDragData() { }
+#if defined(TOOLKIT_VIEWS)
+ static OSExchangeData::CustomFormat GetBookmarkCustomFormat();
+#endif
+
// Created a BookmarkDragData populated from the arguments.
explicit BookmarkDragData(const BookmarkNode* node);
explicit BookmarkDragData(const std::vector<const BookmarkNode*>& nodes);
diff --git a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
index 02b2016..77d999a 100644
--- a/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_drag_data_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "app/os_exchange_data.h"
+#include "app/os_exchange_data_provider_win.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/bookmarks/bookmark_drag_data.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
@@ -12,6 +13,15 @@
typedef testing::Test BookmarkDragDataTest;
+namespace {
+
+OSExchangeData::Provider* CloneProvider(const OSExchangeData& data) {
+ return new OSExchangeDataProviderWin(
+ OSExchangeDataProviderWin::GetIDataObject(data));
+}
+
+} // namespace
+
// Makes sure BookmarkDragData is initially invalid.
TEST_F(BookmarkDragDataTest, InitialState) {
BookmarkDragData data;
@@ -20,9 +30,9 @@ TEST_F(BookmarkDragDataTest, InitialState) {
// Makes sure reading bogus data leaves the BookmarkDragData invalid.
TEST_F(BookmarkDragDataTest, BogusRead) {
- scoped_refptr<OSExchangeData> data(new OSExchangeData());
+ OSExchangeData data;
BookmarkDragData drag_data;
- EXPECT_FALSE(drag_data.Read(OSExchangeData(data.get())));
+ EXPECT_FALSE(drag_data.Read(OSExchangeData(CloneProvider(data))));
EXPECT_FALSE(drag_data.is_valid());
}
@@ -32,11 +42,11 @@ TEST_F(BookmarkDragDataTest, JustURL) {
const GURL url("http://google.com");
const std::wstring title(L"title");
- scoped_refptr<OSExchangeData> data(new OSExchangeData());
- data->SetURL(url, title);
+ OSExchangeData data;
+ data.SetURL(url, title);
BookmarkDragData drag_data;
- EXPECT_TRUE(drag_data.Read(OSExchangeData(data.get())));
+ EXPECT_TRUE(drag_data.Read(OSExchangeData(CloneProvider(data))));
EXPECT_TRUE(drag_data.is_valid());
ASSERT_EQ(1, drag_data.elements.size());
EXPECT_TRUE(drag_data.elements[0].is_url);
@@ -61,13 +71,13 @@ TEST_F(BookmarkDragDataTest, URL) {
EXPECT_TRUE(drag_data.elements[0].is_url);
EXPECT_TRUE(drag_data.elements[0].url == url);
EXPECT_EQ(title, drag_data.elements[0].title);
- scoped_refptr<OSExchangeData> data(new OSExchangeData());
- drag_data.Write(&profile, data.get());
+ OSExchangeData data;
+ drag_data.Write(&profile, &data);
// Now read the data back in.
- scoped_refptr<OSExchangeData> data2(new OSExchangeData(data.get()));
+ OSExchangeData data2(CloneProvider(data));
BookmarkDragData read_data;
- EXPECT_TRUE(read_data.Read(*data2));
+ EXPECT_TRUE(read_data.Read(data2));
EXPECT_TRUE(read_data.is_valid());
ASSERT_EQ(1, read_data.elements.size());
EXPECT_TRUE(read_data.elements[0].is_url);
@@ -82,7 +92,7 @@ TEST_F(BookmarkDragDataTest, URL) {
// Writing should also put the URL and title on the clipboard.
GURL read_url;
std::wstring read_title;
- EXPECT_TRUE(data2->GetURLAndTitle(&read_url, &read_title));
+ EXPECT_TRUE(data2.GetURLAndTitle(&read_url, &read_title));
EXPECT_TRUE(read_url == url);
EXPECT_EQ(title, read_title);
}
@@ -104,13 +114,13 @@ TEST_F(BookmarkDragDataTest, Group) {
EXPECT_EQ(g12->GetTitle(), drag_data.elements[0].title);
EXPECT_FALSE(drag_data.elements[0].is_url);
- scoped_refptr<OSExchangeData> data(new OSExchangeData());
- drag_data.Write(&profile, data.get());
+ OSExchangeData data;
+ drag_data.Write(&profile, &data);
// Now read the data back in.
- scoped_refptr<OSExchangeData> data2(new OSExchangeData(data.get()));
+ OSExchangeData data2(CloneProvider(data));
BookmarkDragData read_data;
- EXPECT_TRUE(read_data.Read(*data2));
+ EXPECT_TRUE(read_data.Read(data2));
EXPECT_TRUE(read_data.is_valid());
ASSERT_EQ(1, read_data.elements.size());
EXPECT_EQ(g12->GetTitle(), read_data.elements[0].title);
@@ -141,13 +151,13 @@ TEST_F(BookmarkDragDataTest, GroupWithChild) {
BookmarkDragData drag_data(group);
- scoped_refptr<OSExchangeData> data(new OSExchangeData());
- drag_data.Write(&profile, data.get());
+ OSExchangeData data;
+ drag_data.Write(&profile, &data);
// Now read the data back in.
- scoped_refptr<OSExchangeData> data2(new OSExchangeData(data.get()));
+ OSExchangeData data2(CloneProvider(data));
BookmarkDragData read_data;
- EXPECT_TRUE(read_data.Read(*data2));
+ EXPECT_TRUE(read_data.Read(data2));
ASSERT_EQ(1, read_data.elements.size());
ASSERT_EQ(1, read_data.elements[0].children.size());
const BookmarkDragData::Element& read_child =
@@ -182,13 +192,13 @@ TEST_F(BookmarkDragDataTest, MultipleNodes) {
nodes.push_back(group);
nodes.push_back(url_node);
BookmarkDragData drag_data(nodes);
- scoped_refptr<OSExchangeData> data(new OSExchangeData());
- drag_data.Write(&profile, data.get());
+ OSExchangeData data;
+ drag_data.Write(&profile, &data);
// Read the data back in.
- scoped_refptr<OSExchangeData> data2(new OSExchangeData(data.get()));
+ OSExchangeData data2(CloneProvider(data));
BookmarkDragData read_data;
- EXPECT_TRUE(read_data.Read(*data2));
+ EXPECT_TRUE(read_data.Read(data2));
EXPECT_TRUE(read_data.is_valid());
ASSERT_EQ(2, read_data.elements.size());
ASSERT_EQ(1, read_data.elements[0].children.size());