Added device name for cloud restoring

This commit is contained in:
r.kuznetsov 2018-05-29 15:16:29 +03:00 committed by yoksnod
parent 2374f66c9b
commit 439e9dc133
8 changed files with 28 additions and 18 deletions

View file

@ -59,7 +59,7 @@ void PrepareClassRefs(JNIEnv * env)
jni::GetMethodID(env, bookmarkManagerInstance,
"onSynchronizationFinished", "(IILjava/lang/String;)V");
g_onRestoreRequestedMethod =
jni::GetMethodID(env, bookmarkManagerInstance, "onRestoreRequested", "(IJ)V");
jni::GetMethodID(env, bookmarkManagerInstance, "onRestoreRequested", "(ILjava/lang/String;J)V");
g_onRestoredFilesPreparedMethod =
jni::GetMethodID(env, bookmarkManagerInstance, "onRestoredFilesPrepared", "()V");
g_onImportStartedMethod =
@ -166,13 +166,14 @@ void OnSynchronizationFinished(JNIEnv * env, Cloud::SynchronizationType type,
}
void OnRestoreRequested(JNIEnv * env, Cloud::RestoringRequestResult result,
uint64_t backupTimestampInMs)
std::string const & deviceName, uint64_t backupTimestampInMs)
{
ASSERT(g_bookmarkManagerClass, ());
jobject bookmarkManagerInstance = env->GetStaticObjectField(g_bookmarkManagerClass,
g_bookmarkManagerInstanceField);
env->CallVoidMethod(bookmarkManagerInstance, g_onRestoreRequestedMethod,
static_cast<jint>(result), static_cast<jlong>(backupTimestampInMs));
static_cast<jint>(result), jni::ToJavaString(env, deviceName),
static_cast<jlong>(backupTimestampInMs));
jni::HandleJavaException(env);
}
@ -231,7 +232,7 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeLoadBookmarks(JNIE
frm()->GetBookmarkManager().SetCloudHandlers(
std::bind(&OnSynchronizationStarted, env, _1),
std::bind(&OnSynchronizationFinished, env, _1, _2, _3),
std::bind(&OnRestoreRequested, env, _1, _2),
std::bind(&OnRestoreRequested, env, _1, _2, _3),
std::bind(&OnRestoredFilesPrepared, env));
frm()->GetBookmarkManager().SetCatalogHandlers(nullptr, nullptr,

View file

@ -314,10 +314,11 @@ public class BookmarkBackupController implements Authorizer.Callback,
@Override
public void onRestoreRequested(@BookmarkManager.RestoringRequestResult int result,
long backupTimestampInMs)
@NonNull String deviceName, long backupTimestampInMs)
{
LOGGER.d(TAG, "onRestoreRequested, result: " + result + ", backupTimestampInMs = "
+ backupTimestampInMs);
//TODO (@alexzatsepin): Output deviceName to the dialog.
LOGGER.d(TAG, "onRestoreRequested, result: " + result + ", deviceName = " + deviceName +
", backupTimestampInMs = " + backupTimestampInMs);
Statistics.INSTANCE.trackBmRestoringRequestResult(result);
hideRestoringProgressDialog();

View file

@ -218,11 +218,11 @@ public enum BookmarkManager
// Called from JNI.
@MainThread
public void onRestoreRequested(@RestoringRequestResult int result,
public void onRestoreRequested(@RestoringRequestResult int result, @NonNull String deviceName,
long backupTimestampInMs)
{
for (BookmarksCloudListener listener : mCloudListeners)
listener.onRestoreRequested(result, backupTimestampInMs);
listener.onRestoreRequested(result, deviceName, backupTimestampInMs);
}
// Called from JNI.
@ -626,9 +626,11 @@ public enum BookmarkManager
* The method is called after restoring request.
*
* @param result By result you can determine if the restoring is possible.
* @param deviceName The name of device which was the source of the backup.
* @param backupTimestampInMs contains timestamp of the backup on the server (in milliseconds).
*/
void onRestoreRequested(@RestoringRequestResult int result, long backupTimestampInMs);
void onRestoreRequested(@RestoringRequestResult int result, @NonNull String deviceName,
long backupTimestampInMs);
/**
* Restored bookmark files are prepared to substitute for the current ones.

View file

@ -167,8 +167,10 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
}];
};
auto onRestoreRequested = [](Cloud::RestoringRequestResult result, uint64_t backupTimestampInMs)
auto onRestoreRequested = [](Cloud::RestoringRequestResult result, std::string const & deviceName,
uint64_t backupTimestampInMs)
{
//TODO (@beloal): Output device name to the dialog.
auto const res = static_cast<MWMRestoringRequestResult>(my::Key(result));
NSDate * date = nil;

View file

@ -478,7 +478,7 @@ BookmarkManager::BookmarkManager(Callbacks && callbacks)
m_bookmarkCloud.SetSynchronizationHandlers(
std::bind(&BookmarkManager::OnSynchronizationStarted, this, _1),
std::bind(&BookmarkManager::OnSynchronizationFinished, this, _1, _2, _3),
std::bind(&BookmarkManager::OnRestoreRequested, this, _1, _2),
std::bind(&BookmarkManager::OnRestoreRequested, this, _1, _2, _3),
std::bind(&BookmarkManager::OnRestoredFilesPrepared, this));
}
@ -1941,16 +1941,17 @@ void BookmarkManager::OnSynchronizationFinished(Cloud::SynchronizationType type,
}
void BookmarkManager::OnRestoreRequested(Cloud::RestoringRequestResult result,
std::string const & deviceName,
uint64_t backupTimestampInMs)
{
GetPlatform().RunTask(Platform::Thread::Gui, [this, result, backupTimestampInMs]()
GetPlatform().RunTask(Platform::Thread::Gui, [this, result, deviceName, backupTimestampInMs]()
{
if (m_onRestoreRequested)
m_onRestoreRequested(result, backupTimestampInMs);
m_onRestoreRequested(result, deviceName, backupTimestampInMs);
});
using namespace std::chrono;
LOG(LINFO, ("Cloud Restore Requested:", result,
LOG(LINFO, ("Cloud Restore Requested:", result, deviceName,
time_point<system_clock>(milliseconds(backupTimestampInMs))));
}

View file

@ -466,7 +466,8 @@ private:
void OnSynchronizationStarted(Cloud::SynchronizationType type);
void OnSynchronizationFinished(Cloud::SynchronizationType type, Cloud::SynchronizationResult result,
std::string const & errorStr);
void OnRestoreRequested(Cloud::RestoringRequestResult result, uint64_t backupTimestampInMs);
void OnRestoreRequested(Cloud::RestoringRequestResult result, std::string const & deviceName,
uint64_t backupTimestampInMs);
void OnRestoredFilesPrepared();
bool CanConvert() const;

View file

@ -1240,7 +1240,7 @@ void Cloud::ProcessSuccessfulSnapshot(SnapshotResult const & result)
if (result.m_response.m_files.empty())
{
ThreadSafeCallback<RestoreRequestedHandler>([this]() { return m_onRestoreRequested; },
RestoringRequestResult::NoBackup,
RestoringRequestResult::NoBackup, "",
result.m_response.m_datetime);
FinishRestoring(SynchronizationResult::Success, {});
return;
@ -1252,7 +1252,7 @@ void Cloud::ProcessSuccessfulSnapshot(SnapshotResult const & result)
if (totalSize * kSizeScalar >= GetPlatform().GetWritableStorageSpace())
{
ThreadSafeCallback<RestoreRequestedHandler>([this]() { return m_onRestoreRequested; },
RestoringRequestResult::NotEnoughDiskSpace,
RestoringRequestResult::NotEnoughDiskSpace, "",
result.m_response.m_datetime);
FinishRestoring(SynchronizationResult::DiskError, {});
return;
@ -1269,6 +1269,7 @@ void Cloud::ProcessSuccessfulSnapshot(SnapshotResult const & result)
{
ThreadSafeCallback<RestoreRequestedHandler>([this]() { return m_onRestoreRequested; },
RestoringRequestResult::BackupExists,
result.m_response.m_deviceName,
result.m_response.m_datetime);
}
}

View file

@ -210,6 +210,7 @@ public:
SynchronizationResult,
std::string const & error)>;
using RestoreRequestedHandler = std::function<void(RestoringRequestResult,
std::string const & deviceName,
uint64_t backupTimestampInMs)>;
using RestoredFilesPreparedHandler = std::function<void()>;