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

feat: add getUploadProgress API to the net API #13783

Merged
merged 1 commit into from Jul 27, 2018
Merged

Conversation

MarshallOfSound
Copy link
Member

@MarshallOfSound MarshallOfSound commented Jul 24, 2018

As the title says, added a new method to the net API to get the upload progress of requests. This is required because we can't use streaming to get upload progress (unlike nodes http module) because Chromium handles the backpressure / buffering.

@MarshallOfSound MarshallOfSound requested review from a team July 24, 2018 09:18
@ckerr ckerr added the semver/minor backwards-compatible functionality label Jul 24, 2018
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM. Some suggestions inline.

Marking as "request changes" mainly to get feedback about my int32_t / uint64_t question.

}

atom_request_->GetUploadProgress(progress);
return progress;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) This control flow is a little awkward; e.g. the use of an else block after a return. Lines 135 and 138 go together.

More readable flow:

mate::Dictionary progress = ...
if (atom_request_) {
  progress.Set("active", true);
  atom_request_->GetUploadProgress(progress);
} else {
  progress.Set("active", false);
}
return progress;

@@ -43,6 +43,7 @@ class AtomURLRequest : public base::RefCountedThreadSafe<AtomURLRequest>,
void PassLoginInformation(const base::string16& username,
const base::string16& password) const;
void SetLoadFlags(int flags) const;
void GetUploadProgress(mate::Dictionary& progress);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLRequest::GetUploadProgress() is const, so I think the compiler should be happy with making this new method const


* `active` Boolean - Whether the request is currently active, if this is false
no other properties will be set
* `started` Boolean - Whether the upload has started, if this is false both
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) In the two lines above, ", if" should be ". If"

auto upload_progress = request_->GetUploadProgress();
progress.Set("current", upload_progress.position());
progress.Set("total", upload_progress.size());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since mate::Dictionary::Set() is a template method, it looks like here we're sometimes setting current/total to int and sometimes to uint64_t. At first read I think that will make the former invoke Converter::ToV8(isolate,int32_t) and the latter Converter::ToV8(uint64_t). Does that matter?

If that matters, we could consistently use net::UploadProgress' types:

net::UploadProgress upload_progress;
if (request_) {
  progress.set("started", true);
  upload_progress = request_->GetUploadProgress();
} else {
  progress.set("started", false);
}
progress.set("current", upload_progress.position());
progress.set("total", upload_progress.size());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it matters, but the consistent code looks nicer anyway 👍

@MarshallOfSound
Copy link
Member Author

@ckerr feedback addressed 👍

@YurySolovyov
Copy link
Contributor

Why not add 'progress' event to request object so that users don't have to poll progress continually?

@MarshallOfSound
Copy link
Member Author

@YurySolovyov Because there is no progress event in chromium and I'd rather not make that API / performance decision for people.

@YurySolovyov
Copy link
Contributor

There is UploadProgressTracker, not sure how suitable it is though

@MarshallOfSound
Copy link
Member Author

@YurySolovyov That helper is basically a setInterval watching the value but less customizable. I'm happy to implement that as an event in the future. But the objective of this PR is to be as safe as possible to make it easier to send back to a minor release.

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the cleanups!

@ckerr ckerr merged commit 4b3011f into master Jul 27, 2018
@ckerr ckerr deleted the net/upload-progress branch July 27, 2018 14:15
@YurySolovyov
Copy link
Contributor

@MarshallOfSound
To your comment about watching progress overhead: how about option to the ClientRequest like watchProgress: true/false, to use UploadProgressTracker or some other mechanism that would emit 'progress' events on the request, so that people will get less overhead by default, but still be able to opt-in when they do care about progress?

@MarshallOfSound
Copy link
Member Author

@YurySolovyov I'm perfectly happy to watch by default in master and emit progress event. My point was this PR should have minimal impact to make backporting causing issues as unlikely as possible.

@YurySolovyov
Copy link
Contributor

I still agree/think that progress watching should be opt-in

@ckerr
Copy link
Member

ckerr commented Aug 8, 2018

/trop run backport-to 2-1-x

@trop
Copy link
Contributor

trop bot commented Aug 8, 2018

The backport process for this PR has been manually initiated, sending your 1's and 0's to "2-1-x" here we go! :D

@trop
Copy link
Contributor

trop bot commented Aug 8, 2018

We have automatically backported this PR to "2-1-x", please check out #13985

@trop trop bot added the merged/2-1-x label Aug 8, 2018
@ckerr
Copy link
Member

ckerr commented Sep 4, 2018

/trop run backport-to 3-0-x

@trop
Copy link
Contributor

trop bot commented Sep 4, 2018

The backport process for this PR has been manually initiated,
sending your 1's and 0's to "3-0-x" here we go! :D

@trop
Copy link
Contributor

trop bot commented Sep 4, 2018

We have automatically backported this PR to "3-0-x", please check out #14446

@trop trop bot added the merged/3-0-x label Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants