Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import browser laptop stats #315

Merged
merged 2 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<message name="IDS_SETTINGS_IMPORT_COOKIES_CHECKBOX" desc="Checkbox for importing cookies">
Cookies
</message>
<message name="IDS_SETTINGS_IMPORT_STATS_CHECKBOX" desc="Checkbox for importing stats">
Stats
</message>
<message name="IDS_WIDEVINE_NOT_INSTALLED_EXPLANATORY_TEXT" desc="Explanatory animated text that appears (and then disappears) in the address line when Widevine is blocked">
Widevine is not installed
</message>
Expand Down
8 changes: 8 additions & 0 deletions browser/importer/brave_external_process_importer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@ void BraveExternalProcessImporterClient::OnCookiesImportGroup(
bridge_->SetCookies(cookies_);
}

void BraveExternalProcessImporterClient::OnStatsImportReady(
const BraveStats& stats) {
if (cancelled_)
return;

bridge_->UpdateStats(stats);
}

BraveExternalProcessImporterClient::~BraveExternalProcessImporterClient() {}
4 changes: 4 additions & 0 deletions browser/importer/brave_external_process_importer_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "chrome/browser/importer/external_process_importer_client.h"
#include "net/cookies/canonical_cookie.h"

struct BraveStats;

class BraveExternalProcessImporterClient : public ExternalProcessImporterClient {
public:
BraveExternalProcessImporterClient(
Expand All @@ -26,6 +28,8 @@ class BraveExternalProcessImporterClient : public ExternalProcessImporterClient
uint32_t total_cookies_count) override;
void OnCookiesImportGroup(
const std::vector<net::CanonicalCookie>& cookies_group) override;
void OnStatsImportReady(
const BraveStats& stats) override;

private:
~BraveExternalProcessImporterClient() override;
Expand Down
4 changes: 4 additions & 0 deletions browser/importer/brave_in_process_importer_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ void BraveInProcessImporterBridge::SetCookies(
writer_->AddCookies(cookies);
}

void BraveInProcessImporterBridge::UpdateStats(const BraveStats& stats) {
writer_->UpdateStats(stats);
}

BraveInProcessImporterBridge::~BraveInProcessImporterBridge() {}
1 change: 1 addition & 0 deletions browser/importer/brave_in_process_importer_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class BraveInProcessImporterBridge : public InProcessImporterBridge {

void SetCookies(
const std::vector<net::CanonicalCookie>& cookies) override;
void UpdateStats(const BraveStats& stats) override;

private:
~BraveInProcessImporterBridge() override;
Expand Down
15 changes: 15 additions & 0 deletions browser/importer/brave_profile_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/importer/brave_profile_writer.h"
#include "brave/common/importer/brave_stats.h"
#include "brave/common/pref_names.h"
#include "brave/utility/importer/brave_importer.h"

#include "base/time/time.h"
#include "chrome/browser/profiles/profile.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
#include "components/prefs/pref_service.h"
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_constants.h"
#include "net/url_request/url_request_context.h"
Expand Down Expand Up @@ -36,3 +40,14 @@ void BraveProfileWriter::AddCookies(
network::mojom::CookieManager::SetCanonicalCookieCallback());
}
}

void BraveProfileWriter::UpdateStats(const BraveStats& stats) {
PrefService* prefs = profile_->GetOriginalProfile()->GetPrefs();

prefs->SetUint64(kAdsBlocked,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to block on this @garrettr but if you have time for a follow up I'd prefer to have this take the greater of the 2 stats and use that. That way someone can't as easily game it by importing multiple times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bbondy Blocking on that is no problem, it's a quick fix! I'll do it right now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was too fast for you, so you'll have to PR again, but can be from the same branch obviously.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I wasn't too fast for you but I was too slow to read your reply and too fast to merge 😆

prefs->GetUint64(kAdsBlocked) + stats.adblock_count);
prefs->SetUint64(kTrackersBlocked,
prefs->GetUint64(kTrackersBlocked) + stats.trackingProtection_count);
prefs->SetUint64(kHttpsUpgrades,
prefs->GetUint64(kHttpsUpgrades) + stats.httpsEverywhere_count);
}
3 changes: 3 additions & 0 deletions browser/importer/brave_profile_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
#include "chrome/browser/importer/profile_writer.h"
#include "net/cookies/canonical_cookie.h"

struct BraveStats;

