diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 21:14:34 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-18 21:14:34 +0000 |
commit | 0072d87bf9dae6259147d51df6067d60f337228d (patch) | |
tree | d4f9bb62a785550c66424a6f466867f7df993cd8 /chrome/browser | |
parent | b3326d6308460c7d2789ee0d719886c7a6745091 (diff) | |
download | chromium_src-0072d87bf9dae6259147d51df6067d60f337228d.zip chromium_src-0072d87bf9dae6259147d51df6067d60f337228d.tar.gz chromium_src-0072d87bf9dae6259147d51df6067d60f337228d.tar.bz2 |
Import bookmarks to bookmark bar if user has not bookmarked anything yet.
BUG=9000
Review URL: http://codereview.chromium.org/131004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/importer/firefox2_importer.cc | 13 | ||||
-rw-r--r-- | chrome/browser/importer/firefox2_importer.h | 2 | ||||
-rw-r--r-- | chrome/browser/importer/firefox3_importer.cc | 6 | ||||
-rw-r--r-- | chrome/browser/importer/ie_importer.cc | 8 | ||||
-rw-r--r-- | chrome/browser/importer/importer.cc | 38 | ||||
-rw-r--r-- | chrome/browser/importer/importer.h | 24 | ||||
-rw-r--r-- | chrome/browser/importer/toolbar_importer.cc | 2 |
7 files changed, 52 insertions, 41 deletions
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 5885773..0d6359e 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -131,7 +131,7 @@ TemplateURL* Firefox2Importer::CreateTemplateURL(const std::wstring& title, void Firefox2Importer::ImportBookmarksFile( const std::wstring& file_path, const std::set<GURL>& default_urls, - bool first_run, + bool import_to_bookmark_bar, const std::wstring& first_folder_name, Importer* importer, std::vector<ProfileWriter::BookmarkEntry>* bookmarks, @@ -185,16 +185,15 @@ void Firefox2Importer::ImportBookmarksFile( entry.url = url; entry.title = title; - if (first_run && toolbar_folder) { + if (import_to_bookmark_bar && toolbar_folder) { // Flatten the items in toolbar. entry.in_toolbar = true; entry.path.assign(path.begin() + toolbar_folder, path.end()); toolbar_bookmarks.push_back(entry); } else { - // Insert the item into the "Imported from Firefox" folder after - // the first run. + // Insert the item into the "Imported from Firefox" folder. entry.path.assign(path.begin(), path.end()); - if (first_run) + if (import_to_bookmark_bar) entry.path.erase(entry.path.begin()); bookmarks->push_back(entry); } @@ -253,7 +252,7 @@ void Firefox2Importer::ImportBookmarks() { else first_folder_name = l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_FIREFOX); - ImportBookmarksFile(file, default_urls, first_run(), + ImportBookmarksFile(file, default_urls, import_to_bookmark_bar(), first_folder_name, this, &bookmarks, &template_urls, &favicons); @@ -262,7 +261,7 @@ void Firefox2Importer::ImportBookmarks() { main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, &ProfileWriter::AddBookmarkEntry, bookmarks, first_folder_name, - first_run() ? ProfileWriter::FIRST_RUN : 0)); + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } if (!parsing_bookmarks_html_file_ && !template_urls.empty() && !cancelled()) { diff --git a/chrome/browser/importer/firefox2_importer.h b/chrome/browser/importer/firefox2_importer.h index eb02cb7..8078c66 100644 --- a/chrome/browser/importer/firefox2_importer.h +++ b/chrome/browser/importer/firefox2_importer.h @@ -39,7 +39,7 @@ class Firefox2Importer : public Importer { static void ImportBookmarksFile( const std::wstring& file_path, const std::set<GURL>& default_urls, - bool first_run, + bool import_to_bookmark_bar, const std::wstring& first_folder_name, Importer* importer, std::vector<ProfileWriter::BookmarkEntry>* bookmarks, diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 0c6571d..2f8eb46 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -197,7 +197,7 @@ void Firefox3Importer::ImportBookmarks() { // This bookmark entry should be put in the bookmark bar. // But we put it in the Firefox group after first run, so // that do not mess up the bookmark bar. - if (first_run()) { + if (import_to_bookmark_bar()) { is_in_toolbar = true; } else { path.insert(path.begin(), parent->title); @@ -209,7 +209,7 @@ void Firefox3Importer::ImportBookmarks() { parent->id == unsorted_folder_id) { // After the first run, the item will be placed in a folder in // the "Other bookmarks". - if (!first_run()) + if (!import_to_bookmark_bar()) path.insert(path.begin(), firefox_folder); found_path = true; break; @@ -250,7 +250,7 @@ void Firefox3Importer::ImportBookmarks() { main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, &ProfileWriter::AddBookmarkEntry, bookmarks, l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_FIREFOX), - first_run() ? ProfileWriter::FIRST_RUN : 0)); + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } if (!template_urls.empty() && !cancelled()) { main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 3862437..41039ff 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -114,7 +114,7 @@ void IEImporter::ImportFavorites() { main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, &ProfileWriter::AddBookmarkEntry, bookmarks, l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_IE), - first_run() ? ProfileWriter::FIRST_RUN : 0)); + import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0)); } } @@ -520,15 +520,15 @@ void IEImporter::ParseFavoritesFolder(const FavoritesInfo& info, // Flatten the bookmarks in Link folder onto bookmark toolbar. Otherwise, // put it into "Other bookmarks". - if (first_run() && + if (import_to_bookmark_bar() && (entry.path.size() > 0 && entry.path[0] == info.links_folder)) { entry.in_toolbar = true; entry.path.erase(entry.path.begin()); toolbar_bookmarks.push_back(entry); } else { - // After the first run, we put the bookmarks in a "Imported From IE" + // We put the bookmarks in a "Imported From IE" // folder, so that we don't mess up the "Other bookmarks". - if (!first_run()) + if (!import_to_bookmark_bar()) entry.path.insert(entry.path.begin(), ie_folder); bookmarks->push_back(entry); } diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index 1046cfd..7be7cd0 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -90,8 +90,8 @@ void ProfileWriter::AddBookmarkEntry( BookmarkModel* model = profile_->GetBookmarkModel(); DCHECK(model->IsLoaded()); - bool first_run = (options & FIRST_RUN) != 0; - std::wstring real_first_folder = first_run ? first_folder_name : + bool import_to_bookmark_bar = ((options & IMPORT_TO_BOOKMARK_BAR) != 0); + std::wstring real_first_folder = import_to_bookmark_bar ? first_folder_name : GenerateUniqueFolderName(model, first_folder_name); bool show_bookmark_toolbar = false; @@ -105,10 +105,9 @@ void ProfileWriter::AddBookmarkEntry( // We suppose that bookmarks are unique by Title, URL, and Folder. Since // checking for uniqueness may not be always the user's intention we have // this as an option. - if (options & ADD_IF_UNIQUE && - DoesBookmarkExist(model, *it, real_first_folder, first_run)) { + if (options & ADD_IF_UNIQUE && DoesBookmarkExist(model, *it, + real_first_folder, import_to_bookmark_bar)) continue; - } // Set up groups in BookmarkModel in such a way that path[i] is // the subgroup of path[i-1]. Finally they construct a path in the @@ -119,9 +118,8 @@ void ProfileWriter::AddBookmarkEntry( for (std::vector<std::wstring>::const_iterator i = it->path.begin(); i != it->path.end(); ++i) { BookmarkNode* child = NULL; - const std::wstring& folder_name = - (!first_run && !it->in_toolbar && (i == it->path.begin())) ? - real_first_folder : *i; + const std::wstring& folder_name = (!import_to_bookmark_bar && + !it->in_toolbar && (i == it->path.begin())) ? real_first_folder : *i; for (int index = 0; index < parent->GetChildCount(); ++index) { BookmarkNode* node = parent->GetChild(index); @@ -325,7 +323,7 @@ bool ProfileWriter::DoesBookmarkExist( BookmarkModel* model, const BookmarkEntry& entry, const std::wstring& first_folder_name, - bool first_run) { + bool import_to_bookmark_bar) { std::vector<BookmarkNode*> nodes_with_same_url; model->GetNodesByURL(entry.url, &nodes_with_same_url); if (nodes_with_same_url.empty()) @@ -343,7 +341,7 @@ bool ProfileWriter::DoesBookmarkExist( entry.path.rbegin(); (path_it != entry.path.rend()) && found_match; ++path_it) { const std::wstring& folder_name = - (!first_run && path_it + 1 == entry.path.rend()) ? + (!import_to_bookmark_bar && path_it + 1 == entry.path.rend()) ? first_folder_name : *path_it; if (NULL == parent || *path_it != folder_name) found_match = false; @@ -353,12 +351,12 @@ bool ProfileWriter::DoesBookmarkExist( // We need a post test to differentiate checks such as // /home/hello and /hello. The parent should either by the other folder - // node, or the bookmarks bar, depending upon first_run and + // node, or the bookmarks bar, depending upon import_to_bookmark_bar and // entry.in_toolbar. if (found_match && - ((first_run && entry.in_toolbar && parent != + ((import_to_bookmark_bar && entry.in_toolbar && parent != model->GetBookmarkBarNode()) || - ((!first_run || !entry.in_toolbar) && + ((!import_to_bookmark_bar || !entry.in_toolbar) && parent != model->other_node()))) { found_match = false; } @@ -425,8 +423,13 @@ ImporterHost::~ImporterHost() { } void ImporterHost::Loaded(BookmarkModel* model) { + DCHECK(model->IsLoaded()); model->RemoveObserver(this); waiting_for_bookmarkbar_model_ = false; + + std::vector<GURL> starred_urls; + model->GetBookmarks(&starred_urls); + importer_->set_import_to_bookmark_bar(starred_urls.size() == 0); InvokeTaskIfDone(); } @@ -487,7 +490,14 @@ void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, writer_ = writer; importer_ = CreateImporterByType(profile_info.browser_type); importer_->AddRef(); - importer_->set_first_run(first_run); + + bool import_to_bookmark_bar = first_run; + if (target_profile && target_profile->GetBookmarkModel()->IsLoaded()) { + std::vector<GURL> starred_urls; + target_profile->GetBookmarkModel()->GetBookmarks(&starred_urls); + import_to_bookmark_bar = (starred_urls.size() == 0); + } + importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); task_ = NewRunnableMethod(importer_, &Importer::StartImport, profile_info, items, writer_.get(), file_loop_, this); diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index bce26ee..c7360fd 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -72,8 +72,8 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { // URL with the same url, path and title. ADD_IF_UNIQUE = 1 << 0, - // Indicates the bookmarks are being added during first run. - FIRST_RUN = 1 << 1 + // Indicates the bookmarks should be added to the bookmark bar. + IMPORT_TO_BOOKMARK_BAR = 1 << 1 }; explicit ProfileWriter(Profile* profile) : profile_(profile) { } @@ -102,10 +102,10 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { virtual void AddHomepage(const GURL& homepage); // Adds the bookmarks to the BookmarkModel. // |options| is a bitmask of BookmarkOptions and dictates how and - // which bookmarks are added. If the bitmask contains FIRST_RUN, + // which bookmarks are added. If the bitmask contains IMPORT_TO_BOOKMARK_BAR, // then any entries with a value of true for in_toolbar are added to - // the bookmark bar. If the bitmask does not contain FIRST_RUN then - // the folder name the bookmarks are added to is uniqued based on + // the bookmark bar. If the bitmask does not contain IMPORT_TO_BOOKMARK_BAR + // then the folder name the bookmarks are added to is uniqued based on // |first_folder_name|. For example, if |first_folder_name| is 'foo' // and a folder with the name 'foo' already exists in the other // bookmarks folder, then the folder name 'foo 2' is used. @@ -144,11 +144,11 @@ class ProfileWriter : public base::RefCounted<ProfileWriter> { // Returns true if a bookmark exists with the same url, title and path // as |entry|. |first_folder_name| is the name to use for the first - // path entry if |first_run| is true. + // path entry if |import_to_bookmark_bar| is true. bool DoesBookmarkExist(BookmarkModel* model, const BookmarkEntry& entry, const std::wstring& first_folder_name, - bool first_run); + bool import_to_bookmark_bar); Profile* profile_; @@ -336,7 +336,9 @@ class Importer : public base::RefCounted<Importer> { // Cancels the import process. virtual void Cancel() { cancelled_ = true; } - void set_first_run(bool first_run) { first_run_ = first_run; } + void set_import_to_bookmark_bar(bool import_to_bookmark_bar) { + import_to_bookmark_bar_ = import_to_bookmark_bar; + } bool cancelled() const { return cancelled_; } @@ -346,7 +348,7 @@ class Importer : public base::RefCounted<Importer> { delagate_loop_(NULL), importer_host_(NULL), cancelled_(false), - first_run_(false) {} + import_to_bookmark_bar_(false) {} // Notifies the coordinator that the collection of data for the specified // item has begun. @@ -380,7 +382,7 @@ class Importer : public base::RefCounted<Importer> { static bool ReencodeFavicon(const unsigned char* src_data, size_t src_len, std::vector<unsigned char>* png_data); - bool first_run() const { return first_run_; } + bool import_to_bookmark_bar() const { return import_to_bookmark_bar_; } // The importer should know the main thread so that ProfileWriter // will be invoked in thread instead. @@ -397,7 +399,7 @@ class Importer : public base::RefCounted<Importer> { bool cancelled_; // True if the importer is created in the first run UI. - bool first_run_; + bool import_to_bookmark_bar_; DISALLOW_EVIL_CONSTRUCTORS(Importer); }; diff --git a/chrome/browser/importer/toolbar_importer.cc b/chrome/browser/importer/toolbar_importer.cc index 0f7c12f..83fb29f 100644 --- a/chrome/browser/importer/toolbar_importer.cc +++ b/chrome/browser/importer/toolbar_importer.cc @@ -583,7 +583,7 @@ void Toolbar5Importer::AddBookmarksToChrome( const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { if (!bookmarks.empty() && !cancelled()) { int options = ProfileWriter::ADD_IF_UNIQUE | - (first_run() ? ProfileWriter::FIRST_RUN : 0); + (import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0); main_loop_->PostTask(FROM_HERE, NewRunnableMethod(writer_, &ProfileWriter::AddBookmarkEntry, bookmarks, l10n_util::GetString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR), |