diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-17 17:20:00 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-17 17:20:00 +0000 |
commit | ea8c56cdad5c7f8e2bf66ae7427dae786a8f82e5 (patch) | |
tree | ed031a71121631e75587cc9257d1f60e493d1dcc /chrome/browser | |
parent | 2eebec6c346b44a6f195f9e6ca15dc7feeeea766 (diff) | |
download | chromium_src-ea8c56cdad5c7f8e2bf66ae7427dae786a8f82e5.zip chromium_src-ea8c56cdad5c7f8e2bf66ae7427dae786a8f82e5.tar.gz chromium_src-ea8c56cdad5c7f8e2bf66ae7427dae786a8f82e5.tar.bz2 |
bookmarks: Change the interface of BookmarkNodeData.
Change it to take a pointer to BookmarkModel and the file path to the
profile.
BUG=360621
TEST=unit_tests --gtest_filter=BookmarkNodeDataTest.*
R=sky@chromium.org,droger@chromium.org,sdefresne@chromium.org
TBR=sky
Review URL: https://codereview.chromium.org/239153009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264554 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
14 files changed, 93 insertions, 68 deletions
diff --git a/chrome/browser/bookmarks/bookmark_node_data.cc b/chrome/browser/bookmarks/bookmark_node_data.cc index 6bfed46..dda7111 100644 --- a/chrome/browser/bookmarks/bookmark_node_data.cc +++ b/chrome/browser/bookmarks/bookmark_node_data.cc @@ -11,8 +11,6 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/bookmarks/bookmark_model_factory.h" -#include "chrome/browser/profiles/profile.h" #include "ui/base/clipboard/scoped_clipboard_writer.h" const char* BookmarkNodeData::kClipboardFormatString = @@ -180,7 +178,7 @@ void BookmarkNodeData::WriteToClipboard(ui::ClipboardType clipboard_type) { } Pickle pickle; - WriteToPickle(NULL, &pickle); + WriteToPickle(base::FilePath(), &pickle); scw.WritePickledData(pickle, ui::Clipboard::GetFormatType(kClipboardFormatString)); } @@ -216,9 +214,9 @@ bool BookmarkNodeData::ReadFromClipboard(ui::ClipboardType type) { } #endif -void BookmarkNodeData::WriteToPickle(Profile* profile, Pickle* pickle) const { - base::FilePath path = profile ? profile->GetPath() : base::FilePath(); - path.WriteToPickle(pickle); +void BookmarkNodeData::WriteToPickle(const base::FilePath& profile_path, + Pickle* pickle) const { + profile_path.WriteToPickle(pickle); pickle->WriteUInt64(elements.size()); for (size_t i = 0; i < elements.size(); ++i) @@ -244,15 +242,15 @@ bool BookmarkNodeData::ReadFromPickle(Pickle* pickle) { } std::vector<const BookmarkNode*> BookmarkNodeData::GetNodes( - Profile* profile) const { + BookmarkModel* model, + const base::FilePath& profile_path) const { std::vector<const BookmarkNode*> nodes; - if (!IsFromProfile(profile)) + if (!IsFromProfilePath(profile_path)) return nodes; for (size_t i = 0; i < elements.size(); ++i) { - const BookmarkNode* node = BookmarkModelFactory::GetForProfile( - profile)->GetNodeByID(elements[i].id_); + const BookmarkNode* node = model->GetNodeByID(elements[i].id_); if (!node) { nodes.clear(); return nodes; @@ -262,8 +260,10 @@ std::vector<const BookmarkNode*> BookmarkNodeData::GetNodes( return nodes; } -const BookmarkNode* BookmarkNodeData::GetFirstNode(Profile* profile) const { - std::vector<const BookmarkNode*> nodes = GetNodes(profile); +const BookmarkNode* BookmarkNodeData::GetFirstNode( + BookmarkModel* model, + const base::FilePath& profile_path) const { + std::vector<const BookmarkNode*> nodes = GetNodes(model, profile_path); return nodes.size() == 1 ? nodes[0] : NULL; } @@ -272,14 +272,14 @@ void BookmarkNodeData::Clear() { elements.clear(); } -void BookmarkNodeData::SetOriginatingProfile(Profile* profile) { +void BookmarkNodeData::SetOriginatingProfilePath( + const base::FilePath& profile_path) { DCHECK(profile_path_.empty()); - - if (profile) - profile_path_ = profile->GetPath(); + profile_path_ = profile_path; } -bool BookmarkNodeData::IsFromProfile(Profile* profile) const { +bool BookmarkNodeData::IsFromProfilePath( + const base::FilePath& profile_path) const { // An empty path means the data is not associated with any profile. - return !profile_path_.empty() && profile_path_ == profile->GetPath(); + return !profile_path_.empty() && profile_path_ == profile_path; } diff --git a/chrome/browser/bookmarks/bookmark_node_data.h b/chrome/browser/bookmarks/bookmark_node_data.h index fbb975e..cc6564a 100644 --- a/chrome/browser/bookmarks/bookmark_node_data.h +++ b/chrome/browser/bookmarks/bookmark_node_data.h @@ -10,7 +10,7 @@ #include "base/files/file_path.h" #include "base/strings/string16.h" #include "base/time/time.h" -#include "chrome/browser/bookmarks/bookmark_model.h" +#include "components/bookmarks/core/browser/bookmark_node.h" #include "ui/base/clipboard/clipboard_types.h" #include "url/gurl.h" @@ -18,9 +18,9 @@ #include "ui/base/dragdrop/os_exchange_data.h" #endif +class BookmarkModel; class Pickle; class PickleIterator; -class Profile; // BookmarkNodeData is used to represent the following: // @@ -115,16 +115,17 @@ struct BookmarkNodeData { // Writes elements to data. If there is only one element and it is a URL // the URL and title are written to the clipboard in a format other apps can // use. - // |profile| is used to identify which profile the data came from. Use a - // value of null to indicate the data is not associated with any profile. - void Write(Profile* profile, ui::OSExchangeData* data) const; + // |profile_path| is used to identify which profile the data came from. Use an + // empty path to indicate that the data is not associated with any profile. + void Write(const base::FilePath& profile_path, + ui::OSExchangeData* data) const; // Restores this data from the clipboard, returning true on success. bool Read(const ui::OSExchangeData& data); #endif // Writes the data for a drag to |pickle|. - void WriteToPickle(Profile* profile, Pickle* pickle) const; + void WriteToPickle(const base::FilePath& profile_path, Pickle* pickle) const; // Reads the data for a drag from a |pickle|. bool ReadFromPickle(Pickle* pickle); @@ -133,11 +134,14 @@ struct BookmarkNodeData { // created from the same profile then the nodes from the model are returned. // If the nodes can't be found (may have been deleted), an empty vector is // returned. - std::vector<const BookmarkNode*> GetNodes(Profile* profile) const; + std::vector<const BookmarkNode*> GetNodes( + BookmarkModel* model, + const base::FilePath& profile_path) const; // Convenience for getting the first node. Returns NULL if the data doesn't // match any nodes or there is more than one node. - const BookmarkNode* GetFirstNode(Profile* profile) const; + const BookmarkNode* GetFirstNode(BookmarkModel* model, + const base::FilePath& profile_path) const; // Do we contain valid data? bool is_valid() const { return !elements.empty(); } @@ -151,13 +155,13 @@ struct BookmarkNodeData { // Clears the data. void Clear(); - // Sets |profile_path_| to that of |profile|. This is useful for the - // constructors/readers that don't set it. This should only be called if the - // profile path is not already set. - void SetOriginatingProfile(Profile* profile); + // Sets |profile_path_|. This is useful for the constructors/readers that + // don't set it. This should only be called if the profile path is not + // already set. + void SetOriginatingProfilePath(const base::FilePath& profile_path); - // Returns true if this data is from the specified profile. - bool IsFromProfile(Profile* profile) const; + // Returns true if this data is from the specified profile path. + bool IsFromProfilePath(const base::FilePath& profile_path) const; // The actual elements written to the clipboard. std::vector<Element> elements; diff --git a/chrome/browser/bookmarks/bookmark_node_data_unittest.cc b/chrome/browser/bookmarks/bookmark_node_data_unittest.cc index 774fbd7..ee10c49 100644 --- a/chrome/browser/bookmarks/bookmark_node_data_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_node_data_unittest.cc @@ -110,7 +110,7 @@ TEST_F(BookmarkNodeDataTest, URL) { EXPECT_EQ(node->date_folder_modified(), drag_data.elements[0].date_folder_modified); ui::OSExchangeData data; - drag_data.Write(profile(), &data); + drag_data.Write(profile()->GetPath(), &data); // Now read the data back in. ui::OSExchangeData data2(CloneProvider(data)); @@ -123,11 +123,11 @@ TEST_F(BookmarkNodeDataTest, URL) { EXPECT_EQ(title, read_data.elements[0].title); EXPECT_TRUE(read_data.elements[0].date_added.is_null()); EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); - EXPECT_TRUE(read_data.GetFirstNode(profile()) == node); + EXPECT_TRUE(read_data.GetFirstNode(model(), profile()->GetPath()) == node); // Make sure asking for the node with a different profile returns NULL. TestingProfile profile2; - EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL); + EXPECT_TRUE(read_data.GetFirstNode(model(), profile2.GetPath()) == NULL); // Writing should also put the URL and title on the clipboard. GURL read_url; @@ -155,7 +155,7 @@ TEST_F(BookmarkNodeDataTest, Folder) { drag_data.elements[0].date_folder_modified); ui::OSExchangeData data; - drag_data.Write(profile(), &data); + drag_data.Write(profile()->GetPath(), &data); // Now read the data back in. ui::OSExchangeData data2(CloneProvider(data)); @@ -169,12 +169,13 @@ TEST_F(BookmarkNodeDataTest, Folder) { EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); // We should get back the same node when asking for the same profile. - const BookmarkNode* r_g12 = read_data.GetFirstNode(profile()); + const BookmarkNode* r_g12 = + read_data.GetFirstNode(model(), profile()->GetPath()); EXPECT_TRUE(g12 == r_g12); // A different profile should return NULL for the node. TestingProfile profile2; - EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL); + EXPECT_TRUE(read_data.GetFirstNode(model(), profile2.GetPath()) == NULL); } // Tests reading/writing a folder with children. @@ -190,7 +191,7 @@ TEST_F(BookmarkNodeDataTest, FolderWithChild) { BookmarkNodeData drag_data(folder); ui::OSExchangeData data; - drag_data.Write(profile(), &data); + drag_data.Write(profile()->GetPath(), &data); // Now read the data back in. ui::OSExchangeData data2(CloneProvider(data)); @@ -209,7 +210,8 @@ TEST_F(BookmarkNodeDataTest, FolderWithChild) { EXPECT_TRUE(read_child.is_url); // And make sure we get the node back. - const BookmarkNode* r_folder = read_data.GetFirstNode(profile()); + const BookmarkNode* r_folder = + read_data.GetFirstNode(model(), profile()->GetPath()); EXPECT_TRUE(folder == r_folder); } @@ -229,7 +231,7 @@ TEST_F(BookmarkNodeDataTest, MultipleNodes) { nodes.push_back(url_node); BookmarkNodeData drag_data(nodes); ui::OSExchangeData data; - drag_data.Write(profile(), &data); + drag_data.Write(profile()->GetPath(), &data); // Read the data back in. ui::OSExchangeData data2(CloneProvider(data)); @@ -252,14 +254,15 @@ TEST_F(BookmarkNodeDataTest, MultipleNodes) { EXPECT_EQ(0u, read_url.children.size()); // And make sure we get the node back. - std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(profile()); + std::vector<const BookmarkNode*> read_nodes = + read_data.GetNodes(model(), profile()->GetPath()); ASSERT_EQ(2u, read_nodes.size()); EXPECT_TRUE(read_nodes[0] == folder); EXPECT_TRUE(read_nodes[1] == url_node); // Asking for the first node should return NULL with more than one element // present. - EXPECT_TRUE(read_data.GetFirstNode(profile()) == NULL); + EXPECT_TRUE(read_data.GetFirstNode(model(), profile()->GetPath()) == NULL); } // Tests reading/writing of meta info. @@ -274,7 +277,7 @@ TEST_F(BookmarkNodeDataTest, MetaInfo) { BookmarkNodeData node_data(node); ui::OSExchangeData data; - node_data.Write(profile(), &data); + node_data.Write(profile()->GetPath(), &data); // Read the data back in. ui::OSExchangeData data2(CloneProvider(data)); diff --git a/chrome/browser/bookmarks/bookmark_node_data_views.cc b/chrome/browser/bookmarks/bookmark_node_data_views.cc index 4eddada..3625105 100644 --- a/chrome/browser/bookmarks/bookmark_node_data_views.cc +++ b/chrome/browser/bookmarks/bookmark_node_data_views.cc @@ -26,7 +26,8 @@ BookmarkNodeData::GetBookmarkCustomFormat() { return format; } -void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const { +void BookmarkNodeData::Write(const base::FilePath& profile_path, + ui::OSExchangeData* data) const { DCHECK(data); // If there is only one element and it is a URL, write the URL to the @@ -40,7 +41,7 @@ void BookmarkNodeData::Write(Profile* profile, ui::OSExchangeData* data) const { } Pickle data_pickle; - WriteToPickle(profile, &data_pickle); + WriteToPickle(profile_path, &data_pickle); data->SetPickledData(GetBookmarkCustomFormat(), data_pickle); } diff --git a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc index 7f72b9c..0a3be77 100644 --- a/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc +++ b/chrome/browser/extensions/api/bookmark_manager_private/bookmark_manager_private_api.cc @@ -144,12 +144,15 @@ CreateApiNodeDataElement(const BookmarkNodeData::Element& element) { // Creates a bookmark_manager_private::BookmarkNodeData from a BookmarkNodeData. scoped_ptr<bookmark_manager_private::BookmarkNodeData> CreateApiBookmarkNodeData(Profile* profile, const BookmarkNodeData& data) { + const base::FilePath& profile_path = profile->GetPath(); + scoped_ptr<bookmark_manager_private::BookmarkNodeData> node_data( new bookmark_manager_private::BookmarkNodeData); - node_data->same_profile = data.IsFromProfile(profile); + node_data->same_profile = data.IsFromProfilePath(profile_path); if (node_data->same_profile) { - std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); + std::vector<const BookmarkNode*> nodes = data.GetNodes( + BookmarkModelFactory::GetForProfile(profile), profile_path); for (size_t i = 0; i < nodes.size(); ++i) { node_data->elements.push_back( CreateNodeDataElementFromBookmarkNode(*nodes[i])); diff --git a/chrome/browser/ui/bookmarks/bookmark_drag_drop.cc b/chrome/browser/ui/bookmarks/bookmark_drag_drop.cc index af174f5..d4f88e9 100644 --- a/chrome/browser/ui/bookmarks/bookmark_drag_drop.cc +++ b/chrome/browser/ui/bookmarks/bookmark_drag_drop.cc @@ -9,6 +9,7 @@ #include "chrome/browser/bookmarks/bookmark_node_data.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/bookmarks/scoped_group_bookmark_actions.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/undo/bookmark_undo_service.h" #include "chrome/browser/undo/bookmark_undo_service_factory.h" #include "ui/base/dragdrop/drag_drop_types.h" @@ -23,9 +24,9 @@ int DropBookmarks(Profile* profile, ScopedGroupBookmarkActions group_drops(profile); #endif BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); - if (data.IsFromProfile(profile)) { + if (data.IsFromProfilePath(profile->GetPath())) { const std::vector<const BookmarkNode*> dragged_nodes = - data.GetNodes(profile); + data.GetNodes(model, profile->GetPath()); if (!dragged_nodes.empty()) { // Drag from same profile. Move nodes. for (size_t i = 0; i < dragged_nodes.size(); ++i) { diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm index 4fdf43a..fe473f82 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm @@ -2416,7 +2416,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { BookmarkNodeData dragData; if (dragData.ReadFromClipboard(ui::CLIPBOARD_TYPE_DRAG)) { std::vector<const BookmarkNode*> nodes( - dragData.GetNodes(browser_->profile())); + dragData.GetNodes(bookmarkModel_, browser_->profile()->GetPath())); dragDataNodes.assign(nodes.begin(), nodes.end()); } return dragDataNodes; diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm index 9b11008..68d0946 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.mm @@ -9,6 +9,7 @@ #include "base/strings/sys_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_node_data.h" +#import "chrome/browser/profiles/profile.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_button_cell.h" @@ -1469,7 +1470,9 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { std::vector<const BookmarkNode*> dragDataNodes; BookmarkNodeData dragData; if (dragData.ReadFromClipboard(ui::CLIPBOARD_TYPE_DRAG)) { - std::vector<const BookmarkNode*> nodes(dragData.GetNodes(profile_)); + BookmarkModel* bookmarkModel = [self bookmarkModel]; + std::vector<const BookmarkNode*> nodes( + dragData.GetNodes(bookmarkModel, profile_->GetPath())); dragDataNodes.assign(nodes.begin(), nodes.end()); } return dragDataNodes; diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_drag_drop_cocoa.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_drag_drop_cocoa.mm index 71e327f..c3e8ec1 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_drag_drop_cocoa.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_drag_drop_cocoa.mm @@ -139,7 +139,7 @@ void DragBookmarks(Profile* profile, base::MessageLoop::current()->SetNestableTasksAllowed(true); BookmarkNodeData drag_data(nodes); - drag_data.SetOriginatingProfile(profile); + drag_data.SetOriginatingProfilePath(profile->GetPath()); drag_data.WriteToClipboard(ui::CLIPBOARD_TYPE_DRAG); // Synthesize an event for dragging, since we can't be sure that diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.mm index d8d65bd..75a12ca 100644 --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.mm +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_folder_target.mm @@ -102,7 +102,7 @@ NSString* kBookmarkButtonDragType = @"ChromiumBookmarkButtonDragType"; [pboard clearContents]; } else { BookmarkNodeData data(node); - data.SetOriginatingProfile(profile_); + data.SetOriginatingProfilePath(profile_->GetPath()); data.WriteToClipboard(ui::CLIPBOARD_TYPE_DRAG); } } diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index 4ac18d5..273a08d 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc @@ -1540,7 +1540,8 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, } else if (!GetBookmarkButtonCount()) { // No bookmarks, accept the drop. location->index = 0; - int ops = data.GetFirstNode(profile) ? ui::DragDropTypes::DRAG_MOVE : + int ops = data.GetFirstNode(model_, profile->GetPath()) ? + ui::DragDropTypes::DRAG_MOVE : ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; location->operation = chrome::GetPreferredBookmarkDropOperation( event.source_operations(), ops); @@ -1606,13 +1607,13 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, location->operation = chrome::GetBookmarkDropOperation( profile, event, data, parent, parent->child_count()); if (!location->operation && !data.has_single_url() && - data.GetFirstNode(profile) == parent) { + data.GetFirstNode(model_, profile->GetPath()) == parent) { // Don't open a menu if the node being dragged is the menu to open. location->on = false; } } else { - location->operation = chrome::GetBookmarkDropOperation(profile, event, - data, model_->bookmark_bar_node(), location->index); + location->operation = chrome::GetBookmarkDropOperation( + profile, event, data, model_->bookmark_bar_node(), location->index); } } @@ -1620,7 +1621,7 @@ void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, ui::OSExchangeData* data) { DCHECK(node && data); BookmarkNodeData drag_data(node); - drag_data.Write(browser_->profile(), data); + drag_data.Write(browser_->profile()->GetPath(), data); } void BookmarkBarView::StartThrobbing(const BookmarkNode* node, diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h index 3bdb513..883f916 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h @@ -31,6 +31,7 @@ class BookmarkContextMenu; class Browser; class BrowserView; +class Profile; namespace content { class PageNavigator; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc b/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc index 1b3a75b..f22882b 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_drag_drop_views.cc @@ -7,7 +7,9 @@ #include "base/message_loop/message_loop.h" #include "base/prefs/pref_service.h" #include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/bookmarks/bookmark_node_data.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" #include "chrome/common/pref_names.h" #include "components/user_prefs/user_prefs.h" @@ -28,7 +30,7 @@ void DragBookmarks(Profile* profile, // Set up our OLE machinery ui::OSExchangeData data; BookmarkNodeData drag_data(nodes); - drag_data.Write(profile, &data); + drag_data.Write(profile->GetPath(), &data); // Allow nested message loop so we get DnD events as we drag this around. bool was_nested = base::MessageLoop::current()->IsNested(); @@ -80,14 +82,17 @@ int GetBookmarkDropOperation(Profile* profile, const BookmarkNodeData& data, const BookmarkNode* parent, int index) { - if (data.IsFromProfile(profile) && data.size() > 1) + const base::FilePath& profile_path = profile->GetPath(); + + if (data.IsFromProfilePath(profile_path) && data.size() > 1) // Currently only accept one dragged node at a time. return ui::DragDropTypes::DRAG_NONE; if (!IsValidBookmarkDropLocation(profile, data, parent, index)) return ui::DragDropTypes::DRAG_NONE; - if (data.GetFirstNode(profile)) + if (data.GetFirstNode(BookmarkModelFactory::GetForProfile(profile), + profile_path)) // User is dragging from this profile: move. return ui::DragDropTypes::DRAG_MOVE; @@ -108,8 +113,10 @@ bool IsValidBookmarkDropLocation(Profile* profile, if (!data.is_valid()) return false; - if (data.IsFromProfile(profile)) { - std::vector<const BookmarkNode*> nodes = data.GetNodes(profile); + const base::FilePath& profile_path = profile->GetPath(); + if (data.IsFromProfilePath(profile_path)) { + std::vector<const BookmarkNode*> nodes = data.GetNodes( + BookmarkModelFactory::GetForProfile(profile), profile_path); for (size_t i = 0; i < nodes.size(); ++i) { // Don't allow the drop if the user is attempting to drop on one of the // nodes being dragged. diff --git a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc index 8380bc5..1954d03 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_menu_delegate.cc @@ -173,7 +173,8 @@ bool BookmarkMenuDelegate::CanDrop(MenuItemView* menu, if (drop_data_.has_single_url()) return true; - const BookmarkNode* drag_node = drop_data_.GetFirstNode(profile_); + const BookmarkNode* drag_node = + drop_data_.GetFirstNode(GetBookmarkModel(), profile_->GetPath()); if (!drag_node) { // Dragging a folder from another profile, always accept. return true; @@ -230,8 +231,8 @@ int BookmarkMenuDelegate::GetDropOperation( break; } DCHECK(drop_parent); - return chrome::GetBookmarkDropOperation(profile_, event, drop_data_, - drop_parent, index_to_drop_at); + return chrome::GetBookmarkDropOperation( + profile_, event, drop_data_, drop_parent, index_to_drop_at); } int BookmarkMenuDelegate::OnPerformDrop( @@ -311,7 +312,7 @@ void BookmarkMenuDelegate::WriteDragData(MenuItemView* sender, content::RecordAction(UserMetricsAction("BookmarkBar_DragFromFolder")); BookmarkNodeData drag_data(menu_id_to_node_map_[sender->GetCommand()]); - drag_data.Write(profile_, data); + drag_data.Write(profile_->GetPath(), data); } int BookmarkMenuDelegate::GetDragOperations(MenuItemView* sender) { |