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_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_OPERATION_REGISTRY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_OPERATION_REGISTRY_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/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/id_map.h" | 13 #include "base/id_map.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 | 16 |
17 namespace gdata { | 17 namespace gdata { |
18 | 18 |
19 // This class tracks all the in-flight GData operation objects and manage their | 19 // This class tracks all the in-flight GData operation objects and manage their |
20 // lifetime. | 20 // lifetime. |
21 class GDataOperationRegistry { | 21 class OperationRegistry { |
22 public: | 22 public: |
23 GDataOperationRegistry(); | 23 OperationRegistry(); |
24 ~GDataOperationRegistry(); | 24 ~OperationRegistry(); |
25 | 25 |
26 // Unique ID to identify each operation. | 26 // Unique ID to identify each operation. |
27 typedef int32 OperationID; | 27 typedef int32 OperationID; |
28 | 28 |
29 // Enumeration type for indicating the direction of the operation. | 29 // Enumeration type for indicating the direction of the operation. |
30 enum OperationType { | 30 enum OperationType { |
31 OPERATION_UPLOAD, | 31 OPERATION_UPLOAD, |
32 OPERATION_DOWNLOAD, | 32 OPERATION_DOWNLOAD, |
33 OPERATION_OTHER, | 33 OPERATION_OTHER, |
34 }; | 34 }; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 protected: | 83 protected: |
84 virtual ~Observer() {} | 84 virtual ~Observer() {} |
85 }; | 85 }; |
86 | 86 |
87 // Base class for operations that this registry class can maintain. | 87 // Base class for operations that this registry class can maintain. |
88 // NotifyStart() passes the ownership of the Operation object to the registry. | 88 // NotifyStart() passes the ownership of the Operation object to the registry. |
89 // In particular, calling NotifyFinish() causes the registry to delete the | 89 // In particular, calling NotifyFinish() causes the registry to delete the |
90 // Operation object itself. | 90 // Operation object itself. |
91 class Operation { | 91 class Operation { |
92 public: | 92 public: |
93 explicit Operation(GDataOperationRegistry* registry); | 93 explicit Operation(OperationRegistry* registry); |
94 Operation(GDataOperationRegistry* registry, | 94 Operation(OperationRegistry* registry, |
95 OperationType type, | 95 OperationType type, |
96 const FilePath& file_path); | 96 const FilePath& file_path); |
97 virtual ~Operation(); | 97 virtual ~Operation(); |
98 | 98 |
99 // Cancels the ongoing operation. NotifyFinish() is called and the Operation | 99 // Cancels the ongoing operation. NotifyFinish() is called and the Operation |
100 // object is deleted once the cancellation is done in DoCancel(). | 100 // object is deleted once the cancellation is done in DoCancel(). |
101 void Cancel(); | 101 void Cancel(); |
102 | 102 |
103 // Retrieves the current progress status of the operation. | 103 // Retrieves the current progress status of the operation. |
104 const ProgressStatus& progress_status() const { return progress_status_; } | 104 const ProgressStatus& progress_status() const { return progress_status_; } |
(...skipping 12 matching lines...) Expand all Loading... |
117 // that it removes the existing "suspend" operation. | 117 // that it removes the existing "suspend" operation. |
118 void NotifySuspend(); | 118 void NotifySuspend(); |
119 void NotifyResume(); | 119 void NotifyResume(); |
120 // Notifies that authentication has failed. | 120 // Notifies that authentication has failed. |
121 void NotifyAuthFailed(); | 121 void NotifyAuthFailed(); |
122 | 122 |
123 private: | 123 private: |
124 // Does the cancellation. | 124 // Does the cancellation. |
125 virtual void DoCancel() = 0; | 125 virtual void DoCancel() = 0; |
126 | 126 |
127 GDataOperationRegistry* const registry_; | 127 OperationRegistry* const registry_; |
128 ProgressStatus progress_status_; | 128 ProgressStatus progress_status_; |
129 }; | 129 }; |
130 | 130 |
131 // Cancels all in-flight operations. | 131 // Cancels all in-flight operations. |
132 void CancelAll(); | 132 void CancelAll(); |
133 | 133 |
134 // Cancels ongoing operation for a given virtual |file_path|. Returns true if | 134 // Cancels ongoing operation for a given virtual |file_path|. Returns true if |
135 // the operation was found and canceled. | 135 // the operation was found and canceled. |
136 bool CancelForFilePath(const FilePath& file_path); | 136 bool CancelForFilePath(const FilePath& file_path); |
137 | 137 |
(...skipping 28 matching lines...) Expand all Loading... |
166 // Sends notifications to the observers after checking that the frequency is | 166 // Sends notifications to the observers after checking that the frequency is |
167 // not too high by ShouldNotifyStatusNow. | 167 // not too high by ShouldNotifyStatusNow. |
168 void NotifyStatusToObservers(); | 168 void NotifyStatusToObservers(); |
169 | 169 |
170 typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap; | 170 typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap; |
171 OperationIDMap in_flight_operations_; | 171 OperationIDMap in_flight_operations_; |
172 ObserverList<Observer> observer_list_; | 172 ObserverList<Observer> observer_list_; |
173 base::Time last_notification_; | 173 base::Time last_notification_; |
174 bool do_notification_frequency_control_; | 174 bool do_notification_frequency_control_; |
175 | 175 |
176 DISALLOW_COPY_AND_ASSIGN(GDataOperationRegistry); | 176 DISALLOW_COPY_AND_ASSIGN(OperationRegistry); |
177 }; | 177 }; |
178 | 178 |
179 } // namespace gdata | 179 } // namespace gdata |
180 | 180 |
181 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_ | 181 #endif // CHROME_BROWSER_CHROMEOS_GDATA_OPERATION_REGISTRY_H_ |
OLD | NEW |