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_GDATA_OPERATION_RUNNER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_RUNNER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "chrome/browser/chromeos/gdata/gdata_auth_service.h" | |
14 #include "chrome/browser/chromeos/gdata/gdata_errorcode.h" | |
15 | |
16 class Profile; | |
17 | |
18 namespace gdata { | |
19 | |
20 class GDataOperationInterface; | |
21 class GDataOperationRegistry; | |
22 | |
23 // Helper class that runs GDataOperationInterface objects, handling retries and | |
24 // authentication. | |
25 class GDataOperationRunner : public GDataAuthService::Observer { | |
26 public: | |
27 explicit GDataOperationRunner(Profile* profile); | |
28 virtual ~GDataOperationRunner(); | |
29 | |
30 GDataAuthService* auth_service() { return auth_service_.get(); } | |
31 GDataOperationRegistry* operation_registry() { | |
32 return operation_registry_.get(); | |
33 } | |
34 | |
35 // Prepares the object for use. | |
36 virtual void Initialize(); | |
37 | |
38 // Cancels all in-flight operations. | |
39 void CancelAll(); | |
40 | |
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 | |
43 // function is run. | |
44 void Authenticate(const AuthStatusCallback& callback); | |
45 | |
46 // Starts an operation implementing the GDataOperationInterface interface, and | |
47 // makes the operation retry upon authentication failures by calling back to | |
48 // RetryOperation. | |
49 void StartOperationWithRetry(GDataOperationInterface* operation); | |
50 | |
51 // Starts an operation implementing the GDataOperationInterface interface. | |
52 void StartOperation(GDataOperationInterface* operation); | |
53 | |
54 // Called when the authentication token is refreshed. | |
55 void OnOperationAuthRefresh(GDataOperationInterface* operation, | |
56 GDataErrorCode error, | |
57 const std::string& auth_token); | |
58 | |
59 // Clears any authentication token and retries the operation, which | |
60 // forces an authentication token refresh. | |
61 void RetryOperation(GDataOperationInterface* operation); | |
62 | |
63 private: | |
64 // GDataAuthService::Observer override. | |
65 virtual void OnOAuth2RefreshTokenChanged() OVERRIDE; | |
66 | |
67 Profile* profile_; // not owned | |
68 | |
69 scoped_ptr<GDataAuthService> auth_service_; | |
70 scoped_ptr<GDataOperationRegistry> 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<GDataOperationRunner> weak_ptr_factory_; | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(GDataOperationRunner); | |
77 }; | |
78 | |
79 } // namespace gdata | |
80 | |
81 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_RUNNER_H_ | |
OLD | NEW |