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

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

Issue 242119: Attempt at fixing crash during importing. As far as I can tell from... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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.h ('k') | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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.h" 5 #include "chrome/browser/importer/importer.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "app/gfx/favicon_size.h" 10 #include "app/gfx/favicon_size.h"
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 } 390 }
391 391
392 // Encode our bitmap as a PNG. 392 // Encode our bitmap as a PNG.
393 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data); 393 gfx::PNGCodec::EncodeBGRASkBitmap(decoded, false, png_data);
394 return true; 394 return true;
395 } 395 }
396 396
397 // ImporterHost. 397 // ImporterHost.
398 398
399 ImporterHost::ImporterHost() 399 ImporterHost::ImporterHost()
400 : observer_(NULL), 400 : profile_(NULL),
401 observer_(NULL),
401 task_(NULL), 402 task_(NULL),
402 importer_(NULL), 403 importer_(NULL),
403 file_loop_(g_browser_process->file_thread()->message_loop()), 404 file_loop_(g_browser_process->file_thread()->message_loop()),
404 waiting_for_bookmarkbar_model_(false), 405 waiting_for_bookmarkbar_model_(false),
406 installed_bookmark_observer_(false),
405 is_source_readable_(true), 407 is_source_readable_(true),
406 headless_(false), 408 headless_(false),
407 parent_window_(NULL) { 409 parent_window_(NULL) {
408 importer_list_.DetectSourceProfiles(); 410 importer_list_.DetectSourceProfiles();
409 } 411 }
410 412
411 ImporterHost::ImporterHost(MessageLoop* file_loop) 413 ImporterHost::ImporterHost(MessageLoop* file_loop)
412 : observer_(NULL), 414 : profile_(NULL),
415 observer_(NULL),
413 task_(NULL), 416 task_(NULL),
414 importer_(NULL), 417 importer_(NULL),
415 file_loop_(file_loop), 418 file_loop_(file_loop),
416 waiting_for_bookmarkbar_model_(false), 419 waiting_for_bookmarkbar_model_(false),
420 installed_bookmark_observer_(false),
417 is_source_readable_(true), 421 is_source_readable_(true),
418 headless_(false), 422 headless_(false),
419 parent_window_(NULL) { 423 parent_window_(NULL) {
420 importer_list_.DetectSourceProfiles(); 424 importer_list_.DetectSourceProfiles();
421 } 425 }
422 426
423 ImporterHost::~ImporterHost() { 427 ImporterHost::~ImporterHost() {
424 if (NULL != importer_) 428 if (NULL != importer_)
425 importer_->Release(); 429 importer_->Release();
430 if (installed_bookmark_observer_) {
431 DCHECK(profile_); // Only way for waiting_for_bookmarkbar_model_ to be true
432 // is if we have a profile.
433 profile_->GetBookmarkModel()->RemoveObserver(this);
434 }
426 } 435 }
427 436
428 void ImporterHost::Loaded(BookmarkModel* model) { 437 void ImporterHost::Loaded(BookmarkModel* model) {
429 DCHECK(model->IsLoaded()); 438 DCHECK(model->IsLoaded());
430 model->RemoveObserver(this); 439 model->RemoveObserver(this);
431 waiting_for_bookmarkbar_model_ = false; 440 waiting_for_bookmarkbar_model_ = false;
441 installed_bookmark_observer_ = false;
432 442
433 std::vector<GURL> starred_urls; 443 std::vector<GURL> starred_urls;
434 model->GetBookmarks(&starred_urls); 444 model->GetBookmarks(&starred_urls);
435 importer_->set_import_to_bookmark_bar(starred_urls.size() == 0); 445 importer_->set_import_to_bookmark_bar(starred_urls.size() == 0);
436 InvokeTaskIfDone(); 446 InvokeTaskIfDone();
437 } 447 }
438 448
449 void ImporterHost::BookmarkModelBeingDeleted(BookmarkModel* model) {
450 installed_bookmark_observer_ = false;
451 }
452
439 void ImporterHost::Observe(NotificationType type, 453 void ImporterHost::Observe(NotificationType type,
440 const NotificationSource& source, 454 const NotificationSource& source,
441 const NotificationDetails& details) { 455 const NotificationDetails& details) {
442 DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED); 456 DCHECK(type == NotificationType::TEMPLATE_URL_MODEL_LOADED);
443 registrar_.RemoveAll(); 457 registrar_.RemoveAll();
444 InvokeTaskIfDone(); 458 InvokeTaskIfDone();
445 } 459 }
446 460
447 void ImporterHost::ShowWarningDialog() { 461 void ImporterHost::ShowWarningDialog() {
448 if (headless_) { 462 if (headless_) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 importer_ = NULL; 494 importer_ = NULL;
481 ImportEnded(); 495 ImportEnded();
482 } 496 }
483 } 497 }
484 498
485 void ImporterHost::StartImportSettings(const ProfileInfo& profile_info, 499 void ImporterHost::StartImportSettings(const ProfileInfo& profile_info,
486 Profile* target_profile, 500 Profile* target_profile,
487 uint16 items, 501 uint16 items,
488 ProfileWriter* writer, 502 ProfileWriter* writer,
489 bool first_run) { 503 bool first_run) {
504 DCHECK(!profile_); // We really only support importing from one host at a
505 // time.
506 profile_ = target_profile;
490 // Preserves the observer and creates a task, since we do async import 507 // Preserves the observer and creates a task, since we do async import
491 // so that it doesn't block the UI. When the import is complete, observer 508 // so that it doesn't block the UI. When the import is complete, observer
492 // will be notified. 509 // will be notified.
493 writer_ = writer; 510 writer_ = writer;
494 importer_ = importer_list_.CreateImporterByType(profile_info.browser_type); 511 importer_ = importer_list_.CreateImporterByType(profile_info.browser_type);
495 // If we fail to create Importer, exit as we can not do anything. 512 // If we fail to create Importer, exit as we can not do anything.
496 if (!importer_) { 513 if (!importer_) {
497 ImportEnded(); 514 ImportEnded();
498 return; 515 return;
499 } 516 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 is_source_readable_ = false; 574 is_source_readable_ = false;
558 } 575 }
559 } 576 }
560 #endif 577 #endif
561 578
562 // BookmarkModel should be loaded before adding IE favorites. So we observe 579 // BookmarkModel should be loaded before adding IE favorites. So we observe
563 // the BookmarkModel if needed, and start the task after it has been loaded. 580 // the BookmarkModel if needed, and start the task after it has been loaded.
564 if ((items & FAVORITES) && !writer_->BookmarkModelIsLoaded()) { 581 if ((items & FAVORITES) && !writer_->BookmarkModelIsLoaded()) {
565 target_profile->GetBookmarkModel()->AddObserver(this); 582 target_profile->GetBookmarkModel()->AddObserver(this);
566 waiting_for_bookmarkbar_model_ = true; 583 waiting_for_bookmarkbar_model_ = true;
584 installed_bookmark_observer_ = true;
567 } 585 }
568 586
569 // Observes the TemplateURLModel if needed to import search engines from the 587 // Observes the TemplateURLModel if needed to import search engines from the
570 // other browser. We also check to see if we're importing bookmarks because 588 // other browser. We also check to see if we're importing bookmarks because
571 // we can import bookmark keywords from Firefox as search engines. 589 // we can import bookmark keywords from Firefox as search engines.
572 if ((items & SEARCH_ENGINES) || (items & FAVORITES)) { 590 if ((items & SEARCH_ENGINES) || (items & FAVORITES)) {
573 if (!writer_->TemplateURLModelIsLoaded()) { 591 if (!writer_->TemplateURLModelIsLoaded()) {
574 TemplateURLModel* model = target_profile->GetTemplateURLModel(); 592 TemplateURLModel* model = target_profile->GetTemplateURLModel();
575 registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED, 593 registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
576 Source<TemplateURLModel>(model)); 594 Source<TemplateURLModel>(model));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 if (observer_) 630 if (observer_)
613 observer_->ImportStarted(); 631 observer_->ImportStarted();
614 } 632 }
615 633
616 void ImporterHost::ImportEnded() { 634 void ImporterHost::ImportEnded() {
617 firefox_lock_.reset(); // Release the Firefox profile lock. 635 firefox_lock_.reset(); // Release the Firefox profile lock.
618 if (observer_) 636 if (observer_)
619 observer_->ImportEnded(); 637 observer_->ImportEnded();
620 Release(); 638 Release();
621 } 639 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/importer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698