summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 20:37:42 +0000
committerisherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-24 20:37:42 +0000
commit2c9516b0a6be36ab3d1cf6a4a4b23916b744f327 (patch)
tree2c71ddad55696e6dee8e44fe4037cdaa298c05db
parente33bd5b260b1f40156a92d9eacaa62cabcde0eac (diff)
downloadchromium_src-2c9516b0a6be36ab3d1cf6a4a4b23916b744f327.zip
chromium_src-2c9516b0a6be36ab3d1cf6a4a4b23916b744f327.tar.gz
chromium_src-2c9516b0a6be36ab3d1cf6a4a4b23916b744f327.tar.bz2
Style cleanup in bookmarks import code
Splitting out this smaller CL from a larger one cleaning up our bookmark import logic. BUG=none TEST=none Review URL: http://codereview.chromium.org/7056033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86477 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/importer/external_process_importer_bridge.cc7
-rw-r--r--chrome/browser/importer/external_process_importer_bridge.h2
-rw-r--r--chrome/browser/importer/external_process_importer_client.cc4
-rw-r--r--chrome/browser/importer/firefox2_importer.cc5
-rw-r--r--chrome/browser/importer/firefox3_importer.cc2
-rw-r--r--chrome/browser/importer/ie_importer.cc2
-rw-r--r--chrome/browser/importer/importer_bridge.h2
-rw-r--r--chrome/browser/importer/importer_unittest.cc18
-rw-r--r--chrome/browser/importer/in_process_importer_bridge.cc7
-rw-r--r--chrome/browser/importer/in_process_importer_bridge.h2
-rw-r--r--chrome/browser/importer/profile_import_process_client.h11
-rw-r--r--chrome/browser/importer/profile_writer.cc40
-rw-r--r--chrome/browser/importer/profile_writer.h14
-rw-r--r--chrome/browser/importer/safari_importer.mm2
-rw-r--r--chrome/browser/importer/toolbar_importer.cc2
15 files changed, 57 insertions, 63 deletions
diff --git a/chrome/browser/importer/external_process_importer_bridge.cc b/chrome/browser/importer/external_process_importer_bridge.cc
index 8dfa65d..14fca1a 100644
--- a/chrome/browser/importer/external_process_importer_bridge.cc
+++ b/chrome/browser/importer/external_process_importer_bridge.cc
@@ -25,12 +25,13 @@ ExternalProcessImporterBridge::ExternalProcessImporterBridge(
localized_strings_.reset(localized_strings.DeepCopy());
}
-void ExternalProcessImporterBridge::AddBookmarkEntries(
+void ExternalProcessImporterBridge::AddBookmarks(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
const string16& first_folder_name,
int options) {
- profile_import_thread_->NotifyBookmarksImportReady(
- bookmarks, first_folder_name, options);
+ profile_import_thread_->NotifyBookmarksImportReady(bookmarks,
+ first_folder_name,
+ options);
}
void ExternalProcessImporterBridge::AddHomePage(const GURL& home_page) {
diff --git a/chrome/browser/importer/external_process_importer_bridge.h b/chrome/browser/importer/external_process_importer_bridge.h
index 0773810..5d90697 100644
--- a/chrome/browser/importer/external_process_importer_bridge.h
+++ b/chrome/browser/importer/external_process_importer_bridge.h
@@ -29,7 +29,7 @@ class ExternalProcessImporterBridge : public ImporterBridge {
const DictionaryValue& localized_strings);
// Begin ImporterBridge implementation:
- virtual void AddBookmarkEntries(
+ virtual void AddBookmarks(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
const string16& first_folder_name,
int options) OVERRIDE;
diff --git a/chrome/browser/importer/external_process_importer_client.cc b/chrome/browser/importer/external_process_importer_client.cc
index 29f249d..1b32501 100644
--- a/chrome/browser/importer/external_process_importer_client.cc
+++ b/chrome/browser/importer/external_process_importer_client.cc
@@ -189,8 +189,8 @@ void ExternalProcessImporterClient::OnBookmarksImportGroup(
bookmarks_.insert(bookmarks_.end(), bookmarks_group.begin(),
bookmarks_group.end());
if (bookmarks_.size() == total_bookmarks_count_) {
- bridge_->AddBookmarkEntries(bookmarks_, bookmarks_first_folder_name_,
- bookmarks_options_);
+ bridge_->AddBookmarks(bookmarks_, bookmarks_first_folder_name_,
+ bookmarks_options_);
}
}
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc
index 6b69db9..b14105a 100644
--- a/chrome/browser/importer/firefox2_importer.cc
+++ b/chrome/browser/importer/firefox2_importer.cc
@@ -330,7 +330,7 @@ void Firefox2Importer::ImportBookmarks() {
options |= ProfileWriter::IMPORT_TO_BOOKMARK_BAR;
if (bookmark_bar_disabled())
options |= ProfileWriter::BOOKMARK_BAR_DISABLED;
- bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options);
+ bridge_->AddBookmarks(bookmarks, first_folder_name, options);
}
if (!parsing_bookmarks_html_file_ && !template_urls.empty() &&
!cancelled()) {
@@ -338,9 +338,8 @@ void Firefox2Importer::ImportBookmarks() {
} else {
STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
}
- if (!favicons.empty()) {
+ if (!favicons.empty())
bridge_->SetFavicons(favicons);
- }
}
void Firefox2Importer::ImportPasswords() {
diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc
index fc11cb0..606549f 100644
--- a/chrome/browser/importer/firefox3_importer.cc
+++ b/chrome/browser/importer/firefox3_importer.cc
@@ -294,7 +294,7 @@ void Firefox3Importer::ImportBookmarks() {
int options = 0;
if (import_to_bookmark_bar())
options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR;
- bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options);
+ bridge_->AddBookmarks(bookmarks, first_folder_name, options);
}
if (!template_urls.empty() && !cancelled()) {
bridge_->SetKeywords(template_urls, -1, false);
diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc
index d8843b6..dbecbeb 100644
--- a/chrome/browser/importer/ie_importer.cc
+++ b/chrome/browser/importer/ie_importer.cc
@@ -140,7 +140,7 @@ void IEImporter::ImportFavorites() {
int options = 0;
if (import_to_bookmark_bar())
options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR;
- bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options);
+ bridge_->AddBookmarks(bookmarks, first_folder_name, options);
}
}
diff --git a/chrome/browser/importer/importer_bridge.h b/chrome/browser/importer/importer_bridge.h
index adc3526..f28f33f 100644
--- a/chrome/browser/importer/importer_bridge.h
+++ b/chrome/browser/importer/importer_bridge.h
@@ -22,7 +22,7 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> {
public:
ImporterBridge();
- virtual void AddBookmarkEntries(
+ virtual void AddBookmarks(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
const string16& first_folder_name,
int options) = 0;
diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc
index 6764ef6..424f21e 100644
--- a/chrome/browser/importer/importer_unittest.cc
+++ b/chrome/browser/importer/importer_unittest.cc
@@ -238,9 +238,9 @@ class TestObserver : public ProfileWriter,
EXPECT_EQ(history::SOURCE_IE_IMPORTED, visit_source);
}
- virtual void AddBookmarkEntry(const std::vector<BookmarkEntry>& bookmark,
- const string16& first_folder_name,
- int options) {
+ virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmark,
+ const string16& first_folder_name,
+ int options) OVERRIDE {
// Importer should import the IE Favorites folder the same as the list.
for (size_t i = 0; i < bookmark.size(); ++i) {
if (FindBookmarkEntry(bookmark[i], kIEBookmarks,
@@ -604,9 +604,9 @@ class FirefoxObserver : public ProfileWriter,
++history_count_;
}
- virtual void AddBookmarkEntry(const std::vector<BookmarkEntry>& bookmark,
- const string16& first_folder_name,
- int options) {
+ virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmark,
+ const string16& first_folder_name,
+ int options) OVERRIDE {
for (size_t i = 0; i < bookmark.size(); ++i) {
if (FindBookmarkEntry(bookmark[i], kFirefox2Bookmarks,
arraysize(kFirefox2Bookmarks)))
@@ -814,9 +814,9 @@ class Firefox3Observer : public ProfileWriter,
++history_count_;
}
- virtual void AddBookmarkEntry(const std::vector<BookmarkEntry>& bookmark,
- const string16& first_folder_name,
- int options) {
+ virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmark,
+ const string16& first_folder_name,
+ int options) OVERRIDE {
for (size_t i = 0; i < bookmark.size(); ++i) {
if (FindBookmarkEntry(bookmark[i], kFirefox3Bookmarks,
arraysize(kFirefox3Bookmarks)))
diff --git a/chrome/browser/importer/in_process_importer_bridge.cc b/chrome/browser/importer/in_process_importer_bridge.cc
index be7e9c8..65cdb79 100644
--- a/chrome/browser/importer/in_process_importer_bridge.cc
+++ b/chrome/browser/importer/in_process_importer_bridge.cc
@@ -20,15 +20,14 @@ InProcessImporterBridge::InProcessImporterBridge(ProfileWriter* writer,
host_(host) {
}
-void InProcessImporterBridge::AddBookmarkEntries(
+void InProcessImporterBridge::AddBookmarks(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
const string16& first_folder_name,
int options) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(
- writer_, &ProfileWriter::AddBookmarkEntry, bookmarks,
- first_folder_name, options));
+ NewRunnableMethod(writer_, &ProfileWriter::AddBookmarks, bookmarks,
+ first_folder_name, options));
}
void InProcessImporterBridge::AddHomePage(const GURL &home_page) {
diff --git a/chrome/browser/importer/in_process_importer_bridge.h b/chrome/browser/importer/in_process_importer_bridge.h
index 141893d..2cd042e 100644
--- a/chrome/browser/importer/in_process_importer_bridge.h
+++ b/chrome/browser/importer/in_process_importer_bridge.h
@@ -23,7 +23,7 @@ class InProcessImporterBridge : public ImporterBridge {
InProcessImporterBridge(ProfileWriter* writer, ImporterHost* host);
// Begin ImporterBridge implementation:
- virtual void AddBookmarkEntries(
+ virtual void AddBookmarks(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks,
const string16& first_folder_name,
int options) OVERRIDE;
diff --git a/chrome/browser/importer/profile_import_process_client.h b/chrome/browser/importer/profile_import_process_client.h
index 25e6c59..9607a4f 100644
--- a/chrome/browser/importer/profile_import_process_client.h
+++ b/chrome/browser/importer/profile_import_process_client.h
@@ -32,8 +32,8 @@ struct PasswordForm;
// process in order to get results back from the process host. The
// ProfileImportProcessHost calls the client's functions on the thread passed to
// it when it's created.
-class ProfileImportProcessClient :
- public base::RefCountedThreadSafe<ProfileImportProcessClient> {
+class ProfileImportProcessClient
+ : public base::RefCountedThreadSafe<ProfileImportProcessClient> {
public:
ProfileImportProcessClient();
@@ -56,10 +56,9 @@ class ProfileImportProcessClient :
virtual void OnHomePageImportReady(const GURL& home_page);
- virtual void OnBookmarksImportStart(
- const string16& first_folder_name,
- int options,
- size_t total_bookmarks_count);
+ virtual void OnBookmarksImportStart(const string16& first_folder_name,
+ int options,
+ size_t total_bookmarks_count);
virtual void OnBookmarksImportGroup(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks);
diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc
index a562816..6f3d222 100644
--- a/chrome/browser/importer/profile_writer.cc
+++ b/chrome/browser/importer/profile_writer.cc
@@ -60,10 +60,12 @@ void ProfileWriter::AddHomepage(const GURL& home_page) {
}
}
-void ProfileWriter::AddBookmarkEntry(
- const std::vector<BookmarkEntry>& bookmark,
- const string16& first_folder_name,
- int options) {
+void ProfileWriter::AddBookmarks(const std::vector<BookmarkEntry>& bookmarks,
+ const string16& first_folder_name,
+ int options) {
+ if (bookmarks.empty())
+ return;
+
BookmarkModel* model = profile_->GetBookmarkModel();
DCHECK(model->IsLoaded());
@@ -73,13 +75,11 @@ void ProfileWriter::AddBookmarkEntry(
bool show_bookmark_toolbar = false;
std::set<const BookmarkNode*> folders_added_to;
- bool import_mode = false;
- if (bookmark.size() > 1) {
- model->BeginImportMode();
- import_mode = true;
- }
- for (std::vector<BookmarkEntry>::const_iterator it = bookmark.begin();
- it != bookmark.end(); ++it) {
+
+ model->BeginImportMode();
+
+ for (std::vector<BookmarkEntry>::const_iterator it = bookmarks.begin();
+ it != bookmarks.end(); ++it) {
// Don't insert this url if it isn't valid.
if (!it->is_folder && !it->url.is_valid())
continue;
@@ -105,17 +105,16 @@ void ProfileWriter::AddBookmarkEntry(
for (int index = 0; index < parent->child_count(); ++index) {
const BookmarkNode* node = parent->GetChild(index);
- if ((node->type() == BookmarkNode::BOOKMARK_BAR ||
- node->type() == BookmarkNode::FOLDER) &&
- node->GetTitle() == folder_name) {
+ if (node->is_folder() && node->GetTitle() == folder_name) {
child = node;
break;
}
}
- if (child == NULL)
+ if (!child)
child = model->AddFolder(parent, parent->child_count(), folder_name);
parent = child;
}
+
folders_added_to.insert(parent);
if (it->is_folder) {
model->AddFolder(parent, parent->child_count(), it->title);
@@ -130,18 +129,15 @@ void ProfileWriter::AddBookmarkEntry(
show_bookmark_toolbar = true;
}
- // Reset the date modified time of the folders we added to. We do this to
- // make sure the 'recently added to' combobox in the bubble doesn't get random
- // folders.
+ // In order to keep the imported-to folders from appearing in the 'recently
+ // added to' combobox, reset their modified times.
for (std::set<const BookmarkNode*>::const_iterator i =
- folders_added_to.begin();
+ folders_added_to.begin();
i != folders_added_to.end(); ++i) {
model->ResetDateFolderModified(*i);
}
- if (import_mode) {
- model->EndImportMode();
- }
+ model->EndImportMode();
if (show_bookmark_toolbar && !(options & BOOKMARK_BAR_DISABLED))
ShowBookmarkBar();
diff --git a/chrome/browser/importer/profile_writer.h b/chrome/browser/importer/profile_writer.h
index c97d807..4a88db7 100644
--- a/chrome/browser/importer/profile_writer.h
+++ b/chrome/browser/importer/profile_writer.h
@@ -33,10 +33,10 @@ class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> {
public:
// Used to identify how the bookmarks are added.
enum BookmarkOptions {
- // Indicates the bookmark should only be added if unique. Uniqueness
- // is done by title, url and path. That is, if this is passed to
- // AddBookmarkEntry the bookmark is added only if there is no other
- // URL with the same url, path and title.
+ // Indicates the bookmark should only be added if unique. Uniqueness is done
+ // by title, url and path. That is, if this is passed to AddBookmarks, the
+ // bookmark is added only if there is no other URL with the same url, path
+ // and title.
ADD_IF_UNIQUE = 1 << 0,
// Indicates the bookmarks should be added to the bookmark bar.
@@ -90,9 +90,9 @@ class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> {
// If |options| contains ADD_IF_UNIQUE, then the bookmark is added only
// if another bookmarks does not exist with the same title, path and
// url.
- virtual void AddBookmarkEntry(const std::vector<BookmarkEntry>& bookmark,
- const string16& first_folder_name,
- int options);
+ virtual void AddBookmarks(const std::vector<BookmarkEntry>& bookmark,
+ const string16& first_folder_name,
+ int options);
virtual void AddFavicons(
const std::vector<history::ImportedFaviconUsage>& favicons);
diff --git a/chrome/browser/importer/safari_importer.mm b/chrome/browser/importer/safari_importer.mm
index 8c5f5a7..fd4e126 100644
--- a/chrome/browser/importer/safari_importer.mm
+++ b/chrome/browser/importer/safari_importer.mm
@@ -107,7 +107,7 @@ void SafariImporter::ImportBookmarks() {
int options = 0;
if (import_to_bookmark_bar())
options = ProfileWriter::IMPORT_TO_BOOKMARK_BAR;
- bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options);
+ bridge_->AddBookmarks(bookmarks, first_folder_name, options);
}
// Import favicons.
diff --git a/chrome/browser/importer/toolbar_importer.cc b/chrome/browser/importer/toolbar_importer.cc
index 66676233..eeea95c 100644
--- a/chrome/browser/importer/toolbar_importer.cc
+++ b/chrome/browser/importer/toolbar_importer.cc
@@ -558,6 +558,6 @@ void Toolbar5Importer::AddBookmarksToChrome(
bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR);
int options = ProfileWriter::ADD_IF_UNIQUE |
(import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0);
- bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options);
+ bridge_->AddBookmarks(bookmarks, first_folder_name, options);
}
}