class BraveProfileWriter : public ProfileWriter {
public:
explicit BraveProfileWriter(Profile* profile);

virtual void AddCookies(const std::vector<net::CanonicalCookie>& cookies);
virtual void UpdateStats(const BraveStats& stats);

protected:
friend class base::RefCountedThreadSafe<BraveProfileWriter>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace settings {
#if !defined(OS_CHROMEOS)
void BraveAddImportDataStrings(content::WebUIDataSource* html_source) {
LocalizedString localized_strings[] = {
{"importCookies", IDS_SETTINGS_IMPORT_COOKIES_CHECKBOX}
{"importCookies", IDS_SETTINGS_IMPORT_COOKIES_CHECKBOX},
{"importStats", IDS_SETTINGS_IMPORT_STATS_CHECKBOX}
};
AddLocalizedStringsBulk(html_source, localized_strings,
arraysize(localized_strings));
Expand Down
1 change: 1 addition & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ source_set("common") {
"extensions/manifest_handlers/pdfjs_manifest_override.h",
"importer/brave_importer_utils.cc",
"importer/brave_importer_utils.h",
"importer/brave_stats.h",
"importer/chrome_importer_utils.cc",
"importer/chrome_importer_utils.h",
"network_constants.cc",
Expand Down
2 changes: 1 addition & 1 deletion common/importer/brave_importer_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool BraveImporterCanImport(const base::FilePath& profile,
if (base::PathExists(history))
*services_supported |= importer::HISTORY;
if (base::PathExists(session_store))
*services_supported |= importer::FAVORITES;
*services_supported |= importer::FAVORITES | importer::STATS;
if (base::PathExists(passwords))
*services_supported |= importer::PASSWORDS;
if (base::PathExists(cookies))
Expand Down
5 changes: 5 additions & 0 deletions common/importer/brave_mock_importer_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@

#include <vector>

#include "brave/common/importer/brave_stats.h"
#include "chrome/common/importer/mock_importer_bridge.h"
#include "net/cookies/canonical_cookie.h"
#include "testing/gmock/include/gmock/gmock.h"

struct BraveStats;

class BraveMockImporterBridge : public MockImporterBridge {
public:
BraveMockImporterBridge();

MOCK_METHOD1(SetCookies,
void(const std::vector<net::CanonicalCookie>&));
MOCK_METHOD1(UpdateStats,
void(const BraveStats&));

private:
~BraveMockImporterBridge() override;
Expand Down
19 changes: 19 additions & 0 deletions common/importer/brave_stats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMMON_IMPORTER_BRAVE_STATS_H_
#define BRAVE_COMMON_IMPORTER_BRAVE_STATS_H_

struct BraveStats {
int adblock_count;
int trackingProtection_count;
int httpsEverywhere_count;

BraveStats()
: adblock_count(0),
trackingProtection_count(0),
httpsEverywhere_count(0) {}
};

#endif // BRAVE_COMMON_IMPORTER_BRAVE_STATS_H_
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
diff --git a/chrome/browser/extensions/api/settings_private/prefs_util.cc b/chrome/browser/extensions/api/settings_private/prefs_util.cc
index b4019834b8be721576b0c832e722696584bb38c6..15f69c83ab5063202c6d22f52842bd23a52b4e61 100644
index b4019834b8be721576b0c832e722696584bb38c6..93173d1a8a1e313b7f741397a95ee220d609d010 100644
--- a/chrome/browser/extensions/api/settings_private/prefs_util.cc
+++ b/chrome/browser/extensions/api/settings_private/prefs_util.cc
@@ -499,6 +499,8 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
@@ -499,6 +499,10 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[::prefs::kImportDialogSearchEngine] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
+ (*s_whitelist)[::prefs::kImportDialogCookies] =
+ settings_api::PrefType::PREF_TYPE_BOOLEAN;
+ (*s_whitelist)[::prefs::kImportDialogStats] =
+ settings_api::PrefType::PREF_TYPE_BOOLEAN;
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
diff --git a/chrome/browser/importer/external_process_importer_client.h b/chrome/browser/importer/external_process_importer_client.h
index 864a6951115dda5ed74963f18b35692960397d50..477c51b320a3f41b75ab36bf7e1780d1aae6e701 100644
index 864a6951115dda5ed74963f18b35692960397d50..ba056b13fbae07f151286f531e1a8d86e0eac2c5 100644
--- a/chrome/browser/importer/external_process_importer_client.h
+++ b/chrome/browser/importer/external_process_importer_client.h
@@ -24,6 +24,7 @@
@@ -24,10 +24,12 @@
#include "components/favicon_base/favicon_usage_data.h"
#include "components/history/core/browser/history_types.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "net/cookies/canonical_cookie.h"

class ExternalProcessImporterHost;
struct ImportedBookmarkEntry;
@@ -88,6 +89,8 @@ class ExternalProcessImporterClient
class InProcessImporterBridge;
+struct BraveStats;

namespace autofill {
struct PasswordForm;
@@ -88,6 +90,9 @@ class ExternalProcessImporterClient
void OnAutofillFormDataImportGroup(
const std::vector<ImporterAutofillFormDataEntry>&
autofill_form_data_entry_group) override;
+ void OnCookiesImportStart(uint32_t total_cookies_count) override {};
+ void OnCookiesImportGroup(const std::vector<net::CanonicalCookie>& cookies_group) override {};
+ void OnStatsImportReady(const BraveStats& stats) override {};
void OnIE7PasswordReceived(
const importer::ImporterIE7PasswordInfo& importer_password_info) override;

Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
diff --git a/chrome/browser/resources/settings/people_page/import_data_dialog.html b/chrome/browser/resources/settings/people_page/import_data_dialog.html
index fdd6f9d2265fe069d159ceed6e1e7ec561a2915e..a3f47eca2998e76569bff76a467807013403bff3 100644
index fdd6f9d2265fe069d159ceed6e1e7ec561a2915e..e0dee6f2af7b92dd2b7f88fefbfda92f7a9b3f02 100644
--- a/chrome/browser/resources/settings/people_page/import_data_dialog.html
+++ b/chrome/browser/resources/settings/people_page/import_data_dialog.html
@@ -94,6 +94,11 @@
@@ -94,6 +94,16 @@
pref="{{prefs.import_dialog_autofill_form_data}}"
label="$i18n{importAutofillFormData}">
</settings-checkbox>
+ <settings-checkbox
+ hidden="[[!selected_.cookies]]"
+ pref="{{prefs.import_dialog_cookies}}"
+ label="$i18n{importCookies}">
+ </settings-checkbox>
+ <settings-checkbox
+ hidden="[[!selected_.stats]]"
+ pref="{{prefs.import_dialog_stats}}"
+ label="$i18n{importStats}">
+ </settings-checkbox>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
diff --git a/chrome/browser/resources/settings/people_page/import_data_dialog.js b/chrome/browser/resources/settings/people_page/import_data_dialog.js
index f59448f4b4a25ab8b5e13c23feafa7957e83fa82..1dcdb0fbfa38deb10418074b9c0f02ee75221591 100644
index f59448f4b4a25ab8b5e13c23feafa7957e83fa82..bfcb5e3e5c846b99f59ba49274881dece8302e87 100644
--- a/chrome/browser/resources/settings/people_page/import_data_dialog.js
+++ b/chrome/browser/resources/settings/people_page/import_data_dialog.js
@@ -84,7 +84,9 @@ Polymer({
@@ -84,7 +84,11 @@ Polymer({
!(this.getPref('import_dialog_search_engine').value &&
this.selected_.search) &&
!(this.getPref('import_dialog_autofill_form_data').value &&
- this.selected_.autofillFormData);
+ this.selected_.autofillFormData) &&
+ !(this.getPref('import_dialog_cookies').value &&
+ this.selected_.cookies);
+ this.selected_.cookies) &&
+ !(this.getPref('import_dialog_stats').value &&
+ this.selected_.stats);
},

/**
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
diff --git a/chrome/browser/ui/webui/settings/md_settings_ui.cc b/chrome/browser/ui/webui/settings/md_settings_ui.cc
index 954647cb963e995c15d903e91689c4927ba3ad29..3d9a2ad9d363cf1504ac7beea248d368f4cb5ace 100644
index 954647cb963e995c15d903e91689c4927ba3ad29..7ba86990b1f630398bc373c680dd977d9b540d89 100644
--- a/chrome/browser/ui/webui/settings/md_settings_ui.cc
+++ b/chrome/browser/ui/webui/settings/md_settings_ui.cc
@@ -131,6 +131,7 @@ void MdSettingsUI::RegisterProfilePrefs(
@@ -131,6 +131,8 @@ void MdSettingsUI::RegisterProfilePrefs(
registry->RegisterBooleanPref(prefs::kImportDialogHistory, true);
registry->RegisterBooleanPref(prefs::kImportDialogSavedPasswords, true);
registry->RegisterBooleanPref(prefs::kImportDialogSearchEngine, true);
+ registry->RegisterBooleanPref(prefs::kImportDialogCookies, true);
+ registry->RegisterBooleanPref(prefs::kImportDialogStats, true);
}

MdSettingsUI::MdSettingsUI(content::WebUI* web_ui)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/chrome/browser/ui/webui/settings/settings_import_data_handler.cc b/chrome/browser/ui/webui/settings/settings_import_data_handler.cc
index 32deebd14fb3383010af01381af9b34442d19b6e..4ee9444e28d9041c3b1dd97fd81f0ce387635982 100644
index 32deebd14fb3383010af01381af9b34442d19b6e..750216677fccfd62a36937cf020341c0b180732c 100644
--- a/chrome/browser/ui/webui/settings/settings_import_data_handler.cc
+++ b/chrome/browser/ui/webui/settings/settings_import_data_handler.cc
@@ -18,6 +18,8 @@
Expand All @@ -26,21 +26,25 @@ index 32deebd14fb3383010af01381af9b34442d19b6e..4ee9444e28d9041c3b1dd97fd81f0ce3

importer::LogImporterUseToMetrics("ImportDataHandler",
source_profile.importer_type);
@@ -126,6 +128,8 @@ void ImportDataHandler::ImportData(const base::ListValue* args) {
@@ -126,6 +128,10 @@ void ImportDataHandler::ImportData(const base::ListValue* args) {
selected_items |= importer::PASSWORDS;
if (prefs->GetBoolean(prefs::kImportDialogSearchEngine))
selected_items |= importer::SEARCH_ENGINES;
+ if (prefs->GetBoolean(prefs::kImportDialogCookies))
+ selected_items |= importer::COOKIES;
+ if (prefs->GetBoolean(prefs::kImportDialogStats))
+ selected_items |= importer::STATS;

const importer::SourceProfile& source_profile =
importer_list_->GetSourceProfileAt(browser_index);
@@ -179,6 +183,8 @@ void ImportDataHandler::SendBrowserProfileData(const std::string& callback_id) {
@@ -179,6 +185,10 @@ void ImportDataHandler::SendBrowserProfileData(const std::string& callback_id) {
browser_profile->SetBoolean(
"autofillFormData",
(browser_services & importer::AUTOFILL_FORM_DATA) != 0);
+ browser_profile->SetBoolean("cookies",
+ (browser_services & importer::COOKIES) != 0);
+ browser_profile->SetBoolean("stats",
+ (browser_services & importer::STATS) != 0);

browser_profiles.Append(std::move(browser_profile));
}
14 changes: 11 additions & 3 deletions patches/chrome-common-importer-importer_bridge.h.patch
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
diff --git a/chrome/common/importer/importer_bridge.h b/chrome/common/importer/importer_bridge.h
index 56d4259aba433df997802109cf5a8d28c03ebd13..dcbb15bba51eb79c086e2b1dec05e04683796993 100644
index 56d4259aba433df997802109cf5a8d28c03ebd13..26bb05d70c9674cab27112704b8957972ff2dab5 100644
--- a/chrome/common/importer/importer_bridge.h
+++ b/chrome/common/importer/importer_bridge.h
@@ -15,6 +15,7 @@
@@ -15,10 +15,12 @@
#include "chrome/common/importer/importer_data_types.h"
#include "chrome/common/importer/importer_url_row.h"
#include "components/favicon_base/favicon_usage_data.h"
+#include "net/cookies/canonical_cookie.h"

class GURL;
struct ImportedBookmarkEntry;
@@ -66,6 +67,9 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> {
struct ImporterAutofillFormDataEntry;
+struct BraveStats;

namespace autofill {
struct PasswordForm;
@@ -66,6 +68,12 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> {
virtual void SetAutofillFormData(
const std::vector<ImporterAutofillFormDataEntry>& entries) = 0;

+ virtual void SetCookies(
+ const std::vector<net::CanonicalCookie>& cookies) {};
+
+ virtual void UpdateStats(
+ const BraveStats& stats) {};
+
// Notifies the coordinator that the import operation has begun.
virtual void NotifyStarted() = 0;
Expand Down
14 changes: 12 additions & 2 deletions patches/chrome-common-importer-importer_data_types.h.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
diff --git a/chrome/common/importer/importer_data_types.h b/chrome/common/importer/importer_data_types.h
index 0fc90c62398a93eb89568ce78c8ded2bc9b232b6..cd3301cdbab878231050dbdf66d4572852d0a331 100644
index 0fc90c62398a93eb89568ce78c8ded2bc9b232b6..875839c01d9b18dc705c421a4287c82cb401c376 100644
--- a/chrome/common/importer/importer_data_types.h
+++ b/chrome/common/importer/importer_data_types.h
@@ -83,6 +83,8 @@ enum VisitSource {
@@ -31,7 +31,8 @@ enum ImportItem {
SEARCH_ENGINES = 1 << 4,
HOME_PAGE = 1 << 5,
AUTOFILL_FORM_DATA = 1 << 6,
- ALL = (1 << 7) - 1 // All the bits should be 1, hence the -1.
+ STATS = 1 << 7,
+ ALL = (1 << 8) - 1 // All the bits should be 1, hence the -1.
};

// Information about a profile needed by an importer to do import work.
@@ -83,6 +84,8 @@ enum VisitSource {
VISIT_SOURCE_FIREFOX_IMPORTED = 1,
VISIT_SOURCE_IE_IMPORTED = 2,
VISIT_SOURCE_SAFARI_IMPORTED = 3,
Expand Down
Loading