| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ | |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "chrome/browser/google_apis/gdata_errorcode.h" | |
| 15 | |
| 16 class Profile; | |
| 17 | |
| 18 namespace net { | |
| 19 class URLRequestContextGetter; | |
| 20 } | |
| 21 | |
| 22 namespace google_apis { | |
| 23 | |
| 24 class AuthenticatedRequestInterface; | |
| 25 class AuthService; | |
| 26 class OperationRegistry; | |
| 27 | |
| 28 // Helper class that runs AuthenticatedRequestInterface objects, handling | |
| 29 // retries and authentication. | |
| 30 class OperationRunner { | |
| 31 public: | |
| 32 // |url_request_context_getter| is used to perform authentication with | |
| 33 // AuthService. | |
| 34 // | |
| 35 // |scopes| specifies OAuth2 scopes. | |
| 36 // | |
| 37 // |custom_user_agent| will be used for the User-Agent header in HTTP | |
| 38 // requests issued through the operation runner if the value is not empty. | |
| 39 OperationRunner(Profile* profile, | |
| 40 net::URLRequestContextGetter* url_request_context_getter, | |
| 41 const std::vector<std::string>& scopes, | |
| 42 const std::string& custom_user_agent); | |
| 43 virtual ~OperationRunner(); | |
| 44 | |
| 45 AuthService* auth_service() { return auth_service_.get(); } | |
| 46 OperationRegistry* operation_registry() { | |
| 47 return operation_registry_.get(); | |
| 48 } | |
| 49 | |
| 50 // Prepares the object for use. | |
| 51 virtual void Initialize(); | |
| 52 | |
| 53 // Cancels all in-flight operations. | |
| 54 void CancelAll(); | |
| 55 | |
| 56 // Starts an operation implementing the AuthenticatedRequestInterface | |
| 57 // interface, and makes the operation retry upon authentication failures by | |
| 58 // calling back to RetryOperation. | |
| 59 void StartOperationWithRetry(AuthenticatedRequestInterface* operation); | |
| 60 | |
| 61 private: | |
| 62 // Called when the access token is fetched. | |
| 63 void OnAccessTokenFetched( | |
| 64 const base::WeakPtr<AuthenticatedRequestInterface>& operation, | |
| 65 GDataErrorCode error, | |
| 66 const std::string& access_token); | |
| 67 | |
| 68 // Clears any authentication token and retries the operation, which forces | |
| 69 // an authentication token refresh. | |
| 70 void RetryOperation(AuthenticatedRequestInterface* operation); | |
| 71 | |
| 72 Profile* profile_; // Not owned. | |
| 73 | |
| 74 scoped_ptr<AuthService> auth_service_; | |
| 75 scoped_ptr<OperationRegistry> operation_registry_; | |
| 76 const std::string custom_user_agent_; | |
| 77 | |
| 78 // Note: This should remain the last member so it'll be destroyed and | |
| 79 // invalidate its weak pointers before any other members are destroyed. | |
| 80 base::WeakPtrFactory<OperationRunner> weak_ptr_factory_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(OperationRunner); | |
| 83 }; | |
| 84 | |
| 85 } // namespace google_apis | |
| 86 | |
| 87 #endif // CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ | |
| OLD | NEW |