Skip to content

Commit

Permalink
[Sync] Set the |BRAVE_SYNC_ENDPOINT| directly in kSyncServerUrl/kSync…
Browse files Browse the repository at this point in the history
…DevServerUrl using chromium_src overrides instead of passing it via command_line
  • Loading branch information
jagadeshjai committed Sep 21, 2024
1 parent 5e18302 commit 2c9a8ce
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 66 deletions.
7 changes: 0 additions & 7 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,6 @@ void BraveMainDelegate::AppendCommandLineOptions() {
#endif // BUILDFLAG(IS_ANDROID)

command_line->AppendSwitchASCII(switches::kLsoUrl, kDummyUrl);

// Brave's sync protocol does not use the sync service url
if (!command_line->HasSwitch(syncer::kSyncServiceURL)) {
command_line->AppendSwitchASCII(syncer::kSyncServiceURL,
brave_sync_service_url.c_str());
}

variations::AppendBraveCommandLineOptions(*command_line);
}

Expand Down
48 changes: 0 additions & 48 deletions chromium_src/chrome/browser/sync/sync_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,11 @@

#include "chrome/browser/sync/sync_service_factory.h"

#include "base/command_line.h"
#include "brave/browser/sync/brave_sync_service_impl_delegate.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
#include "brave/components/sync/service/brave_sync_service_impl.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "components/sync/base/command_line_switches.h"

// Below includes are just to prevent redefining of
// |BuildServiceInstanceForBrowserContext|.
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/commerce/product_specifications/product_specifications_service_factory.h"
#include "chrome/browser/consent_auditor/consent_auditor_factory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/metrics/variations/google_groups_manager_factory.h"
#include "chrome/browser/password_manager/password_receiver_service_factory.h"
#include "chrome/browser/password_manager/password_sender_service_factory.h"
#include "chrome/browser/plus_addresses/plus_address_setting_service_factory.h"
#include "chrome/browser/power_bookmarks/power_bookmark_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/security_events/security_event_recorder_factory.h"
#include "chrome/browser/sharing/sharing_message_bridge_factory.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_service_factory.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "chrome/browser/webauthn/passkey_model_factory.h"
#include "chrome/browser/webdata_services/web_data_service_factory.h"

#define BRAVE_BUILD_SERVICE_INSTANCE_FOR \
std::make_unique<syncer::BraveSyncServiceImpl>( \
Expand All @@ -41,32 +19,6 @@
HistoryServiceFactory::GetForProfile( \
profile, ServiceAccessType::IMPLICIT_ACCESS)));

#define BuildServiceInstanceForBrowserContext \
BuildServiceInstanceForBrowserContext_ChromiumImpl

#include "src/chrome/browser/sync/sync_service_factory.cc"

#undef BuildServiceInstanceForBrowserContext
#undef BRAVE_BUILD_SERVICE_INSTANCE_FOR

std::unique_ptr<KeyedService>
SyncServiceFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
auto* command_line = base::CommandLine::ForCurrentProcess();
Profile* profile = Profile::FromBrowserContext(context);

// Pass the custom sync service URL to the sync service if it's not managed.
if (!profile->GetPrefs()->IsManagedPreference(
brave_sync::kCustomSyncServiceUrl)) {
if (!command_line->HasSwitch(syncer::kSyncServiceURL) ||
command_line->GetSwitchValueASCII(syncer::kSyncServiceURL).empty()) {
command_line->AppendSwitchASCII(
syncer::kSyncServiceURL,
profile->GetPrefs()
->GetString(brave_sync::kCustomSyncServiceUrl)
.c_str());
}
}

return BuildServiceInstanceForBrowserContext_ChromiumImpl(context);
}
3 changes: 3 additions & 0 deletions chromium_src/components/sync/base/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+brave/components/brave_sync",
]
24 changes: 24 additions & 0 deletions chromium_src/components/sync/base/sync_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2024 The Brave Authors. All rights reserved.
* 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 https://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_SYNC_UTIL_H_
#define BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_SYNC_UTIL_H_

#include "brave/components/brave_sync/buildflags.h"

namespace syncer::internal {
inline constexpr char kSyncServerUrl[] = BUILDFLAG(BRAVE_SYNC_ENDPOINT);
inline constexpr char kSyncDevServerUrl[] = BUILDFLAG(BRAVE_SYNC_ENDPOINT);
} // namespace syncer::internal

#define kSyncServerUrl kSyncServerUrl_ChromiumImpl
#define kSyncDevServerUrl kSyncDevServerUrl_ChromiumImpl

#include "src/components/sync/base/sync_util.h" // IWYU pragma: export

#undef kSyncDevServerUrl
#undef kSyncServerUrl

#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_SYNC_BASE_SYNC_UTIL_H_
34 changes: 23 additions & 11 deletions chromium_src/components/sync/service/sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,51 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "base/command_line.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
#include "brave/components/sync/service/brave_sync_auth_manager.h"
#include "brave/components/sync/service/brave_sync_stopped_reporter.h"
#include "components/prefs/pref_service.h"
#include "components/sync/base/command_line_switches.h"
#include "components/sync/base/sync_util.h"

namespace syncer {

GURL BraveGetSyncServiceURL(const base::CommandLine& command_line,
version_info::Channel channel,
PrefService* prefs) {
// Allow group policy to override sync service URL.
// This has a higher priority than the --sync-url command-line param.
// https://github.com/brave/brave-browser/issues/20431
if (prefs && prefs->IsManagedPreference(brave_sync::kCustomSyncServiceUrl)) {
std::string value(prefs->GetString(brave_sync::kCustomSyncServiceUrl));
if (prefs) {
std::string value = prefs->GetString(brave_sync::kCustomSyncServiceUrl);
if (!value.empty()) {
GURL custom_sync_url(value);
// Provided URL must be HTTPS.
if (custom_sync_url.is_valid() &&
custom_sync_url.SchemeIs(url::kHttpsScheme)) {
DVLOG(2) << "Sync URL specified via GPO: "
<< prefs->GetString(brave_sync::kCustomSyncServiceUrl);
return custom_sync_url;
// Allow group policy to override sync service URL.
// This has a higher priority than the --sync-url command-line param.
// https://github.com/brave/brave-browser/issues/20431
if (prefs->IsManagedPreference(brave_sync::kCustomSyncServiceUrl)) {
DVLOG(2) << "Sync URL specified via GPO: " << value;
return custom_sync_url;
} else {
// If the sync URL is not set via command line.
if (!command_line.HasSwitch(syncer::kSyncServiceURL) ||
command_line.GetSwitchValueASCII(syncer::kSyncServiceURL)
.empty()) {
DVLOG(2) << "Sync URL specified via settings: " << value;
return custom_sync_url;
}
}
} else {
LOG(WARNING) << "The following sync URL specified via GPO "
<< "is invalid: " << value;
LOG(WARNING) << "The following sync URL specified via GPO or settings "
"page is invalid: "
<< value;
}
}
}

// Default logic.
// See `GetSyncServiceURL` in `components/sync/base/sync_util.cc`
// See `GetSyncServiceURL` in components/sync/base/sync_util.cc
return GetSyncServiceURL(command_line, channel);
}

Expand Down

0 comments on commit 2c9a8ce

Please sign in to comment.