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_GDATA_OPERATION_RUNNER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_OPERATION_RUNNER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_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/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 GDataOperationInterface; |
21 class GDataOperationRegistry; | 21 class OperationRegistry; |
22 | 22 |
23 // Helper class that runs GDataOperationInterface objects, handling retries and | 23 // Helper class that runs GDataOperationInterface objects, handling retries and |
24 // authentication. | 24 // authentication. |
25 class GDataOperationRunner : public GDataAuthService::Observer { | 25 class OperationRunner : public AuthService::Observer { |
26 public: | 26 public: |
27 explicit GDataOperationRunner(Profile* profile); | 27 explicit OperationRunner(Profile* profile); |
28 virtual ~GDataOperationRunner(); | 28 virtual ~OperationRunner(); |
29 | 29 |
30 GDataAuthService* auth_service() { return auth_service_.get(); } | 30 AuthService* auth_service() { return auth_service_.get(); } |
31 GDataOperationRegistry* 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| |
(...skipping 12 matching lines...) Expand all Loading... |
54 // Called when the authentication token is refreshed. | 54 // Called when the authentication token is refreshed. |
55 void OnOperationAuthRefresh(GDataOperationInterface* operation, | 55 void OnOperationAuthRefresh(GDataOperationInterface* operation, |
56 GDataErrorCode error, | 56 GDataErrorCode error, |
57 const std::string& auth_token); | 57 const std::string& auth_token); |
58 | 58 |
59 // Clears any authentication token and retries the operation, which | 59 // Clears any authentication token and retries the operation, which |
60 // forces an authentication token refresh. | 60 // forces an authentication token refresh. |
61 void RetryOperation(GDataOperationInterface* operation); | 61 void RetryOperation(GDataOperationInterface* operation); |
62 | 62 |
63 private: | 63 private: |
64 // GDataAuthService::Observer override. | 64 // AuthService::Observer override. |
65 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; | 65 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; |
66 | 66 |
67 Profile* profile_; // not owned | 67 Profile* profile_; // not owned |
68 | 68 |
69 scoped_ptr<GDataAuthService> auth_service_; | 69 scoped_ptr<AuthService> auth_service_; |
70 scoped_ptr<GDataOperationRegistry> operation_registry_; | 70 scoped_ptr<OperationRegistry> operation_registry_; |
71 | 71 |
72 // Note: This should remain the last member so it'll be destroyed and | 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. | 73 // invalidate its weak pointers before any other members are destroyed. |
74 base::WeakPtrFactory<GDataOperationRunner> weak_ptr_factory_; | 74 base::WeakPtrFactory<OperationRunner> weak_ptr_factory_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(GDataOperationRunner); | 76 DISALLOW_COPY_AND_ASSIGN(OperationRunner); |
77 }; | 77 }; |
78 | 78 |
79 } // namespace gdata | 79 } // namespace gdata |
80 | 80 |
81 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_RUNNER_H_ | 81 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATION_RUNNER_H_ |
OLD | NEW |