Skip to content

Commit

Permalink
Merge pull request #226 from brave/WIP_sync
Browse files Browse the repository at this point in the history
Sync
  • Loading branch information
AlexeyBarabash authored Nov 1, 2018
2 parents 332a98c + c5853d8 commit d8e7d68
Show file tree
Hide file tree
Showing 118 changed files with 9,245 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/browser/resources/brave_extension/
/components/brave_webtorrent/extension/out/
/components/brave_rewards/resources/extension/brave_rewards/out/
/components/brave_sync/extension/brave-crypto/
/components/brave_sync/extension/brave-sync/
/dist/
/out/
/vendor
Expand Down
14 changes: 14 additions & 0 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ deps = {
"vendor/bip39wally-core-native": "https://github.com/brave-intl/bip39wally-core-native.git@9b119931c702d55be994117eb505d56310720b1d",
"vendor/bat-native-anonize": "https://github.com/brave-intl/bat-native-anonize.git@adeff3254bb90ccdc9699040d5a4e1cd6b8393b7",
"vendor/bat-native-tweetnacl": "https://github.com/brave-intl/bat-native-tweetnacl.git@1b4362968c8f22720bfb75af6f506d4ecc0f3116",
"components/brave_sync/extension/brave-sync": "https://github.com/brave/sync.git@ff9c7f3bdea37e8cc1cb08eff48123fd9add6da9",
"components/brave_sync/extension/brave-crypto": "https://github.com/brave/crypto@c07866c3b9c8264195756a81112bb74b8fa90858",
}

hooks = [
Expand All @@ -37,5 +39,17 @@ hooks = [
'condition': 'not checkout_android',
'pattern': '.',
'action': ['python', 'src/brave/script/init-brave-extension.py'],
},
{
# Build brave-sync
'name': 'build_brave_sync',
'pattern': '.',
'action': ['python', 'src/brave/script/build-simple-js-bundle.py', '--repo_dir_path', 'src/brave/components/brave_sync/extension/brave-sync'],
},
{
# Build brave-crypto
'name': 'build_brave_crypto',
'pattern': '.',
'action': ['python', 'src/brave/script/build-simple-js-bundle.py', '--repo_dir_path', 'src/brave/components/brave_sync/extension/brave-crypto'],
}
]
1 change: 1 addition & 0 deletions app/brave_command_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define IDC_NEW_TOR_IDENTITY 56002
#define IDC_NEW_OFFTHERECORD_WINDOW_TOR 56003
#define IDC_CONTENT_CONTEXT_OPENLINKTOR 56004
#define IDC_SHOW_BRAVE_SYNC 56005

#define IDC_BRAVE_COMMANDS_LAST 57000

Expand Down
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<message name="IDS_SHOW_BRAVE_ADBLOCK" desc="The show Brave Ad Block menu in the app menu">
Brave Ad Block
</message>
<message name="IDS_SHOW_BRAVE_SYNC" desc="The show brave sync menu in the app menu">
Brave Sync
</message>
<message name="IDS_EXTENSION_CANT_INSTALL_ON_BRAVE" desc="Error message when user tries to install an extension that is not allowed in Brave.">
<ph name="EXTENSION_NAME">$1</ph> (extension ID "<ph name="EXTENSION_ID">$2<ex>abacabadabacabaeabacabadabacabaf</ex></ph>") is not allowed in Brave.
</message>
Expand Down
4 changes: 3 additions & 1 deletion brave_paks.gni
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ template("brave_extra_paks") {
"$root_gen_dir/brave/components/brave_rewards/resources/extension/brave_rewards_extension_resources.pak",
"$target_gen_dir/browser/resources/brave_extension.pak",
"$target_gen_dir/components/brave_webtorrent/brave_webtorrent_resources.pak",
"$target_gen_dir/components/brave_sync/brave_sync_resources.pak",
]

