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_OPERATION_RUNNER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ |
6 #define CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chrome/browser/google_apis/auth_service.h" |
14 #include "chrome/browser/google_apis/base_operations.h" | 15 #include "chrome/browser/google_apis/base_operations.h" |
15 #include "chrome/browser/google_apis/gdata_errorcode.h" | 16 #include "chrome/browser/google_apis/gdata_errorcode.h" |
16 | 17 |
17 class Profile; | 18 class Profile; |
18 | 19 |
19 namespace google_apis { | 20 namespace google_apis { |
20 | 21 |
21 class AuthenticatedOperationInterface; | 22 class AuthenticatedOperationInterface; |
22 class AuthService; | 23 class AuthService; |
23 class OperationRegistry; | 24 class OperationRegistry; |
(...skipping 15 matching lines...) Expand all Loading... |
39 OperationRegistry* operation_registry() { | 40 OperationRegistry* operation_registry() { |
40 return operation_registry_.get(); | 41 return operation_registry_.get(); |
41 } | 42 } |
42 | 43 |
43 // Prepares the object for use. | 44 // Prepares the object for use. |
44 virtual void Initialize(); | 45 virtual void Initialize(); |
45 | 46 |
46 // Cancels all in-flight operations. | 47 // Cancels all in-flight operations. |
47 void CancelAll(); | 48 void CancelAll(); |
48 | 49 |
49 // Authenticates the user by fetching the auth token as needed. |callback| | |
50 // will be run with the error code and the auth token, on the thread this | |
51 // function is run. | |
52 void Authenticate(const AuthStatusCallback& callback); | |
53 | |
54 // Starts an operation implementing the AuthenticatedOperationInterface | 50 // Starts an operation implementing the AuthenticatedOperationInterface |
55 // interface, and makes the operation retry upon authentication failures by | 51 // interface, and makes the operation retry upon authentication failures by |
56 // calling back to RetryOperation. | 52 // calling back to RetryOperation. |
57 void StartOperationWithRetry(AuthenticatedOperationInterface* operation); | 53 void StartOperationWithRetry(AuthenticatedOperationInterface* operation); |
58 | 54 |
| 55 private: |
59 // Starts an operation implementing the AuthenticatedOperationInterface | 56 // Starts an operation implementing the AuthenticatedOperationInterface |
60 // interface. | 57 // interface. |
61 void StartOperation(AuthenticatedOperationInterface* operation); | 58 void StartOperation(AuthenticatedOperationInterface* operation); |
62 | 59 |
63 // Called when the authentication token is refreshed. | 60 // Called when the authentication token is refreshed. |
64 void OnOperationAuthRefresh( | 61 void OnOperationAuthRefresh( |
65 const base::WeakPtr<AuthenticatedOperationInterface>& operation, | 62 const base::WeakPtr<AuthenticatedOperationInterface>& operation, |
66 GDataErrorCode error, | 63 GDataErrorCode error, |
67 const std::string& auth_token); | 64 const std::string& auth_token); |
68 | 65 |
69 // Clears any authentication token and retries the operation, which | 66 // Clears any authentication token and retries the operation, which |
70 // forces an authentication token refresh. | 67 // forces an authentication token refresh. |
71 void RetryOperation(AuthenticatedOperationInterface* operation); | 68 void RetryOperation(AuthenticatedOperationInterface* operation); |
72 | 69 |
73 private: | |
74 Profile* profile_; // not owned | 70 Profile* profile_; // not owned |
75 | 71 |
76 scoped_ptr<AuthService> auth_service_; | 72 scoped_ptr<AuthService> auth_service_; |
77 scoped_ptr<OperationRegistry> operation_registry_; | 73 scoped_ptr<OperationRegistry> operation_registry_; |
78 const std::string custom_user_agent_; | 74 const std::string custom_user_agent_; |
79 | 75 |
80 // Note: This should remain the last member so it'll be destroyed and | 76 // Note: This should remain the last member so it'll be destroyed and |
81 // invalidate its weak pointers before any other members are destroyed. | 77 // invalidate its weak pointers before any other members are destroyed. |
82 base::WeakPtrFactory<OperationRunner> weak_ptr_factory_; | 78 base::WeakPtrFactory<OperationRunner> weak_ptr_factory_; |
83 | 79 |
84 DISALLOW_COPY_AND_ASSIGN(OperationRunner); | 80 DISALLOW_COPY_AND_ASSIGN(OperationRunner); |
85 }; | 81 }; |
86 | 82 |
87 } // namespace google_apis | 83 } // namespace google_apis |
88 | 84 |
89 #endif // CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ | 85 #endif // CHROME_BROWSER_GOOGLE_APIS_OPERATION_RUNNER_H_ |
OLD | NEW |