Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: chrome/browser/importer/importer_host.cc

Issue 6979007: Many fixes to bookmark importing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Happy tests =) Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/importer/importer_host.h ('k') | chrome/browser/importer/importer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/importer_host.h" 5 #include "chrome/browser/importer/importer_host.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/bookmarks/bookmark_model.h" 8 #include "chrome/browser/bookmarks/bookmark_model.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/importer/firefox_profile_lock.h" 10 #include "chrome/browser/importer/firefox_profile_lock.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // notified. 110 // notified.
111 writer_ = writer; 111 writer_ = writer;
112 importer_ = importer::CreateImporterByType(source_profile.importer_type); 112 importer_ = importer::CreateImporterByType(source_profile.importer_type);
113 // If we fail to create the Importer, exit, as we cannot do anything. 113 // If we fail to create the Importer, exit, as we cannot do anything.
114 if (!importer_) { 114 if (!importer_) {
115 NotifyImportEnded(); 115 NotifyImportEnded();
116 return; 116 return;
117 } 117 }
118 118
119 importer_->AddRef(); 119 importer_->AddRef();
120 importer_->set_import_to_bookmark_bar(ShouldImportToBookmarkBar(first_run));
121 importer_->set_bookmark_bar_disabled(first_run);
122 120
123 scoped_refptr<InProcessImporterBridge> bridge( 121 scoped_refptr<InProcessImporterBridge> bridge(
124 new InProcessImporterBridge(writer_.get(), this)); 122 new InProcessImporterBridge(writer_.get(), this));
125 task_ = NewRunnableMethod( 123 task_ = NewRunnableMethod(
126 importer_, &Importer::StartImport, source_profile, items, bridge); 124 importer_, &Importer::StartImport, source_profile, items, bridge);
127 125
128 CheckForFirefoxLock(source_profile, items, first_run); 126 CheckForFirefoxLock(source_profile, items, first_run);
129 127
130 #if defined(OS_WIN) 128 #if defined(OS_WIN)
131 // For google toolbar import, we need the user to log in and store their GAIA 129 // For google toolbar import, we need the user to log in and store their GAIA
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (NULL != importer_) 163 if (NULL != importer_)
166 importer_->Release(); 164 importer_->Release();
167 165
168 if (installed_bookmark_observer_) { 166 if (installed_bookmark_observer_) {
169 DCHECK(profile_); // Only way for waiting_for_bookmarkbar_model_ to be true 167 DCHECK(profile_); // Only way for waiting_for_bookmarkbar_model_ to be true
170 // is if we have a profile. 168 // is if we have a profile.
171 profile_->GetBookmarkModel()->RemoveObserver(this); 169 profile_->GetBookmarkModel()->RemoveObserver(this);
172 } 170 }
173 } 171 }
174 172
175 bool ImporterHost::ShouldImportToBookmarkBar(bool first_run) {
176 bool import_to_bookmark_bar = first_run;
177 if (profile_ && profile_->GetBookmarkModel()->IsLoaded()) {
178 import_to_bookmark_bar = (!profile_->GetBookmarkModel()->HasBookmarks());
179 }
180 return import_to_bookmark_bar;
181 }
182
183 void ImporterHost::CheckForFirefoxLock( 173 void ImporterHost::CheckForFirefoxLock(
184 const importer::SourceProfile& source_profile, 174 const importer::SourceProfile& source_profile,
185 uint16 items, 175 uint16 items,
186 bool first_run) { 176 bool first_run) {
187 if (source_profile.importer_type == importer::FIREFOX2 || 177 if (source_profile.importer_type == importer::FIREFOX2 ||
188 source_profile.importer_type == importer::FIREFOX3) { 178 source_profile.importer_type == importer::FIREFOX3) {
189 DCHECK(!firefox_lock_.get()); 179 DCHECK(!firefox_lock_.get());
190 firefox_lock_.reset(new FirefoxProfileLock(source_profile.source_path)); 180 firefox_lock_.reset(new FirefoxProfileLock(source_profile.source_path));
191 if (!firefox_lock_->HasAcquired()) { 181 if (!firefox_lock_->HasAcquired()) {
192 // If fail to acquire the lock, we set the source unreadable and 182 // If fail to acquire the lock, we set the source unreadable and
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return; 215 return;
226 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task_); 216 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, task_);
227 } 217 }
228 218
229 void ImporterHost::Loaded(BookmarkModel* model) { 219 void ImporterHost::Loaded(BookmarkModel* model) {
230 DCHECK(model->IsLoaded()); 220 DCHECK(model->IsLoaded());
231 model->RemoveObserver(this); 221 model->RemoveObserver(this);
232 waiting_for_bookmarkbar_model_ = false; 222 waiting_for_bookmarkbar_model_ = false;
233 installed_bookmark_observer_ = false; 223 installed_bookmark_observer_ = false;
234 224
235 importer_->set_import_to_bookmark_bar(!model->HasBookmarks());
236 InvokeTaskIfDone(); 225 InvokeTaskIfDone();
237 } 226 }
238 227
239 void ImporterHost::BookmarkModelBeingDeleted(BookmarkModel* model) { 228 void ImporterHost::BookmarkModelBeingDeleted(BookmarkModel* model) {
240 installed_bookmark_observer_ = false; 229 installed_bookmark_observer_ = false;
241 } 230 }
242 231
243 void ImporterHost::BookmarkModelChanged() { 232 void ImporterHost::BookmarkModelChanged() {
244 } 233 }
245 234
246 void ImporterHost::Observe(NotificationType type, 235 void ImporterHost::Observe(NotificationType type,
247 const NotificationSource& source, 236 const NotificationSource& source,
248 const NotificationDetails& details) { 237 const NotificationDetails& details) {
249 DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED); 238 DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED);
250 registrar_.RemoveAll(); 239 registrar_.RemoveAll();
251 InvokeTaskIfDone(); 240 InvokeTaskIfDone();
252 } 241 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/importer_host.h ('k') | chrome/browser/importer/importer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698