| 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_CHROMEOS_GDATA_OPERATION_RUNNER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_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 #include "chrome/browser/google_apis/operations_base.h" | |
| 16 | |
| 17 class Profile; | |
| 18 | |
| 19 namespace gdata { | |
| 20 | |
| 21 class AuthenticatedOperationInterface; | |
| 22 class AuthService; | |
| 23 class OperationRegistry; | |
| 24 | |
| 25 // Helper class that runs AuthenticatedOperationInterface objects, handling | |
| 26 // retries and authentication. | |
| 27 class OperationRunner { | |
| 28 public: | |
| 29 OperationRunner(Profile* profile, const std::vector<std::string>& scopes); | |
| 30 virtual ~OperationRunner(); | |
| 31 | |
| 32 AuthService* auth_service() { return auth_service_.get(); } | |
| 33 OperationRegistry* operation_registry() { | |
| 34 return operation_registry_.get(); | |
| 35 } | |
| 36 | |
| 37 // Prepares the object for use. | |
| 38 virtual void Initialize(); | |
| 39 | |
| 40 // Cancels all in-flight operations. | |
| 41 void CancelAll(); | |
| 42 | |
| 43 // Authenticates the user by fetching the auth token as needed. |callback| | |
| 44 // will be run with the error code and the auth token, on the thread this | |
| 45 // function is run. | |
| 46 void Authenticate(const AuthStatusCallback& callback); | |
| 47 | |
| 48 // Starts an operation implementing the AuthenticatedOperationInterface | |
| 49 // interface, and makes the operation retry upon authentication failures by | |
| 50 // calling back to RetryOperation. | |
| 51 void StartOperationWithRetry(AuthenticatedOperationInterface* operation); | |
| 52 | |
| 53 // Starts an operation implementing the AuthenticatedOperationInterface | |
| 54 // interface. | |
| 55 void StartOperation(AuthenticatedOperationInterface* operation); | |
| 56 | |
| 57 // Called when the authentication token is refreshed. | |
| 58 void OnOperationAuthRefresh(AuthenticatedOperationInterface* operation, | |
| 59 GDataErrorCode error, | |
| 60 const std::string& auth_token); | |
| 61 | |
| 62 // Clears any authentication token and retries the operation, which | |
| 63 // forces an authentication token refresh. | |
| 64 void RetryOperation(AuthenticatedOperationInterface* operation); | |
| 65 | |
| 66 private: | |
| 67 Profile* profile_; // not owned | |
| 68 | |
| 69 scoped_ptr<AuthService> auth_service_; | |
| 70 scoped_ptr<OperationRegistry> operation_registry_; | |
| 71 | |
| 72 // Note: This should remain the last member so it'll be destroyed and | |
| 73 // invalidate its weak pointers before any other members are destroyed. | |
| 74 base::WeakPtrFactory<OperationRunner> weak_ptr_factory_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(OperationRunner); | |
| 77 }; | |
| 78 | |
| 79 } // namespace gdata | |
| 80 | |
| 81 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATION_RUNNER_H_ | |
| OLD | NEW |