OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/importer/profile_writer.h" | 5 #include "chrome/browser/importer/profile_writer.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/bookmarks/bookmark_model.h" | 15 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/password_manager/password_store.h" | 18 #include "chrome/browser/password_manager/password_store.h" |
18 #include "chrome/browser/password_manager/password_store_factory.h" | 19 #include "chrome/browser/password_manager/password_store_factory.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/search_engines/template_url.h" | 22 #include "chrome/browser/search_engines/template_url.h" |
22 #include "chrome/browser/search_engines/template_url_service.h" | 23 #include "chrome/browser/search_engines/template_url_service.h" |
23 #include "chrome/browser/search_engines/template_url_service_factory.h" | 24 #include "chrome/browser/search_engines/template_url_service_factory.h" |
24 #include "chrome/browser/webdata/web_data_service_factory.h" | 25 #include "chrome/browser/webdata/web_data_service_factory.h" |
25 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 is_folder == other.is_folder && | 76 is_folder == other.is_folder && |
76 url == other.url && | 77 url == other.url && |
77 path == other.path && | 78 path == other.path && |
78 title == other.title && | 79 title == other.title && |
79 creation_time == other.creation_time); | 80 creation_time == other.creation_time); |
80 } | 81 } |
81 | 82 |
82 ProfileWriter::ProfileWriter(Profile* profile) : profile_(profile) {} | 83 ProfileWriter::ProfileWriter(Profile* profile) : profile_(profile) {} |
83 | 84 |
84 bool ProfileWriter::BookmarkModelIsLoaded() const { | 85 bool ProfileWriter::BookmarkModelIsLoaded() const { |
85 return profile_->GetBookmarkModel()->IsLoaded(); | 86 return BookmarkModelFactory::GetForProfile(profile_)->IsLoaded(); |
86 } | 87 } |
87 | 88 |
88 bool ProfileWriter::TemplateURLServiceIsLoaded() const { | 89 bool ProfileWriter::TemplateURLServiceIsLoaded() const { |
89 return TemplateURLServiceFactory::GetForProfile(profile_)->loaded(); | 90 return TemplateURLServiceFactory::GetForProfile(profile_)->loaded(); |
90 } | 91 } |
91 | 92 |
92 void ProfileWriter::AddPasswordForm(const webkit::forms::PasswordForm& form) { | 93 void ProfileWriter::AddPasswordForm(const webkit::forms::PasswordForm& form) { |
93 PasswordStoreFactory::GetForProfile( | 94 PasswordStoreFactory::GetForProfile( |
94 profile_, Profile::EXPLICIT_ACCESS)->AddLogin(form); | 95 profile_, Profile::EXPLICIT_ACCESS)->AddLogin(form); |
95 } | 96 } |
(...skipping 20 matching lines...) Expand all Loading... |
116 if (pref && !pref->IsManaged()) { | 117 if (pref && !pref->IsManaged()) { |
117 prefs->SetString(prefs::kHomePage, home_page.spec()); | 118 prefs->SetString(prefs::kHomePage, home_page.spec()); |
118 } | 119 } |
119 } | 120 } |
120 | 121 |
121 void ProfileWriter::AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, | 122 void ProfileWriter::AddBookmarks(const std::vector<BookmarkEntry>& bookmarks, |
122 const string16& top_level_folder_name) { | 123 const string16& top_level_folder_name) { |
123 if (bookmarks.empty()) | 124 if (bookmarks.empty()) |
124 return; | 125 return; |
125 | 126 |
126 BookmarkModel* model = profile_->GetBookmarkModel(); | 127 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
127 DCHECK(model->IsLoaded()); | 128 DCHECK(model->IsLoaded()); |
128 | 129 |
129 // If the bookmark bar is currently empty, we should import directly to it. | 130 // If the bookmark bar is currently empty, we should import directly to it. |
130 // Otherwise, we should import everything to a subfolder. | 131 // Otherwise, we should import everything to a subfolder. |
131 const BookmarkNode* bookmark_bar = model->bookmark_bar_node(); | 132 const BookmarkNode* bookmark_bar = model->bookmark_bar_node(); |
132 bool import_to_top_level = bookmark_bar->empty(); | 133 bool import_to_top_level = bookmark_bar->empty(); |
133 | 134 |
134 // Reorder bookmarks so that the toolbar entries come first. | 135 // Reorder bookmarks so that the toolbar entries come first. |
135 std::vector<BookmarkEntry> toolbar_bookmarks; | 136 std::vector<BookmarkEntry> toolbar_bookmarks; |
136 std::vector<BookmarkEntry> reordered_bookmarks; | 137 std::vector<BookmarkEntry> reordered_bookmarks; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 320 |
320 // Only add valid TemplateURLs to the model. | 321 // Only add valid TemplateURLs to the model. |
321 if ((*i)->url_ref().IsValid()) { | 322 if ((*i)->url_ref().IsValid()) { |
322 model->AddAndSetProfile(*i, profile_); // Takes ownership. | 323 model->AddAndSetProfile(*i, profile_); // Takes ownership. |
323 *i = NULL; // Prevent the vector from deleting *i later. | 324 *i = NULL; // Prevent the vector from deleting *i later. |
324 } | 325 } |
325 } | 326 } |
326 } | 327 } |
327 | 328 |
328 ProfileWriter::~ProfileWriter() {} | 329 ProfileWriter::~ProfileWriter() {} |
OLD | NEW |