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

Side by Side Diff: chrome/browser/google_apis/request_sender.h

Issue 18742002: Remove direct reference to GetBlockingPool() in c/b/google_apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix + rebase. Created 7 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 | Annotate | Revision Log
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 #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 the context used to perform network
35 // AuthService. 40 // requests from this RequestSender.
41 //
42 // |blocking_task_runner| is used for running blocking operation, e.g.,
43 // parsing JSON response from the server.
36 // 44 //
37 // |scopes| specifies OAuth2 scopes. 45 // |scopes| specifies OAuth2 scopes.
38 // 46 //
39 // |custom_user_agent| will be used for the User-Agent header in HTTP 47 // |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. 48 // requests issued through the request sender if the value is not empty.
41 RequestSender(Profile* profile, 49 RequestSender(Profile* profile,
42 net::URLRequestContextGetter* url_request_context_getter, 50 net::URLRequestContextGetter* url_request_context_getter,
51 base::TaskRunner* blocking_task_runner,
43 const std::vector<std::string>& scopes, 52 const std::vector<std::string>& scopes,
44 const std::string& custom_user_agent); 53 const std::string& custom_user_agent);
45 virtual ~RequestSender(); 54 virtual ~RequestSender();
46 55
47 AuthService* auth_service() { return auth_service_.get(); } 56 AuthService* auth_service() { return auth_service_.get(); }
48 57
49 net::URLRequestContextGetter* url_request_context_getter() const { 58 net::URLRequestContextGetter* url_request_context_getter() const {
50 return url_request_context_getter_; 59 return url_request_context_getter_;
51 } 60 }
52 61
62 base::TaskRunner* blocking_task_runner() const {
63 return blocking_task_runner_.get();
64 }
65
53 // Prepares the object for use. 66 // Prepares the object for use.
54 virtual void Initialize(); 67 virtual void Initialize();
55 68
56 // Starts a request implementing the AuthenticatedRequestInterface 69 // Starts a request implementing the AuthenticatedRequestInterface
57 // interface, and makes the request retry upon authentication failures by 70 // interface, and makes the request retry upon authentication failures by
58 // calling back to RetryRequest. The |request| object is owned by this 71 // calling back to RetryRequest. The |request| object is owned by this
59 // RequestSender. It will be deleted in RequestSender's destructor or 72 // RequestSender. It will be deleted in RequestSender's destructor or
60 // in RequestFinished(). 73 // in RequestFinished().
61 // 74 //
62 // Returns a closure to cancel the request. The closure cancels the request 75 // Returns a closure to cancel the request. The closure cancels the request
(...skipping 15 matching lines...) Expand all
78 // an authentication token refresh. 91 // an authentication token refresh.
79 void RetryRequest(AuthenticatedRequestInterface* request); 92 void RetryRequest(AuthenticatedRequestInterface* request);
80 93
81 // Cancels the request. Used for implementing the returned closure of 94 // Cancels the request. Used for implementing the returned closure of
82 // StartRequestWithRetry. 95 // StartRequestWithRetry.
83 void CancelRequest( 96 void CancelRequest(
84 const base::WeakPtr<AuthenticatedRequestInterface>& request); 97 const base::WeakPtr<AuthenticatedRequestInterface>& request);
85 98
86 Profile* profile_; // Not owned. 99 Profile* profile_; // Not owned.
87 net::URLRequestContextGetter* url_request_context_getter_; // Not owned. 100 net::URLRequestContextGetter* url_request_context_getter_; // Not owned.
101 scoped_refptr<base::TaskRunner> blocking_task_runner_;
88 102
89 scoped_ptr<AuthService> auth_service_; 103 scoped_ptr<AuthService> auth_service_;
90 std::set<AuthenticatedRequestInterface*> in_flight_requests_; 104 std::set<AuthenticatedRequestInterface*> in_flight_requests_;
91 const std::string custom_user_agent_; 105 const std::string custom_user_agent_;
92 106
93 base::ThreadChecker thread_checker_; 107 base::ThreadChecker thread_checker_;
94 108
95 // Note: This should remain the last member so it'll be destroyed and 109 // Note: This should remain the last member so it'll be destroyed and
96 // invalidate its weak pointers before any other members are destroyed. 110 // invalidate its weak pointers before any other members are destroyed.
97 base::WeakPtrFactory<RequestSender> weak_ptr_factory_; 111 base::WeakPtrFactory<RequestSender> weak_ptr_factory_;
98 112
99 DISALLOW_COPY_AND_ASSIGN(RequestSender); 113 DISALLOW_COPY_AND_ASSIGN(RequestSender);
100 }; 114 };
101 115
102 } // namespace google_apis 116 } // namespace google_apis
103 117
104 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_ 118 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_SENDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698