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

Merge pull request #2016 from brave/sync_dont_send_bookmarks_when_no_… #2053

Closed
Closed
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
14 changes: 8 additions & 6 deletions components/brave_sync/brave_sync_prefs.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* 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/. */
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

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

Expand Down Expand Up @@ -91,7 +92,8 @@ bool Prefs::GetSyncSiteSettingsEnabled() const {
}

void Prefs::SetSyncSiteSettingsEnabled(const bool sync_site_settings_enabled) {
pref_service_->SetBoolean(kSyncSiteSettingsEnabled, sync_site_settings_enabled);
pref_service_->SetBoolean(
kSyncSiteSettingsEnabled, sync_site_settings_enabled);
}

bool Prefs::GetSyncHistoryEnabled() const {
Expand Down Expand Up @@ -170,5 +172,5 @@ void Prefs::Clear() {
pref_service_->ClearPref(kSyncApiVersion);
}

} // namespace prefs
} // namespace brave_sync
} // namespace prefs
} // namespace brave_sync
24 changes: 13 additions & 11 deletions components/brave_sync/brave_sync_prefs.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* 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_COMPONENT_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_
#define BRAVE_COMPONENT_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_
#define BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_

#include <string>
#include <memory>
Expand Down Expand Up @@ -54,8 +56,8 @@ extern const char kSyncDeviceList[];
extern const char kSyncApiVersion[];

class Prefs {
public:
Prefs(PrefService* pref_service);
public:
explicit Prefs(PrefService* pref_service);

std::string GetSeed() const;
void SetSeed(const std::string& seed);
Expand Down Expand Up @@ -92,14 +94,14 @@ class Prefs {

void Clear();

private:
private:
// May be null.
PrefService* pref_service_;

DISALLOW_COPY_AND_ASSIGN(Prefs);
};

} // namespace prefs
} // namespace brave_sync
} // namespace prefs
} // namespace brave_sync

#endif //BRAVE_COMPONENT_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_
#endif // BRAVE_COMPONENTS_BRAVE_SYNC_BRAVE_SYNC_PREFS_H_
6 changes: 5 additions & 1 deletion components/brave_sync/brave_sync_service_factory.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* Copyright 2019 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 http://mozilla.org/MPL/2.0/. */

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

#include <memory>
#include <string>

#include "base/memory/singleton.h"
#include "brave/components/brave_sync/brave_sync_prefs.h"
#include "brave/components/brave_sync/brave_sync_service.h"
Expand Down
13 changes: 12 additions & 1 deletion components/brave_sync/brave_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,23 @@ void BraveSyncServiceImpl::RequestSyncData() {

if (tools::IsTimeEmpty(last_fetch_time)) {
SendCreateDevice();
}

sync_client_->SendFetchSyncDevices();

if (sync_prefs_->GetSyncDevices()->size() <= 1) {
// No sense to fetch or sync bookmarks when there no at least two devices
// in chain
// Set last fetch time here because we had fetched devices at least
sync_prefs_->SetLastFetchTime(base::Time::Now());
return;
}

if (tools::IsTimeEmpty(last_fetch_time)) {
bookmark_change_processor_->InitialSync();
}

FetchSyncRecords(bookmarks, history, preferences, 1000);
sync_client_->SendFetchSyncDevices();
}

void BraveSyncServiceImpl::FetchSyncRecords(const bool bookmarks,
Expand Down
26 changes: 24 additions & 2 deletions components/brave_sync/brave_sync_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,34 @@ TEST_F(BraveSyncServiceTest, OnSyncReadyAlreadyWithSync) {
EXPECT_FALSE(sync_service()->IsSyncInitialized());
profile()->GetPrefs()->SetString(
brave_sync::prefs::kSyncBookmarksBaseOrder, "1.1.");
// OnSyncPrefsChanged => OnSyncStateChanged for kSyncSiteSettingsEnabled
EXPECT_CALL(*observer(), OnSyncStateChanged);
// OnSyncPrefsChanged => OnSyncStateChanged for
// kSyncSiteSettingsEnabled (1) and kSyncDeviceList (2)
EXPECT_CALL(*observer(), OnSyncStateChanged).Times(2);
profile()->GetPrefs()->SetBoolean(
brave_sync::prefs::kSyncSiteSettingsEnabled, true);
profile()->GetPrefs()->SetTime(
brave_sync::prefs::kSyncLastFetchTime, base::Time::Now());
const char* devices_json = R"(
{
"devices":[
{
"device_id":"0",
"last_active":1552993896717.0,
"name":"Device1",
"object_id":"186, 247, 230, 75, 57, 111, 76, 166, 51, 142, 217, 221, 219, 237, 229, 235"
},
{
"device_id":"1",
"last_active":1552993909257.0,
"name":"Device2",
"object_id":"36, 138, 200, 221, 191, 81, 214, 65, 134, 48, 55, 119, 162, 93, 33, 226"
}
]
}
)";

profile()->GetPrefs()->SetString(
brave_sync::prefs::kSyncDeviceList, devices_json);
EXPECT_CALL(*sync_client(), SendFetchSyncRecords).Times(1);
EXPECT_CALL(*sync_client(), SendFetchSyncDevices).Times(1);
sync_service()->OnSyncReady();
Expand Down