Chromium Code Reviews| 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 CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
| 17 #include "chrome/browser/google_apis/gdata_errorcode.h" | 18 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 18 | 19 |
| 19 class Profile; | 20 class Profile; |
| 20 | 21 |
| 22 namespace base { | |
| 23 class TaskRunner; | |
| 24 } | |
| 25 | |
| 21 namespace net { | 26 namespace net { |
| 22 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
| 23 } | 28 } |
| 24 | 29 |
| 25 namespace google_apis { | 30 namespace google_apis { |
| 26 | 31 |
| 27 class AuthenticatedRequestInterface; | 32 class AuthenticatedRequestInterface; |
| 28 class AuthService; | 33 class AuthService; |
| 29 | 34 |
| 30 // Helper class that sends requests implementing | 35 // Helper class that sends requests implementing |
| 31 // AuthenticatedRequestInterface and handles retries and authentication. | 36 // AuthenticatedRequestInterface and handles retries and authentication. |
| 32 class RequestSender { | 37 class RequestSender { |
| 33 public: | 38 public: |
| 34 // |url_request_context_getter| is used to perform authentication with | 39 // |url_request_context_getter| is used to perform authentication with |
| 35 // AuthService. | 40 // AuthService. |
| 36 // | 41 // |
| 37 // |scopes| specifies OAuth2 scopes. | 42 // |scopes| specifies OAuth2 scopes. |
| 38 // | 43 // |
| 39 // |custom_user_agent| will be used for the User-Agent header in HTTP | 44 // |custom_user_agent| will be used for the User-Agent header in HTTP |
| 40 // requests issued through the request sender if the value is not empty. | 45 // requests issued through the request sender if the value is not empty. |
|
satorux1
2013/07/08 01:30:07
Please document |blocking_task_runner|
kinaba
2013/07/08 03:12:02
Done.
| |
| 41 RequestSender(Profile* profile, | 46 RequestSender(Profile* profile, |
| 42 net::URLRequestContextGetter* url_request_context_getter, | 47 net::URLRequestContextGetter* url_request_context_getter, |
| 48 base::TaskRunner* blocking_task_runner_, | |
| 43 const std::vector<std::string>& scopes, | 49 const std::vector<std::string>& scopes, |
| 44 const std::string& custom_user_agent); | 50 const std::string& custom_user_agent); |
| 45 virtual ~RequestSender(); | 51 virtual ~RequestSender(); |
| 46 | 52 |
| 47 AuthService* auth_service() { return auth_service_.get(); } | 53 AuthService* auth_service() { return auth_service_.get(); } |
| 48 | 54 |
| 49 net::URLRequestContextGetter* url_request_context_getter() const { | 55 net::URLRequestContextGetter* url_request_context_getter() const { |
| 50 return url_request_context_getter_; | 56 return url_request_context_getter_; |
| 51 } | 57 } |
| 52 | 58 |
| 59 base::TaskRunner* blocking_task_runner() const { | |
| 60 return blocking_task_runner_.get(); | |
| 61 } | |
| 62 | |
| 53 // Prepares the object for use. | 63 // Prepares the object for use. |
| 54 virtual void Initialize(); | 64 virtual void Initialize(); |
| 55 | 65 |
| 56 // Starts a request implementing the AuthenticatedRequestInterface | 66 // Starts a request implementing the AuthenticatedRequestInterface |
| 57 // interface, and makes the request retry upon authentication failures by | 67 // interface, and makes the request retry upon authentication failures by |
| 58 // calling back to RetryRequest. The |request| object is owned by this | 68 // calling back to RetryRequest. The |request| object is owned by this |
| 59 // RequestSender. It will be deleted in RequestSender's destructor or | 69 // RequestSender. It will be deleted in RequestSender's destructor or |
| 60 // in RequestFinished(). | 70 // in RequestFinished(). |
| 61 // | 71 // |
| 62 // Returns a closure to cancel the request. The closure cancels the request | 72 // Returns a closure to cancel the request. The closure cancels the request |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 78 // an authentication token refresh. | 88 // an authentication token refresh. |
| 79 void RetryRequest(AuthenticatedRequestInterface* request); | 89 void RetryRequest(AuthenticatedRequestInterface* request); |
| 80 | 90 |
| 81 // Cancels the request. Used for implementing the returned closure of | 91 // Cancels the request. Used for implementing the returned closure of |
| 82 // StartRequestWithRetry. | 92 // StartRequestWithRetry. |
| 83 void CancelRequest( | 93 void CancelRequest( |
| 84 const base::WeakPtr<AuthenticatedRequestInterface>& request); | 94 const base::WeakPtr<AuthenticatedRequestInterface>& request); |
| 85 | 95 |
| 86 Profile* profile_; // Not owned. | 96 Profile* profile_; // Not owned. |
| 87 net::URLRequestContextGetter* url_request_context_getter_; // Not owned. | 97 net::URLRequestContextGetter* url_request_context_getter_; // Not owned. |
| 98 scoped_refptr<base::TaskRunner> blocking_task_runner_; | |
| 88 | 99 |
| 89 scoped_ptr<AuthService> auth_service_; | 100 scoped_ptr<AuthService> auth_service_; |
| 90 std::set<AuthenticatedRequestInterface*> in_flight_requests_; | 101 std::set<AuthenticatedRequestInterface*> in_flight_requests_; |
| 91 const std::string custom_user_agent_; | 102 const std::string custom_user_agent_; |
| 92 | 103 |
| 93 base::ThreadChecker thread_checker_; | 104 base::ThreadChecker thread_checker_; |
| 94 | 105 |
| 95 // Note: This should remain the last member so it'll be destroyed and | 106 // Note: This should remain the last member so it'll be destroyed and |
| 96 // invalidate its weak pointers before any other members are destroyed. | 107 // invalidate its weak pointers before any other members are destroyed. |
| 97 base::WeakPtrFactory<RequestSender> weak_ptr_factory_; | 108 base::WeakPtrFactory<RequestSender> weak_ptr_factory_; |
| 98 | 109 |
| 99 DISALLOW_COPY_AND_ASSIGN(RequestSender); | 110 DISALLOW_COPY_AND_ASSIGN(RequestSender); |
| 100 }; | 111 }; |
| 101 | 112 |
| 102 } // namespace google_apis | 113 } // namespace google_apis |
| 103 | 114 |
| 104 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ | 115 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ |
| OLD | NEW |