Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: google_apis/drive/request_sender.cc

Issue 1218773003: Implement a DRIVE_REQUEST_TOO_LARGE backoff. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/drive/request_sender.h" 5 #include "google_apis/drive/request_sender.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/sequenced_task_runner.h" 8 #include "base/sequenced_task_runner.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "google_apis/drive/auth_service.h" 10 #include "google_apis/drive/auth_service.h"
(...skipping 13 matching lines...) Expand all
24 custom_user_agent_(custom_user_agent), 24 custom_user_agent_(custom_user_agent),
25 weak_ptr_factory_(this) { 25 weak_ptr_factory_(this) {
26 } 26 }
27 27
28 RequestSender::~RequestSender() { 28 RequestSender::~RequestSender() {
29 DCHECK(thread_checker_.CalledOnValidThread()); 29 DCHECK(thread_checker_.CalledOnValidThread());
30 STLDeleteContainerPointers(in_flight_requests_.begin(), 30 STLDeleteContainerPointers(in_flight_requests_.begin(),
31 in_flight_requests_.end()); 31 in_flight_requests_.end());
32 } 32 }
33 33
34 base::Closure RequestSender::StartRequestWithRetry( 34 base::Closure RequestSender::StartRequestWithAuthRetry(
35 AuthenticatedRequestInterface* request) { 35 AuthenticatedRequestInterface* request) {
36 DCHECK(thread_checker_.CalledOnValidThread()); 36 DCHECK(thread_checker_.CalledOnValidThread());
37 37
38 in_flight_requests_.insert(request); 38 in_flight_requests_.insert(request);
39 39
40 // TODO(kinaba): Stop relying on weak pointers. Move lifetime management 40 // TODO(kinaba): Stop relying on weak pointers. Move lifetime management
41 // of the requests to request sender. 41 // of the requests to request sender.
42 base::Closure cancel_closure = 42 base::Closure cancel_closure =
43 base::Bind(&RequestSender::CancelRequest, 43 base::Bind(&RequestSender::CancelRequest,
44 weak_ptr_factory_.GetWeakPtr(), 44 weak_ptr_factory_.GetWeakPtr(),
(...skipping 20 matching lines...) Expand all
65 DriveApiErrorCode code, 65 DriveApiErrorCode code,
66 const std::string& /* access_token */) { 66 const std::string& /* access_token */) {
67 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
68 68
69 // Do nothing if the request is canceled during authentication. 69 // Do nothing if the request is canceled during authentication.
70 if (!request.get()) 70 if (!request.get())
71 return; 71 return;
72 72
73 if (code == HTTP_SUCCESS) { 73 if (code == HTTP_SUCCESS) {
74 DCHECK(auth_service_->HasAccessToken()); 74 DCHECK(auth_service_->HasAccessToken());
75 StartRequestWithRetry(request.get()); 75 StartRequestWithAuthRetry(request.get());
76 } else { 76 } else {
77 request->OnAuthFailed(code); 77 request->OnAuthFailed(code);
78 } 78 }
79 } 79 }
80 80
81 void RequestSender::RetryRequest(AuthenticatedRequestInterface* request) { 81 void RequestSender::RetryRequest(AuthenticatedRequestInterface* request) {
82 DCHECK(thread_checker_.CalledOnValidThread()); 82 DCHECK(thread_checker_.CalledOnValidThread());
83 83
84 auth_service_->ClearAccessToken(); 84 auth_service_->ClearAccessToken();
85 // User authentication might have expired - rerun the request to force 85 // User authentication might have expired - rerun the request to force
86 // auth token refresh. 86 // auth token refresh.
87 StartRequestWithRetry(request); 87 StartRequestWithAuthRetry(request);
88 } 88 }
89 89
90 void RequestSender::CancelRequest( 90 void RequestSender::CancelRequest(
91 const base::WeakPtr<AuthenticatedRequestInterface>& request) { 91 const base::WeakPtr<AuthenticatedRequestInterface>& request) {
92 DCHECK(thread_checker_.CalledOnValidThread()); 92 DCHECK(thread_checker_.CalledOnValidThread());
93 93
94 // Do nothing if the request is already finished. 94 // Do nothing if the request is already finished.
95 if (!request.get()) 95 if (!request.get())
96 return; 96 return;
97 request->Cancel(); 97 request->Cancel();
98 } 98 }
99 99
100 void RequestSender::RequestFinished(AuthenticatedRequestInterface* request) { 100 void RequestSender::RequestFinished(AuthenticatedRequestInterface* request) {
101 in_flight_requests_.erase(request); 101 in_flight_requests_.erase(request);
102 delete request; 102 delete request;
103 } 103 }
104 104
105 } // namespace google_apis 105 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698