- if (iter == state_map_.end()) {
- const GURL url = GetURLForAttachmentId(sync_service_url_, attachment_id);
- scoped_ptr<UploadState> upload_state(
- new UploadState(url,
- url_request_context_getter_,
- attachment,
- callback,
- account_id_,
- scopes_,
- token_service_provider_.get(),
- this));
- state_map_.add(unique_id, upload_state.Pass());
- } else {
- DCHECK(
- attachment.GetData()->Equals(iter->second->GetAttachment().GetData()));
- // We already have an upload for this attachment. "Join" it.
- iter->second->AddUserCallback(callback);
+ if (iter != state_map_.end()) {
+ // We have an old upload request for this attachment...
+ if (!iter->second->IsStopped()) {
+ // "join" to it.
+ DCHECK(attachment.GetData()
+ ->Equals(iter->second->GetAttachment().GetData()));
+ iter->second->AddUserCallback(callback);
+ return;
+ } else {
+ // It's stopped so we can't use it. Delete it.
+ state_map_.erase(iter);
+ }