| OLD | NEW |
| 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 #ifndef GOOGLE_APIS_DRIVE_REQUEST_SENDER_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_REQUEST_SENDER_H_ |
| 6 #define GOOGLE_APIS_DRIVE_REQUEST_SENDER_H_ | 6 #define GOOGLE_APIS_DRIVE_REQUEST_SENDER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Starts a request implementing the AuthenticatedRequestInterface | 64 // Starts a request implementing the AuthenticatedRequestInterface |
| 65 // interface, and makes the request retry upon authentication failures by | 65 // interface, and makes the request retry upon authentication failures by |
| 66 // calling back to RetryRequest. The |request| object is owned by this | 66 // calling back to RetryRequest. The |request| object is owned by this |
| 67 // RequestSender. It will be deleted in RequestSender's destructor or | 67 // RequestSender. It will be deleted in RequestSender's destructor or |
| 68 // in RequestFinished(). | 68 // in RequestFinished(). |
| 69 // | 69 // |
| 70 // Returns a closure to cancel the request. The closure cancels the request | 70 // Returns a closure to cancel the request. The closure cancels the request |
| 71 // if it is in-flight, and does nothing if it is already terminated. | 71 // if it is in-flight, and does nothing if it is already terminated. |
| 72 base::Closure StartRequestWithRetry(AuthenticatedRequestInterface* request); | 72 base::Closure StartRequestWithAuthRetry( |
| 73 AuthenticatedRequestInterface* request); |
| 73 | 74 |
| 74 // Notifies to this RequestSender that |request| has finished. | 75 // Notifies to this RequestSender that |request| has finished. |
| 75 // TODO(kinaba): refactor the life time management and make this at private. | 76 // TODO(kinaba): refactor the life time management and make this at private. |
| 76 void RequestFinished(AuthenticatedRequestInterface* request); | 77 void RequestFinished(AuthenticatedRequestInterface* request); |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 // Called when the access token is fetched. | 80 // Called when the access token is fetched. |
| 80 void OnAccessTokenFetched( | 81 void OnAccessTokenFetched( |
| 81 const base::WeakPtr<AuthenticatedRequestInterface>& request, | 82 const base::WeakPtr<AuthenticatedRequestInterface>& request, |
| 82 DriveApiErrorCode error, | 83 DriveApiErrorCode error, |
| 83 const std::string& access_token); | 84 const std::string& access_token); |
| 84 | 85 |
| 85 // Clears any authentication token and retries the request, which forces | 86 // Clears any authentication token and retries the request, which forces |
| 86 // an authentication token refresh. | 87 // an authentication token refresh. |
| 87 void RetryRequest(AuthenticatedRequestInterface* request); | 88 void RetryRequest(AuthenticatedRequestInterface* request); |
| 88 | 89 |
| 89 // Cancels the request. Used for implementing the returned closure of | 90 // Cancels the request. Used for implementing the returned closure of |
| 90 // StartRequestWithRetry. | 91 // StartRequestWithAuthRetry. |
| 91 void CancelRequest( | 92 void CancelRequest( |
| 92 const base::WeakPtr<AuthenticatedRequestInterface>& request); | 93 const base::WeakPtr<AuthenticatedRequestInterface>& request); |
| 93 | 94 |
| 94 scoped_ptr<AuthServiceInterface> auth_service_; | 95 scoped_ptr<AuthServiceInterface> auth_service_; |
| 95 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 96 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 96 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 97 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 97 | 98 |
| 98 std::set<AuthenticatedRequestInterface*> in_flight_requests_; | 99 std::set<AuthenticatedRequestInterface*> in_flight_requests_; |
| 99 const std::string custom_user_agent_; | 100 const std::string custom_user_agent_; |
| 100 | 101 |
| 101 base::ThreadChecker thread_checker_; | 102 base::ThreadChecker thread_checker_; |
| 102 | 103 |
| 103 // Note: This should remain the last member so it'll be destroyed and | 104 // Note: This should remain the last member so it'll be destroyed and |
| 104 // invalidate its weak pointers before any other members are destroyed. | 105 // invalidate its weak pointers before any other members are destroyed. |
| 105 base::WeakPtrFactory<RequestSender> weak_ptr_factory_; | 106 base::WeakPtrFactory<RequestSender> weak_ptr_factory_; |
| 106 | 107 |
| 107 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 108 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| 108 }; | 109 }; |
| 109 | 110 |
| 110 } // namespace google_apis | 111 } // namespace google_apis |
| 111 | 112 |
| 112 #endif // GOOGLE_APIS_DRIVE_REQUEST_SENDER_H_ | 113 #endif // GOOGLE_APIS_DRIVE_REQUEST_SENDER_H_ |
| OLD | NEW |