deps = [
Expand All @@ -75,7 +76,8 @@ template("brave_extra_paks") {
"//brave/components/resources:strings",
"//brave/browser/resources:brave_extension_grit",
"//brave/browser/resources:brave_settings_resources",
"//brave/common/extensions/api"
"//brave/common/extensions/api",
"//brave/components/brave_sync:resources",
]

if (defined(invoker.deps)) {
Expand Down
4 changes: 4 additions & 0 deletions browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ source_set("browser_process") {
"autocomplete/brave_autocomplete_provider_client.h",
"autocomplete/brave_autocomplete_scheme_classifier.cc",
"autocomplete/brave_autocomplete_scheme_classifier.h",
"bookmarks/brave_bookmark_client.cc",
"bookmarks/brave_bookmark_client.h",
"brave_browser_main_extra_parts.cc",
"brave_browser_main_extra_parts.h",
"brave_browser_main_parts_mac.mm",
Expand Down Expand Up @@ -60,6 +62,8 @@ source_set("browser_process") {
"//brave/common",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_shields/browser:brave_shields",
"//brave/components/brave_sync",
"//brave/components/content_settings/core/browser",
"//chrome/common",
"//components/component_updater",
"//components/prefs",
Expand Down
31 changes: 31 additions & 0 deletions browser/bookmarks/brave_bookmark_client.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* 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/. */

#include "brave/browser/bookmarks/brave_bookmark_client.h"

#include "brave/components/brave_sync/brave_sync_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
#include "components/sync_bookmarks/bookmark_sync_service.h"

BraveBookmarkClient::BraveBookmarkClient(
Profile* profile,
bookmarks::ManagedBookmarkService* managed_bookmark_service,
sync_bookmarks::BookmarkSyncService* bookmark_sync_service)
: ChromeBookmarkClient(profile,
managed_bookmark_service,
bookmark_sync_service) {}

bookmarks::LoadExtraCallback BraveBookmarkClient::GetLoadExtraNodesCallback() {
return base::BindOnce(&brave_sync::LoadExtraNodes,
ChromeBookmarkClient::GetLoadExtraNodesCallback());
}

bool BraveBookmarkClient::IsPermanentNodeVisible(
const bookmarks::BookmarkPermanentNode* node) {
if (brave_sync::IsSyncManagedNode(node))
return false; // don't display sync managed nodes
return ChromeBookmarkClient::IsPermanentNodeVisible(node);
}
25 changes: 25 additions & 0 deletions browser/bookmarks/brave_bookmark_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_
#define BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_

#include "chrome/browser/bookmarks/chrome_bookmark_client.h"

class BraveBookmarkClient : public ChromeBookmarkClient {
public:
BraveBookmarkClient(
Profile* profile,
bookmarks::ManagedBookmarkService* managed_bookmark_service,
sync_bookmarks::BookmarkSyncService* bookmark_sync_service);

bookmarks::LoadExtraCallback GetLoadExtraNodesCallback() override;
bool IsPermanentNodeVisible(
const bookmarks::BookmarkPermanentNode* node) override;

private:
DISALLOW_COPY_AND_ASSIGN(BraveBookmarkClient);
};

#endif // BRAVE_BROWSER_BOOKMARKS_BRAVE_BOOKMARK_CLIENT_H_
2 changes: 2 additions & 0 deletions browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

#include "brave/browser/tor/tor_profile_service_factory.h"
#include "brave/components/brave_rewards/browser/rewards_service_factory.h"
#include "brave/components/brave_sync/brave_sync_service_factory.h"

namespace brave {

void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
brave_rewards::RewardsServiceFactory::GetInstance();
brave_sync::BraveSyncServiceFactory::GetInstance();
TorProfileServiceFactory::GetInstance();
}

Expand Down
1 change: 1 addition & 0 deletions browser/extensions/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ source_set("extensions") {
"//brave/browser/resources:brave_extension_grit",
"//brave/common/extensions/api",
"//brave/components/brave_rewards/resources/extension:resources",
"//brave/components/brave_sync:resources",
"//brave/components/brave_webtorrent:resources",
"//chrome/browser",
"//content/public/browser",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "brave/browser/resources/grit/brave_extension_resources_map.h"
#include "brave/components/brave_rewards/resources/extension/grit/brave_rewards_extension_resources_map.h"
#include "brave/components/brave_sync/grit/brave_sync_resources_map.h"
#include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources_map.h"

namespace extensions {
Expand All @@ -20,6 +21,10 @@ BraveComponentExtensionResourceManager() {
kBraveRewardsExtensionResources,
kBraveRewardsExtensionResourcesSize);

AddComponentResourceEntries(
kBraveSyncResources,
kBraveSyncResourcesSize);

AddComponentResourceEntries(
kBraveWebtorrentResources,
kBraveWebtorrentResourcesSize);
Expand Down
6 changes: 4 additions & 2 deletions browser/extensions/brave_extension_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ bool BraveExtensionProvider::IsVetted(const Extension* extension) {
static std::vector<std::string> vetted_extensions({
brave_extension_id,
brave_rewards_extension_id,
brave_sync_extension_id,
brave_webtorrent_extension_id,
pdfjs_extension_id,
// 1Password
Expand Down Expand Up @@ -96,7 +97,7 @@ bool BraveExtensionProvider::IsVetted(const Extension* extension) {
// Test ID: Brave HTTPS Everywhere Updater
"bhlmpjhncoojbkemjkeppfahkglffilp",
// Test ID: Brave Tor Client Updater
"ngicbhhaldfdgmjhilmnleppfpmkgbbk"
"ngicbhhaldfdgmjhilmnleppfpmkgbbk",
});
return std::find(vetted_extensions.begin(), vetted_extensions.end(),
extension->id()) != vetted_extensions.end();
Expand Down Expand Up @@ -138,7 +139,8 @@ bool BraveExtensionProvider::MustRemainInstalled(const Extension* extension,
base::string16* error) const {
return extension->id() == brave_extension_id ||
extension->id() == brave_rewards_extension_id ||
extension->id() == brave_webtorrent_extension_id;
extension->id() == brave_webtorrent_extension_id ||
extension->id() == brave_sync_extension_id;
}

} // namespace extensions
1 change: 1 addition & 0 deletions browser/profiles/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ source_set("profiles") {
"//brave/browser/extensions",
"//brave/browser/tor",
"//brave/common/tor",
"//brave/components/brave_sync",
"//ui/base",
]
}
9 changes: 9 additions & 0 deletions browser/profiles/brave_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "brave/browser/tor/tor_profile_service_factory.h"
#include "brave/common/tor/pref_names.h"
#include "brave/common/tor/tor_constants.h"
#include "brave/components/brave_sync/brave_sync_service_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -89,6 +90,14 @@ BraveProfileManager::CreateProfileAsyncHelper(const base::FilePath& path,
return profile;
}

void BraveProfileManager::DoFinalInitForServices(Profile* profile,
bool go_off_the_record) {
ProfileManager::DoFinalInitForServices(profile, go_off_the_record);
// BraveSyncService need to be created when profile initialized, otherwise
// it will only be constructed only when we open chrome://bravesync
brave_sync::BraveSyncServiceFactory::GetForProfile(profile);
}

void BraveProfileManager::LaunchTorProcess(Profile* profile) {
tor::TorProfileService* tor_profile_service =
TorProfileServiceFactory::GetForProfile(profile);
Expand Down
2 changes: 2 additions & 0 deletions browser/profiles/brave_profile_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class BraveProfileManager : public ProfileManager {
Profile* CreateProfileHelper(const base::FilePath& path) override;
Profile* CreateProfileAsyncHelper(const base::FilePath& path,
Delegate* delegate) override;
void DoFinalInitForServices(Profile* profile,
bool go_off_the_record) override;
private:
void LaunchTorProcess(Profile* profile);

Expand Down
3 changes: 3 additions & 0 deletions browser/resources/resource_ids
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"brave/app/theme/brave_unscaled_resources.grd": {
"includes": [36500],
},
"brave/components/brave_sync/resources.grd": {
"includes": [37000]
},
# brave webtorrent 37500
"brave/components/brave_rewards/resources/extension/extension_resources.grd": {
"includes": [38000]
Expand Down
5 changes: 5 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ source_set("ui") {
"webui/settings/brave_privacy_handler.h",
"webui/settings/default_brave_shields_handler.cc",
"webui/settings/default_brave_shields_handler.h",
"webui/sync/sync_ui.cc",
"webui/sync/sync_ui.h",
]

if (enable_widevine_cdm_component) {
Expand Down Expand Up @@ -110,7 +112,10 @@ source_set("ui") {
"//brave/app/theme:brave_unscaled_resources",
"//brave/app/theme:brave_theme_resources",
"//brave/app/vector_icons:vector_icons",
"//brave/common",
"//brave/components/brave_rewards/browser",
"//brave/components/brave_sync",
"//brave/components/brave_sync:resources",
"//brave/browser/tor",
"//brave/browser/resources:brave_settings_resources",
"//brave/components/resources",
Expand Down
12 changes: 12 additions & 0 deletions browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include "brave/app/brave_command_ids.h"
#include "brave/browser/ui/brave_pages.h"
#include "brave/components/brave_rewards/browser/buildflags/buildflags.h"
#include "brave/components/brave_sync/brave_sync_service.h"
#include "brave/browser/ui/browser_commands.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"

Expand Down Expand Up @@ -78,6 +80,9 @@ void BraveBrowserCommandController::InitBraveCommandState() {
#endif
UpdateCommandForBraveAdblock();
UpdateCommandForTor();
if (brave_sync::BraveSyncService::is_enabled() &&
!browser_->profile()->IsOffTheRecord())
UpdateCommandForBraveSync();
}

void BraveBrowserCommandController::UpdateCommandForBraveRewards() {
Expand All @@ -93,6 +98,10 @@ void BraveBrowserCommandController::UpdateCommandForTor() {
UpdateCommandEnabled(IDC_NEW_OFFTHERECORD_WINDOW_TOR, true);
}

void BraveBrowserCommandController::UpdateCommandForBraveSync() {
UpdateCommandEnabled(IDC_SHOW_BRAVE_SYNC, true);
}

bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
int id, WindowOpenDisposition disposition) {
if (!SupportsCommand(id) || !IsCommandEnabled(id))
Expand All @@ -117,6 +126,9 @@ bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
case IDC_NEW_TOR_IDENTITY:
brave::NewTorIdentity(browser_);
break;
case IDC_SHOW_BRAVE_SYNC:
brave::ShowBraveSync(browser_);
break;

default:
LOG(WARNING) << "Received Unimplemented Command: " << id;
Expand Down
1 change: 1 addition & 0 deletions browser/ui/brave_browser_command_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class BraveBrowserCommandController : public chrome::BrowserCommandController {
void UpdateCommandForBraveRewards();
void UpdateCommandForBraveAdblock();
void UpdateCommandForTor();
void UpdateCommandForBraveSync();

bool ExecuteBraveCommandWithDisposition(int id,
WindowOpenDisposition disposition);
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/brave_pages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@ void ShowBraveAdblock(Browser* browser) {
GetSingletonTabNavigateParams(browser, GURL(kBraveUIAdblockURL)));
}

void ShowBraveSync(Browser* browser) {
ShowSingletonTabOverwritingNTP(
browser,
GetSingletonTabNavigateParams(browser, GURL(kBraveUISyncURL)));
}

} // namespace brave
1 change: 1 addition & 0 deletions browser/ui/brave_pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace brave {

void ShowBraveAdblock(Browser* browser);
void ShowBraveRewards(Browser* browser);
void ShowBraveSync(Browser* browser);

} // namespace brave

Expand Down
7 changes: 7 additions & 0 deletions browser/ui/toolbar/brave_app_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "brave/browser/ui/toolbar/brave_app_menu_model.h"

#include "brave/app/brave_command_ids.h"
#include "brave/components/brave_sync/brave_sync_service.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
Expand Down Expand Up @@ -43,4 +44,10 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
IDC_NEW_OFFTHERECORD_WINDOW_TOR,
IDS_NEW_OFFTHERECORD_WINDOW_TOR);
}
if (brave_sync::BraveSyncService::is_enabled() &&
!browser_->profile()->IsOffTheRecord())
InsertItemWithStringIdAt(
GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS),
IDC_SHOW_BRAVE_SYNC,
IDS_SHOW_BRAVE_SYNC);
}
Loading

0 comments on commit d8e7d68

Please sign in to comment.