| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/favicon_size.h" | 7 #include "app/gfx/favicon_size.h" |
| 8 #include "app/gfx/codec/png_codec.h" | 8 #include "app/gfx/codec/png_codec.h" |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/thread.h" | 11 #include "base/thread.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/browsing_instance.h" | 14 #include "chrome/browser/browsing_instance.h" |
| 15 #include "chrome/browser/chrome_thread.h" |
| 16 #include "chrome/browser/importer/firefox_profile_lock.h" | 16 #include "chrome/browser/importer/firefox_profile_lock.h" |
| 17 #include "chrome/browser/importer/importer_bridge.h" | 17 #include "chrome/browser/importer/importer_bridge.h" |
| 18 #include "chrome/browser/renderer_host/site_instance.h" | 18 #include "chrome/browser/renderer_host/site_instance.h" |
| 19 #include "chrome/browser/search_engines/template_url_model.h" | 19 #include "chrome/browser/search_engines/template_url_model.h" |
| 20 #include "chrome/browser/webdata/web_data_service.h" | 20 #include "chrome/browser/webdata/web_data_service.h" |
| 21 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 24 #include "skia/ext/image_operations.h" | 24 #include "skia/ext/image_operations.h" |
| 25 #include "webkit/glue/image_decoder.h" | 25 #include "webkit/glue/image_decoder.h" |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 return true; | 387 return true; |
| 388 } | 388 } |
| 389 | 389 |
| 390 // ImporterHost. | 390 // ImporterHost. |
| 391 | 391 |
| 392 ImporterHost::ImporterHost() | 392 ImporterHost::ImporterHost() |
| 393 : profile_(NULL), | 393 : profile_(NULL), |
| 394 observer_(NULL), | 394 observer_(NULL), |
| 395 task_(NULL), | 395 task_(NULL), |
| 396 importer_(NULL), | 396 importer_(NULL), |
| 397 file_loop_(g_browser_process->file_thread()->message_loop()), | |
| 398 waiting_for_bookmarkbar_model_(false), | 397 waiting_for_bookmarkbar_model_(false), |
| 399 installed_bookmark_observer_(false), | 398 installed_bookmark_observer_(false), |
| 400 is_source_readable_(true), | 399 is_source_readable_(true), |
| 401 headless_(false), | 400 headless_(false), |
| 402 parent_window_(NULL) { | 401 parent_window_(NULL) { |
| 403 importer_list_.DetectSourceProfiles(); | 402 importer_list_.DetectSourceProfiles(); |
| 404 } | 403 } |
| 405 | 404 |
| 406 ImporterHost::ImporterHost(MessageLoop* file_loop) | |
| 407 : profile_(NULL), | |
| 408 observer_(NULL), | |
| 409 task_(NULL), | |
| 410 importer_(NULL), | |
| 411 file_loop_(file_loop), | |
| 412 waiting_for_bookmarkbar_model_(false), | |
| 413 installed_bookmark_observer_(false), | |
| 414 is_source_readable_(true), | |
| 415 headless_(false), | |
| 416 parent_window_(NULL) { | |
| 417 importer_list_.DetectSourceProfiles(); | |
| 418 } | |
| 419 | |
| 420 ImporterHost::~ImporterHost() { | 405 ImporterHost::~ImporterHost() { |
| 421 if (NULL != importer_) | 406 if (NULL != importer_) |
| 422 importer_->Release(); | 407 importer_->Release(); |
| 423 if (installed_bookmark_observer_) { | 408 if (installed_bookmark_observer_) { |
| 424 DCHECK(profile_); // Only way for waiting_for_bookmarkbar_model_ to be true | 409 DCHECK(profile_); // Only way for waiting_for_bookmarkbar_model_ to be true |
| 425 // is if we have a profile. | 410 // is if we have a profile. |
| 426 profile_->GetBookmarkModel()->RemoveObserver(this); | 411 profile_->GetBookmarkModel()->RemoveObserver(this); |
| 427 } | 412 } |
| 428 } | 413 } |
| 429 | 414 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 importer_->AddRef(); | 495 importer_->AddRef(); |
| 511 | 496 |
| 512 bool import_to_bookmark_bar = first_run; | 497 bool import_to_bookmark_bar = first_run; |
| 513 if (target_profile && target_profile->GetBookmarkModel()->IsLoaded()) { | 498 if (target_profile && target_profile->GetBookmarkModel()->IsLoaded()) { |
| 514 std::vector<GURL> starred_urls; | 499 std::vector<GURL> starred_urls; |
| 515 target_profile->GetBookmarkModel()->GetBookmarks(&starred_urls); | 500 target_profile->GetBookmarkModel()->GetBookmarks(&starred_urls); |
| 516 import_to_bookmark_bar = (starred_urls.size() == 0); | 501 import_to_bookmark_bar = (starred_urls.size() == 0); |
| 517 } | 502 } |
| 518 importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); | 503 importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); |
| 519 scoped_refptr<ImporterBridge> bridge( | 504 scoped_refptr<ImporterBridge> bridge( |
| 520 new InProcessImporterBridge(writer_.get(), file_loop_, this)); | 505 new InProcessImporterBridge(writer_.get(), this)); |
| 521 task_ = NewRunnableMethod(importer_, &Importer::StartImport, | 506 task_ = NewRunnableMethod(importer_, &Importer::StartImport, |
| 522 profile_info, items, bridge); | 507 profile_info, items, bridge); |
| 523 | 508 |
| 524 // We should lock the Firefox profile directory to prevent corruption. | 509 // We should lock the Firefox profile directory to prevent corruption. |
| 525 if (profile_info.browser_type == FIREFOX2 || | 510 if (profile_info.browser_type == FIREFOX2 || |
| 526 profile_info.browser_type == FIREFOX3) { | 511 profile_info.browser_type == FIREFOX3) { |
| 527 firefox_lock_.reset(new FirefoxProfileLock(profile_info.source_path)); | 512 firefox_lock_.reset(new FirefoxProfileLock(profile_info.source_path)); |
| 528 if (!firefox_lock_->HasAcquired()) { | 513 if (!firefox_lock_->HasAcquired()) { |
| 529 // If fail to acquire the lock, we set the source unreadable and | 514 // If fail to acquire the lock, we set the source unreadable and |
| 530 // show a warning dialog. | 515 // show a warning dialog. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 583 } |
| 599 | 584 |
| 600 void ImporterHost::SetObserver(Observer* observer) { | 585 void ImporterHost::SetObserver(Observer* observer) { |
| 601 observer_ = observer; | 586 observer_ = observer; |
| 602 } | 587 } |
| 603 | 588 |
| 604 void ImporterHost::InvokeTaskIfDone() { | 589 void ImporterHost::InvokeTaskIfDone() { |
| 605 if (waiting_for_bookmarkbar_model_ || !registrar_.IsEmpty() || | 590 if (waiting_for_bookmarkbar_model_ || !registrar_.IsEmpty() || |
| 606 !is_source_readable_) | 591 !is_source_readable_) |
| 607 return; | 592 return; |
| 608 file_loop_->PostTask(FROM_HERE, task_); | 593 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, task_); |
| 609 } | 594 } |
| 610 | 595 |
| 611 void ImporterHost::ImportItemStarted(ImportItem item) { | 596 void ImporterHost::ImportItemStarted(ImportItem item) { |
| 612 if (observer_) | 597 if (observer_) |
| 613 observer_->ImportItemStarted(item); | 598 observer_->ImportItemStarted(item); |
| 614 } | 599 } |
| 615 | 600 |
| 616 void ImporterHost::ImportItemEnded(ImportItem item) { | 601 void ImporterHost::ImportItemEnded(ImportItem item) { |
| 617 if (observer_) | 602 if (observer_) |
| 618 observer_->ImportItemEnded(item); | 603 observer_->ImportItemEnded(item); |
| 619 } | 604 } |
| 620 | 605 |
| 621 void ImporterHost::ImportStarted() { | 606 void ImporterHost::ImportStarted() { |
| 622 if (observer_) | 607 if (observer_) |
| 623 observer_->ImportStarted(); | 608 observer_->ImportStarted(); |
| 624 } | 609 } |
| 625 | 610 |
| 626 void ImporterHost::ImportEnded() { | 611 void ImporterHost::ImportEnded() { |
| 627 firefox_lock_.reset(); // Release the Firefox profile lock. | 612 firefox_lock_.reset(); // Release the Firefox profile lock. |
| 628 if (observer_) | 613 if (observer_) |
| 629 observer_->ImportEnded(); | 614 observer_->ImportEnded(); |
| 630 Release(); | 615 Release(); |
| 631 } | 616 } |
| OLD | NEW |