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

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

Issue 27242: Make importer.cc compile on Posix. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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') | chrome/chrome.gyp » ('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) 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 "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/gfx/png_encoder.h" 11 #include "base/gfx/png_encoder.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/bookmarks/bookmark_model.h" 14 #include "chrome/browser/bookmarks/bookmark_model.h"
15 #include "chrome/browser/browser.h" 15 #include "chrome/browser/browser.h"
16 #include "chrome/browser/browser_list.h" 16 #include "chrome/browser/browser_list.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/first_run.h" 18 #include "chrome/browser/first_run.h"
19 #include "chrome/browser/importer/firefox2_importer.h" 19 #include "chrome/browser/importer/firefox2_importer.h"
20 #include "chrome/browser/importer/firefox3_importer.h" 20 #include "chrome/browser/importer/firefox3_importer.h"
21 #include "chrome/browser/importer/firefox_importer_utils.h" 21 #include "chrome/browser/importer/firefox_importer_utils.h"
22 #include "chrome/browser/importer/firefox_profile_lock.h" 22 #include "chrome/browser/importer/firefox_profile_lock.h"
23 #if defined(OS_WIN)
23 #include "chrome/browser/importer/ie_importer.h" 24 #include "chrome/browser/importer/ie_importer.h"
25 #endif
24 #include "chrome/browser/search_engines/template_url_model.h" 26 #include "chrome/browser/search_engines/template_url_model.h"
25 #include "chrome/browser/shell_integration.h" 27 #include "chrome/browser/shell_integration.h"
26 #include "chrome/browser/tab_contents/site_instance.h" 28 #include "chrome/browser/tab_contents/site_instance.h"
27 #include "chrome/browser/views/importer_lock_view.h"
28 #include "chrome/browser/webdata/web_data_service.h" 29 #include "chrome/browser/webdata/web_data_service.h"
29 #include "chrome/common/gfx/favicon_size.h" 30 #include "chrome/common/gfx/favicon_size.h"
30 #include "chrome/common/l10n_util.h" 31 #include "chrome/common/l10n_util.h"
31 #include "chrome/common/notification_service.h" 32 #include "chrome/common/notification_service.h"
32 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
33 #include "chrome/common/pref_service.h" 34 #include "chrome/common/pref_service.h"
34 #include "chrome/common/win_util.h"
35 #include "chrome/views/window.h"
36 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
37 #include "skia/ext/image_operations.h" 36 #include "skia/ext/image_operations.h"
38 #include "webkit/glue/image_decoder.h" 37 #include "webkit/glue/image_decoder.h"
39 38
39 // TODO(port): Port these files.
40 #if defined(OS_WIN)
41 #include "chrome/browser/views/importer_lock_view.h"
42 #include "chrome/common/win_util.h"
43 #include "chrome/views/window.h"
44 #endif
45
40 // ProfileWriter. 46 // ProfileWriter.
41 47
42 bool ProfileWriter::BookmarkModelIsLoaded() const { 48 bool ProfileWriter::BookmarkModelIsLoaded() const {
43 return profile_->GetBookmarkModel()->IsLoaded(); 49 return profile_->GetBookmarkModel()->IsLoaded();
44 } 50 }
45 51
46 void ProfileWriter::AddBookmarkModelObserver(BookmarkModelObserver* observer) { 52 void ProfileWriter::AddBookmarkModelObserver(BookmarkModelObserver* observer) {
47 profile_->GetBookmarkModel()->AddObserver(observer); 53 profile_->GetBookmarkModel()->AddObserver(observer);
48 } 54 }
49 55
50 bool ProfileWriter::TemplateURLModelIsLoaded() const { 56 bool ProfileWriter::TemplateURLModelIsLoaded() const {
51 return profile_->GetTemplateURLModel()->loaded(); 57 return profile_->GetTemplateURLModel()->loaded();
52 } 58 }
53 59
54 void ProfileWriter::AddTemplateURLModelObserver( 60 void ProfileWriter::AddTemplateURLModelObserver(
55 NotificationObserver* observer) { 61 NotificationObserver* observer) {
56 TemplateURLModel* model = profile_->GetTemplateURLModel(); 62 TemplateURLModel* model = profile_->GetTemplateURLModel();
57 NotificationService::current()->AddObserver( 63 NotificationService::current()->AddObserver(
58 observer, NotificationType::TEMPLATE_URL_MODEL_LOADED, 64 observer, NotificationType::TEMPLATE_URL_MODEL_LOADED,
59 Source<TemplateURLModel>(model)); 65 Source<TemplateURLModel>(model));
60 model->Load(); 66 model->Load();
61 } 67 }
62 68
63 void ProfileWriter::AddPasswordForm(const PasswordForm& form) { 69 void ProfileWriter::AddPasswordForm(const PasswordForm& form) {
64 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddLogin(form); 70 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddLogin(form);
65 } 71 }
66 72
73 #if defined(OS_WIN)
67 void ProfileWriter::AddIE7PasswordInfo(const IE7PasswordInfo& info) { 74 void ProfileWriter::AddIE7PasswordInfo(const IE7PasswordInfo& info) {
68 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddIE7Login(info); 75 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddIE7Login(info);
69 } 76 }
77 #endif
70 78
71 void ProfileWriter::AddHistoryPage(const std::vector<history::URLRow>& page) { 79 void ProfileWriter::AddHistoryPage(const std::vector<history::URLRow>& page) {
72 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)-> 80 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->
73 AddPagesWithDetails(page); 81 AddPagesWithDetails(page);
74 } 82 }
75 83
76 void ProfileWriter::AddHomepage(const GURL& home_page) { 84 void ProfileWriter::AddHomepage(const GURL& home_page) {
77 DCHECK(profile_); 85 DCHECK(profile_);
78 86
79 PrefService* prefs = profile_->GetPrefs(); 87 PrefService* prefs = profile_->GetPrefs();
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (turl_with_host_path) 271 if (turl_with_host_path)
264 model->SetDefaultSearchProvider(turl_with_host_path); 272 model->SetDefaultSearchProvider(turl_with_host_path);
265 else 273 else
266 NOTREACHED(); // BuildHostPathMap should only insert non-null values. 274 NOTREACHED(); // BuildHostPathMap should only insert non-null values.
267 } 275 }
268 delete t_url; 276 delete t_url;
269 continue; 277 continue;
270 } 278 }
271 if (t_url->url() && t_url->url()->IsValid()) { 279 if (t_url->url() && t_url->url()->IsValid()) {
272 model->Add(t_url); 280 model->Add(t_url);
273 if (default_keyword && t_url->url() && 281 if (default_keyword && t_url->url() &&
274 t_url->url()->SupportsReplacement()) 282 t_url->url()->SupportsReplacement())
275 model->SetDefaultSearchProvider(t_url); 283 model->SetDefaultSearchProvider(t_url);
276 } else { 284 } else {
277 // Don't add invalid TemplateURLs to the model. 285 // Don't add invalid TemplateURLs to the model.
278 delete t_url; 286 delete t_url;
279 } 287 }
280 } 288 }
281 } 289 }
282 290
283 void ProfileWriter::ShowBookmarkBar() { 291 void ProfileWriter::ShowBookmarkBar() {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 331
324 bool ProfileWriter::DoesBookmarkExist( 332 bool ProfileWriter::DoesBookmarkExist(
325 BookmarkModel* model, 333 BookmarkModel* model,
326 const BookmarkEntry& entry, 334 const BookmarkEntry& entry,
327 const std::wstring& first_folder_name, 335 const std::wstring& first_folder_name,
328 bool first_run) { 336 bool first_run) {
329 std::vector<BookmarkNode*> nodes_with_same_url; 337 std::vector<BookmarkNode*> nodes_with_same_url;
330 model->GetNodesByURL(entry.url, &nodes_with_same_url); 338 model->GetNodesByURL(entry.url, &nodes_with_same_url);
331 if (nodes_with_same_url.empty()) 339 if (nodes_with_same_url.empty())
332 return false; 340 return false;
333 341
334 for (size_t i = 0; i < nodes_with_same_url.size(); ++i) { 342 for (size_t i = 0; i < nodes_with_same_url.size(); ++i) {
335 BookmarkNode* node = nodes_with_same_url[i]; 343 BookmarkNode* node = nodes_with_same_url[i];
336 if (entry.title != node->GetTitle()) 344 if (entry.title != node->GetTitle())
337 continue; 345 continue;
338 346
339 // Does the path match? 347 // Does the path match?
340 bool found_match = true; 348 bool found_match = true;
341 BookmarkNode* parent = node->GetParent(); 349 BookmarkNode* parent = node->GetParent();
342 for (std::vector<std::wstring>::const_reverse_iterator path_it = 350 for (std::vector<std::wstring>::const_reverse_iterator path_it =
343 entry.path.rbegin(); 351 entry.path.rbegin();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 this, NotificationType::TEMPLATE_URL_MODEL_LOADED, 449 this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
442 Source<TemplateURLModel>(model)); 450 Source<TemplateURLModel>(model));
443 waiting_for_template_url_model_ = false; 451 waiting_for_template_url_model_ = false;
444 InvokeTaskIfDone(); 452 InvokeTaskIfDone();
445 } 453 }
446 454
447 void ImporterHost::ShowWarningDialog() { 455 void ImporterHost::ShowWarningDialog() {
448 if (headless_) { 456 if (headless_) {
449 OnLockViewEnd(false); 457 OnLockViewEnd(false);
450 } else { 458 } else {
459 #if defined(OS_WIN)
451 views::Window::CreateChromeWindow(GetActiveWindow(), gfx::Rect(), 460 views::Window::CreateChromeWindow(GetActiveWindow(), gfx::Rect(),
452 new ImporterLockView(this))->Show(); 461 new ImporterLockView(this))->Show();
462 #else
463 // TODO(port): Need CreateChromeWindow.
464 NOTIMPLEMENTED();
465 #endif
453 } 466 }
454 } 467 }
455 468
456 void ImporterHost::OnLockViewEnd(bool is_continue) { 469 void ImporterHost::OnLockViewEnd(bool is_continue) {
457 if (is_continue) { 470 if (is_continue) {
458 // User chose to continue, then we check the lock again to make 471 // User chose to continue, then we check the lock again to make
459 // sure that Firefox has been closed. Try to import the settings 472 // sure that Firefox has been closed. Try to import the settings
460 // if successful. Otherwise, show a warning dialog. 473 // if successful. Otherwise, show a warning dialog.
461 firefox_lock_->Lock(); 474 firefox_lock_->Lock();
462 if (firefox_lock_->HasAcquired()) { 475 if (firefox_lock_->HasAcquired()) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 568
556 void ImporterHost::ImportEnded() { 569 void ImporterHost::ImportEnded() {
557 firefox_lock_.reset(); // Release the Firefox profile lock. 570 firefox_lock_.reset(); // Release the Firefox profile lock.
558 if (observer_) 571 if (observer_)
559 observer_->ImportEnded(); 572 observer_->ImportEnded();
560 Release(); 573 Release();
561 } 574 }
562 575
563 Importer* ImporterHost::CreateImporterByType(ProfileType type) { 576 Importer* ImporterHost::CreateImporterByType(ProfileType type) {
564 switch (type) { 577 switch (type) {
578 #if defined(OS_WIN)
565 case MS_IE: 579 case MS_IE:
566 return new IEImporter(); 580 return new IEImporter();
581 #endif
567 case BOOKMARKS_HTML: 582 case BOOKMARKS_HTML:
568 case FIREFOX2: 583 case FIREFOX2:
569 return new Firefox2Importer(); 584 return new Firefox2Importer();
570 case FIREFOX3: 585 case FIREFOX3:
571 return new Firefox3Importer(); 586 return new Firefox3Importer();
572 } 587 }
573 NOTREACHED(); 588 NOTREACHED();
574 return NULL; 589 return NULL;
575 } 590 }
576 591
577 int ImporterHost::GetAvailableProfileCount() { 592 int ImporterHost::GetAvailableProfileCount() {
578 return static_cast<int>(source_profiles_.size()); 593 return static_cast<int>(source_profiles_.size());
579 } 594 }
580 595
581 std::wstring ImporterHost::GetSourceProfileNameAt(int index) const { 596 std::wstring ImporterHost::GetSourceProfileNameAt(int index) const {
582 DCHECK(index < static_cast<int>(source_profiles_.size())); 597 DCHECK(index < static_cast<int>(source_profiles_.size()));
583 return source_profiles_[index]->description; 598 return source_profiles_[index]->description;
584 } 599 }
585 600
586 const ProfileInfo& ImporterHost::GetSourceProfileInfoAt(int index) const { 601 const ProfileInfo& ImporterHost::GetSourceProfileInfoAt(int index) const {
587 DCHECK(index < static_cast<int>(source_profiles_.size())); 602 DCHECK(index < static_cast<int>(source_profiles_.size()));
588 return *source_profiles_[index]; 603 return *source_profiles_[index];
589 } 604 }
590 605
591 void ImporterHost::DetectSourceProfiles() { 606 void ImporterHost::DetectSourceProfiles() {
607 #if defined(OS_WIN)
592 // The order in which detect is called determines the order 608 // The order in which detect is called determines the order
593 // in which the options appear in the dropdown combo-box 609 // in which the options appear in the dropdown combo-box
594 if (ShellIntegration::IsFirefoxDefaultBrowser()) { 610 if (ShellIntegration::IsFirefoxDefaultBrowser()) {
595 DetectFirefoxProfiles(); 611 DetectFirefoxProfiles();
596 DetectIEProfiles(); 612 DetectIEProfiles();
597 } else { 613 } else {
598 DetectIEProfiles(); 614 DetectIEProfiles();
599 DetectFirefoxProfiles(); 615 DetectFirefoxProfiles();
600 } 616 }
617 #else
618 DetectFirefoxProfiles();
619 #endif
601 } 620 }
602 621
622
623 #if defined(OS_WIN)
603 void ImporterHost::DetectIEProfiles() { 624 void ImporterHost::DetectIEProfiles() {
604 // IE always exists and don't have multiple profiles. 625 // IE always exists and don't have multiple profiles.
605 ProfileInfo* ie = new ProfileInfo(); 626 ProfileInfo* ie = new ProfileInfo();
606 ie->description = l10n_util::GetString(IDS_IMPORT_FROM_IE); 627 ie->description = l10n_util::GetString(IDS_IMPORT_FROM_IE);
607 ie->browser_type = MS_IE; 628 ie->browser_type = MS_IE;
608 ie->source_path.clear(); 629 ie->source_path.clear();
609 ie->app_path.clear(); 630 ie->app_path.clear();
610 ie->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | 631 ie->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS |
611 SEARCH_ENGINES; 632 SEARCH_ENGINES;
612 source_profiles_.push_back(ie); 633 source_profiles_.push_back(ie);
613 } 634 }
635 #endif
614 636
615 void ImporterHost::DetectFirefoxProfiles() { 637 void ImporterHost::DetectFirefoxProfiles() {
616 // Detects which version of Firefox is installed. 638 // Detects which version of Firefox is installed.
617 int version = GetCurrentFirefoxMajorVersion(); 639 int version = GetCurrentFirefoxMajorVersion();
618 ProfileType firefox_type; 640 ProfileType firefox_type;
619 if (version == 2) { 641 if (version == 2) {
620 firefox_type = FIREFOX2; 642 firefox_type = FIREFOX2;
621 } else if (version == 3) { 643 } else if (version == 3) {
622 firefox_type = FIREFOX3; 644 firefox_type = FIREFOX3;
623 } else { 645 } else {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 ProfileInfo* firefox = new ProfileInfo(); 692 ProfileInfo* firefox = new ProfileInfo();
671 firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX); 693 firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX);
672 firefox->browser_type = firefox_type; 694 firefox->browser_type = firefox_type;
673 firefox->source_path = source_path; 695 firefox->source_path = source_path;
674 firefox->app_path = GetFirefoxInstallPath(); 696 firefox->app_path = GetFirefoxInstallPath();
675 firefox->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS | 697 firefox->services_supported = HISTORY | FAVORITES | COOKIES | PASSWORDS |
676 SEARCH_ENGINES; 698 SEARCH_ENGINES;
677 source_profiles_.push_back(firefox); 699 source_profiles_.push_back(firefox);
678 } 700 }
679 } 701 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/importer.h ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698