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