Skip to content

Commit

Permalink
[Android][Sync] Move the logic for changing the sync url for staging …
Browse files Browse the repository at this point in the history
…in Android to |BraveGetSyncServiceURL|.
  • Loading branch information
jagadeshjai committed Sep 28, 2024
1 parent 5d72880 commit 22a48d8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 38 deletions.
38 changes: 0 additions & 38 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
#include "base/linux_util.h"
#endif

#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_android.h"
#include "brave/build/android/jni_headers/BraveQAPreferences_jni.h"
#include "components/signin/public/base/account_consistency_method.h"
#endif
namespace {

const char kBraveOriginTrialsPublicKey[] =
Expand All @@ -65,34 +60,6 @@ std::string GetUpdateURLHost() {
return BUILDFLAG(UPDATER_DEV_ENDPOINT);
}

#if BUILDFLAG(IS_ANDROID)
// staging "https://sync-v2.bravesoftware.com/v2" can be overriden by
// syncer::kSyncServiceURL manually
const char kBraveSyncServiceStagingURL[] =
"https://sync-v2.bravesoftware.com/v2";

void AdjustSyncServiceUrlForAndroid(std::string* brave_sync_service_url) {
DCHECK_NE(brave_sync_service_url, nullptr);
const char kProcessTypeSwitchName[] = "type";

// On Android we can detect data dir only on host process, and we cannot
// for example on renderer or gpu-process, because JNI is not initialized
// And no sense to override sync service url for them in anyway
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kProcessTypeSwitchName)) {
// This is something other than browser process
return;
}

JNIEnv* env = base::android::AttachCurrentThread();
bool b_use_staging_sync_server =
Java_BraveQAPreferences_isSyncStagingUsed(env);
if (b_use_staging_sync_server) {
*brave_sync_service_url = kBraveSyncServiceStagingURL;
}
}
#endif // BUILDFLAG(IS_ANDROID)

} // namespace

#if !defined(CHROME_MULTIPLE_DLL_BROWSER)
Expand Down Expand Up @@ -157,11 +124,6 @@ void BraveMainDelegate::AppendCommandLineOptions() {
kBraveOriginTrialsPublicKey);
}

std::string brave_sync_service_url = BUILDFLAG(BRAVE_SYNC_ENDPOINT);
#if BUILDFLAG(IS_ANDROID)
AdjustSyncServiceUrlForAndroid(&brave_sync_service_url);
#endif // BUILDFLAG(IS_ANDROID)

command_line->AppendSwitchASCII(switches::kLsoUrl, kDummyUrl);
variations::AppendBraveCommandLineOptions(*command_line);
}
Expand Down
1 change: 1 addition & 0 deletions chromium_src/components/sync/service/DEPS
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include_rules = [
"+brave/components/brave_sync",
"+brave/components/sync/service",
"+brave/build/android/jni_headers/BraveQAPreferences_jni.h",
]
19 changes: 19 additions & 0 deletions chromium_src/components/sync/service/sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
#include "components/sync/base/command_line_switches.h"
#include "components/sync/base/sync_util.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/jni_android.h"
#include "brave/build/android/jni_headers/BraveQAPreferences_jni.h"
#endif

namespace syncer {

GURL BraveGetSyncServiceURL(const base::CommandLine& command_line,
version_info::Channel channel,
PrefService* prefs) {
// TODO: Currently, we only handle the custom sync URL via GPO/Settings Page
// on Desktop OSes. However, we should also handle it on Android in the future.
#if !BUILDFLAG(IS_ANDROID)
if (prefs) {
std::string value = prefs->GetString(brave_sync::kCustomSyncServiceUrl);
if (!value.empty()) {
Expand Down Expand Up @@ -45,6 +53,17 @@ GURL BraveGetSyncServiceURL(const base::CommandLine& command_line,
}
}
}
#else
const char kBraveSyncServiceStagingURL[] =
"https://sync-v2.bravesoftware.com/v2";

JNIEnv* env = base::android::AttachCurrentThread();
bool b_use_staging_sync_server =
Java_BraveQAPreferences_isSyncStagingUsed(env);
if (b_use_staging_sync_server) {
return GURL(kBraveSyncServiceStagingURL);
}
#endif

// Default logic.
// See `GetSyncServiceURL` in `components/sync/base/sync_util.cc`
Expand Down
5 changes: 5 additions & 0 deletions components/sync/service/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ brave_components_sync_driver_sources = [
"//brave/components/sync/service/brave_sync_stopped_reporter.h",
"//brave/components/sync/service/sync_service_impl_delegate.h",
]

brave_components_sync_driver_deps = [
"//brave/components/brave_sync",
"//brave/components/brave_sync:crypto",
"//brave/components/brave_sync:network_time_helper",
"//brave/components/brave_sync:prefs",
"//brave/components/constants",
]

if (is_android) {
brave_components_sync_driver_deps += [ "//brave/build/android:jni_headers" ]
}

0 comments on commit 22a48d8

Please sign in to comment.