Skip to content

Commit

Permalink
Merge pull request #951 from brave/show_sync_setup_error
Browse files Browse the repository at this point in the history
Show sync setup error
  • Loading branch information
AlexeyBarabash committed Nov 27, 2018
1 parent a03cc5f commit f3a9146
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
10 changes: 10 additions & 0 deletions browser/ui/webui/sync/sync_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class SyncUIDOMHandler : public WebUIMessageHandler,
void DeleteDevice(const base::ListValue* args);
void ResetSync(const base::ListValue* args);

void OnSyncSetupError(brave_sync::BraveSyncService* sync_service,
const std::string& error) override;
void OnSyncStateChanged(brave_sync::BraveSyncService *sync_service) override;
void OnHaveSyncWords(brave_sync::BraveSyncService *sync_service,
const std::string& sync_words) override;
Expand Down Expand Up @@ -193,6 +195,14 @@ void SyncUIDOMHandler::ResetSync(const base::ListValue* args) {
sync_service_->OnResetSync();
}

void SyncUIDOMHandler::OnSyncSetupError(
brave_sync::BraveSyncService* sync_service,
const std::string& error) {

web_ui()->CallJavascriptFunctionUnsafe(
"sync_ui_exports.syncSetupError", base::Value(error));
}

void SyncUIDOMHandler::OnSyncStateChanged(
brave_sync::BraveSyncService *sync_service) {
LoadSyncSettingsView();
Expand Down
11 changes: 10 additions & 1 deletion components/brave_sync/brave_sync_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ void BraveSyncServiceImpl::OnSetupSyncNewToSync(
return;
}

sync_words_.clear(); // If the previous attempt was connect to sync chain
// and failed to receive save-init-data

sync_prefs_->SetThisDeviceName(device_name);
initializing_ = true;

Expand Down Expand Up @@ -288,7 +291,7 @@ void BraveSyncServiceImpl::OnSyncSetupError(const std::string& error) {
if (!sync_initialized_) {
sync_prefs_->Clear();
}
OnSyncDebug(error);
NotifySyncSetupError(error);
}

void BraveSyncServiceImpl::OnGetInitData(const std::string& sync_version) {
Expand Down Expand Up @@ -609,6 +612,12 @@ void BraveSyncServiceImpl::NotifyLogMessage(const std::string& message) {
DLOG(INFO) << message;
}

void BraveSyncServiceImpl::NotifySyncSetupError(const std::string& error) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
for (auto& observer : observers_)
observer.OnSyncSetupError(this, error);
}

void BraveSyncServiceImpl::NotifySyncStateChanged() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
for (auto& observer : observers_)
Expand Down
1 change: 1 addition & 0 deletions components/brave_sync/brave_sync_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class BraveSyncServiceImpl : public BraveSyncService,
const bool is_truncated );

void NotifyLogMessage(const std::string& message);
void NotifySyncSetupError(const std::string& error);
void NotifySyncStateChanged();
void NotifyHaveSyncWords(const std::string& sync_words);

Expand Down
2 changes: 2 additions & 0 deletions components/brave_sync/brave_sync_service_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class BraveSyncServiceObserver : public base::CheckedObserver {
public:
~BraveSyncServiceObserver() override {}

virtual void OnSyncSetupError(BraveSyncService* sync_service,
const std::string& error) {}
virtual void OnSyncStateChanged(BraveSyncService* sync_service) {}
virtual void OnHaveSyncWords(BraveSyncService* sync_service,
const std::string& sync_words) {}
Expand Down
6 changes: 6 additions & 0 deletions components/brave_sync/brave_sync_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class MockBraveSyncServiceObserver : public BraveSyncServiceObserver {
public:
MockBraveSyncServiceObserver() {}

MOCK_METHOD2(OnSyncSetupError, void(BraveSyncService*, const std::string&));
MOCK_METHOD1(OnSyncStateChanged, void(BraveSyncService*));
MOCK_METHOD2(OnHaveSyncWords, void(BraveSyncService*, const std::string&));
};
Expand Down Expand Up @@ -296,6 +297,11 @@ TEST_F(BraveSyncServiceTest, GetSyncWords) {
sync_service()->OnSyncWordsPrepared(words);
}

TEST_F(BraveSyncServiceTest, SyncSetupError) {
EXPECT_CALL(*observer(), OnSyncSetupError(sync_service(), _)).Times(1);
sync_service()->OnSetupSyncHaveCode("", "");
}

TEST_F(BraveSyncServiceTest, GetSeed) {
EXPECT_CALL(*sync_client(), OnSyncEnabledChanged);
EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(AtLeast(2));
Expand Down
2 changes: 1 addition & 1 deletion components/brave_sync/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class InjectedObject {
chrome.braveSync.saveInitData(arg1/*seed*/, deviceId);
break;
case "sync-ready":
console.log(`"save-init-data"`);
console.log(`"sync-ready"`);
chrome.braveSync.syncReady();
break;
case "get-existing-objects":
Expand Down
7 changes: 6 additions & 1 deletion components/brave_sync/ui/brave_sync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ window.cr.define('sync_ui_exports', function () {
getActions().onLogMessage(message)
}

function syncSetupError(error: string) {
alert('Sync setup error: ' + error)
}

return {
initialize,
showSettings,
haveSyncWords,
haveSeedForQrCode,
logMessage
logMessage,
syncSetupError
}
})

Expand Down

0 comments on commit f3a9146

Please sign in to comment.