Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #197 from brave/bl8849
Browse files Browse the repository at this point in the history
Fix broken import cookies
  • Loading branch information
bridiver authored May 16, 2017
2 parents 1b4abcb + 8d5a1de commit 89405c8
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 12 deletions.
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "brave/browser/brave_content_browser_client.h"
#include "chrome/browser/importer/external_process_importer_host.h"
#include "brave/browser/importer/brave_external_process_importer_host.h"
#include "chrome/browser/importer/importer_list.h"
#include "content/public/browser/browser_thread.h"
#include "native_mate/dictionary.h"
Expand Down Expand Up @@ -121,7 +121,7 @@ void Importer::StartImport(

import_did_succeed_ = false;

importer_host_ = new ExternalProcessImporterHost();
importer_host_ = new BraveExternalProcessImporterHost();
importer_host_->set_observer(this);
importer_host_->StartImportSettings(source_profile, NULL,
imported_items,
Expand Down
2 changes: 2 additions & 0 deletions brave/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ source_set("browser") {
"brave_javascript_dialog_manager.cc",
"brave_permission_manager.h",
"brave_permission_manager.cc",
"importer/brave_external_process_importer_host.cc",
"importer/brave_external_process_importer_host.h",
"password_manager/brave_credentials_filter.h",
"password_manager/brave_credentials_filter.cc",
"password_manager/brave_password_manager_client.h",
Expand Down
31 changes: 31 additions & 0 deletions brave/browser/importer/brave_external_process_importer_host.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2017 The Brave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "brave/browser/importer/brave_external_process_importer_host.h"

#include "atom/browser/importer/external_process_importer_client.h"
#include "atom/browser/importer/in_process_importer_bridge.h"

BraveExternalProcessImporterHost::BraveExternalProcessImporterHost()
: ExternalProcessImporterHost() {}

void BraveExternalProcessImporterHost::LaunchImportIfReady() {
if (waiting_for_bookmarkbar_model_ || template_service_subscription_.get() ||
!is_source_readable_ || cancelled_)
return;

// This is the in-process half of the bridge, which catches data from the IPC
// pipe and feeds it to the ProfileWriter. The external process half of the
// bridge lives in the external process (see ProfileImportThread).
// The ExternalProcessImporterClient created in the next line owns the bridge,
// and will delete it.
atom::InProcessImporterBridge* bridge =
new atom::InProcessImporterBridge(writer_.get(),
weak_ptr_factory_.GetWeakPtr());
client_ = new atom::ExternalProcessImporterClient(
weak_ptr_factory_.GetWeakPtr(), source_profile_, items_, bridge);
client_->Start();
}

BraveExternalProcessImporterHost::~BraveExternalProcessImporterHost() {}
26 changes: 26 additions & 0 deletions brave/browser/importer/brave_external_process_importer_host.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2017 The Brave Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_
#define BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_

#include "chrome/browser/importer/external_process_importer_host.h"

class BraveExternalProcessImporterHost : public ExternalProcessImporterHost {
public:
BraveExternalProcessImporterHost();

private:
~BraveExternalProcessImporterHost() override;

// Launches the utility process that starts the import task, unless bookmark
// or template model are not yet loaded. If load is not detected, this method
// will be called when the loading observer sees that model loading is
// complete.
void LaunchImportIfReady() override;

DISALLOW_COPY_AND_ASSIGN(BraveExternalProcessImporterHost);
};

#endif // BRAVE_BROWSER_IMPORTER_BRAVE_EXTERNAL_PROCESS_IMPORTER_HOST_H_
4 changes: 2 additions & 2 deletions brave/utility/importer/chrome_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <memory>
#include <string>

#include "atom/browser/importer/in_process_importer_bridge.h"
#include "brave/utility/importer/brave_external_process_importer_bridge.h"
#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/macros.h"
Expand Down Expand Up @@ -246,7 +246,7 @@ void ChromeImporter::ImportCookies() {
}

if (!cookies.empty() && !cancelled())
static_cast<atom::InProcessImporterBridge*>(bridge_.get())->
static_cast<BraveExternalProcessImporterBridge*>(bridge_.get())->
SetCookies(cookies);
}

Expand Down
7 changes: 2 additions & 5 deletions brave/utility/importer/firefox_importer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <vector>

#include "atom/browser/importer/in_process_importer_bridge.h"
#include "brave/utility/importer/brave_external_process_importer_bridge.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/macros.h"
Expand All @@ -33,15 +33,12 @@ void FirefoxImporter::StartImport(const importer::SourceProfile& source_profile,

bridge_ = bridge;
source_path_ = source_profile.source_path;

bridge_->NotifyStarted();
if ((items & importer::COOKIES) && !cancelled()) {
bridge_->NotifyItemStarted(importer::COOKIES);
ImportCookies();
bridge_->NotifyItemEnded(importer::COOKIES);
}
bridge_->NotifyEnded();
bridge_->NotifyEnded();
}


Expand Down Expand Up @@ -86,7 +83,7 @@ void FirefoxImporter::ImportCookies() {
}

if (!cookies.empty() && !cancelled())
static_cast<atom::InProcessImporterBridge*>(bridge_.get())->
static_cast<BraveExternalProcessImporterBridge*>(bridge_.get())->
SetCookies(cookies);
}

Expand Down
2 changes: 1 addition & 1 deletion brave/utility/importer/importer_creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ scoped_refptr<Importer> CreateImporterByType(importer::ImporterType type) {
case importer::TYPE_BOOKMARKS_FILE:
return new BookmarksFileImporter();
case importer::TYPE_FIREFOX:
return new FirefoxImporter();
return new brave::FirefoxImporter();
#if defined(OS_MACOSX)
case importer::TYPE_SAFARI:
return new SafariImporter(base::mac::GetUserLibraryPath());
Expand Down
17 changes: 15 additions & 2 deletions patches/master_patch.patch
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,17 @@ index edf5cc054ac3c703cc049509aed223313a875001..6c5f76eb7f8082afa02f6d0721efa3dc
const importer::ImporterIE7PasswordInfo& importer_password_info) override;

diff --git a/chrome/browser/importer/external_process_importer_host.h b/chrome/browser/importer/external_process_importer_host.h
index 08c6f28746cc5f345114a942834db18f5c7a1d41..45b3b8072cc352d3fc2824489b2b59a2cee38ec3 100644
index 08c6f28746cc5f345114a942834db18f5c7a1d41..3a43ae76f054ba449e3b892ea752c62fdad2e5a3 100644
--- a/chrome/browser/importer/external_process_importer_host.h
+++ b/chrome/browser/importer/external_process_importer_host.h
@@ -74,7 +74,9 @@ class ExternalProcessImporterHost
@@ -74,7 +74,10 @@ class ExternalProcessImporterHost

private:
// ExternalProcessImporterHost deletes itself in OnImportEnded().
+ protected:
~ExternalProcessImporterHost() override;
+ private:
+ friend class BraveExternalProcessImporterHost;

// Launches the utility process that starts the import task, unless bookmark
// or template model are not yet loaded. If load is not detected, this method
Expand Down Expand Up @@ -831,6 +832,18 @@ index 7e05c4e04f8e61b418d373a73bd8901347df4c76..e7e6d9fa5e0d54c7755fe3a38eca6f70

// Holds strings needed by the external importer because the resource
// bundle isn't available to the external process.
diff --git a/chrome/utility/importer/firefox_importer.cc b/chrome/utility/importer/firefox_importer.cc
index 7f8d598bca0243e62f11d5d2ce50d8c25ba88764..d198d90e8872eb1d7a371aeaca6119c73a6cda1c 100644
--- a/chrome/utility/importer/firefox_importer.cc
+++ b/chrome/utility/importer/firefox_importer.cc
@@ -147,7 +147,6 @@ void FirefoxImporter::StartImport(const importer::SourceProfile& source_profile,
ImportAutofillFormData();
bridge_->NotifyItemEnded(importer::AUTOFILL_FORM_DATA);
}
- bridge_->NotifyEnded();
}

void FirefoxImporter::ImportHistory() {
diff --git a/chrome/utility/importer/firefox_importer.h b/chrome/utility/importer/firefox_importer.h
index c3f648f165483a2d618438c1a4ef1b35ad6fb10c..3c95e1256465b7b6a009d3bf7619c8f48e2d3d94 100644
--- a/chrome/utility/importer/firefox_importer.h
Expand Down

0 comments on commit 89405c8

Please sign in to comment.