зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1200310 - No need to wifi+cell scan if stumble file is full, just trigger upload. r=jdm
This commit is contained in:
Родитель
4c80c2ee2f
Коммит
5368b8a344
|
@ -77,6 +77,16 @@ private:
|
|||
void
|
||||
MozStumble(nsGeoPosition* position)
|
||||
{
|
||||
if (WriteStumbleOnThread::IsFileWaitingForUpload()) {
|
||||
nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
||||
MOZ_ASSERT(target);
|
||||
// Knowing that file is waiting to upload, and no collection will take place,
|
||||
// just trigger the thread with an empty string.
|
||||
nsCOMPtr<nsIRunnable> event = new WriteStumbleOnThread(EmptyCString());
|
||||
target->Dispatch(event, NS_DISPATCH_NORMAL);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMGeoPositionCoords> coords;
|
||||
position->GetCoords(getter_AddRefs(coords));
|
||||
if (!coords) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define ONEDAY_IN_MSEC (24 * 60 * 60 * 1000)
|
||||
#define MAX_UPLOAD_ATTEMPTS 20
|
||||
|
||||
mozilla::Atomic<bool> WriteStumbleOnThread::sIsFileWaitingForUpload(false);
|
||||
mozilla::Atomic<bool> WriteStumbleOnThread::sIsAlreadyRunning(false);
|
||||
WriteStumbleOnThread::UploadFreqGuard WriteStumbleOnThread::sUploadFreqGuard = {0};
|
||||
|
||||
|
@ -42,6 +43,7 @@ class DeleteRunnable : public nsRunnable
|
|||
}
|
||||
// critically, this sets this flag to false so writing can happen again
|
||||
WriteStumbleOnThread::sIsAlreadyRunning = false;
|
||||
WriteStumbleOnThread::sIsFileWaitingForUpload = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -49,6 +51,12 @@ class DeleteRunnable : public nsRunnable
|
|||
~DeleteRunnable() {}
|
||||
};
|
||||
|
||||
bool
|
||||
WriteStumbleOnThread::IsFileWaitingForUpload()
|
||||
{
|
||||
return sIsFileWaitingForUpload;
|
||||
}
|
||||
|
||||
void
|
||||
WriteStumbleOnThread::UploadEnded(bool deleteUploadFile)
|
||||
{
|
||||
|
@ -194,6 +202,7 @@ WriteStumbleOnThread::Run()
|
|||
|
||||
if (UploadFileStatus::NoFile != status) {
|
||||
if (UploadFileStatus::ExistsAndReadyToUpload == status) {
|
||||
sIsFileWaitingForUpload = true;
|
||||
Upload();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -206,6 +215,7 @@ WriteStumbleOnThread::Run()
|
|||
}
|
||||
}
|
||||
|
||||
sIsFileWaitingForUpload = false;
|
||||
sIsAlreadyRunning = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,10 @@ public:
|
|||
|
||||
static void UploadEnded(bool deleteUploadFile);
|
||||
|
||||
// Used externally to determine if cell+wifi scans should happen
|
||||
// (returns false for that case).
|
||||
static bool IsFileWaitingForUpload();
|
||||
|
||||
private:
|
||||
friend class DeleteRunnable;
|
||||
|
||||
|
@ -72,6 +76,8 @@ private:
|
|||
// Only run one instance of this
|
||||
static mozilla::Atomic<bool> sIsAlreadyRunning;
|
||||
|
||||
static mozilla::Atomic<bool> sIsFileWaitingForUpload;
|
||||
|
||||
// Limit the upload attempts per day. If the device is rebooted
|
||||
// this resets the allowed attempts, which is acceptable.
|
||||
struct UploadFreqGuard {
|
||||
|
|
Загрузка…
Ссылка в новой задаче