| 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_GDATA_OPERATION_REGISTRY_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Current state of the transfer; | 62 // Current state of the transfer; |
| 63 OperationTransferState transfer_state; | 63 OperationTransferState transfer_state; |
| 64 // The time when the operation is initiated. | 64 // The time when the operation is initiated. |
| 65 base::Time start_time; | 65 base::Time start_time; |
| 66 // Current fraction of progress of the operation. | 66 // Current fraction of progress of the operation. |
| 67 int64 progress_current; | 67 int64 progress_current; |
| 68 // Expected total number of bytes to be transferred in the operation. | 68 // Expected total number of bytes to be transferred in the operation. |
| 69 // -1 if no expectation is available (yet). | 69 // -1 if no expectation is available (yet). |
| 70 int64 progress_total; | 70 int64 progress_total; |
| 71 }; | 71 }; |
| 72 typedef std::vector<ProgressStatus> ProgressStatusList; |
| 72 | 73 |
| 73 // Observer interface for listening changes in the active set of operations. | 74 // Observer interface for listening changes in the active set of operations. |
| 74 class Observer { | 75 class Observer { |
| 75 public: | 76 public: |
| 76 // Called when a GData operation started, made some progress, or finished. | 77 // Called when a GData operation started, made some progress, or finished. |
| 77 virtual void OnProgressUpdate(const std::vector<ProgressStatus>& list) = 0; | 78 virtual void OnProgressUpdate(const ProgressStatusList& list) = 0; |
| 78 protected: | 79 protected: |
| 79 virtual ~Observer() {} | 80 virtual ~Observer() {} |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 // Base class for operations that this registry class can maintain. | 83 // Base class for operations that this registry class can maintain. |
| 83 // The Operation objects are owned by the registry. In particular, calling | 84 // The Operation objects are owned by the registry. In particular, calling |
| 84 // NotifyFinish() causes the registry to delete the Operation object itself. | 85 // NotifyFinish() causes the registry to delete the Operation object itself. |
| 85 class Operation { | 86 class Operation { |
| 86 public: | 87 public: |
| 87 explicit Operation(GDataOperationRegistry* registry); | 88 explicit Operation(GDataOperationRegistry* registry); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 // Cancels all in-flight operations. | 124 // Cancels all in-flight operations. |
| 124 void CancelAll(); | 125 void CancelAll(); |
| 125 | 126 |
| 126 // Cancels ongoing operation for a given virtual |file_path|. Returns true if | 127 // Cancels ongoing operation for a given virtual |file_path|. Returns true if |
| 127 // the operation was found and canceled. | 128 // the operation was found and canceled. |
| 128 bool CancelForFilePath(const FilePath& file_path); | 129 bool CancelForFilePath(const FilePath& file_path); |
| 129 | 130 |
| 130 // Obtains the list of currently active operations. | 131 // Obtains the list of currently active operations. |
| 131 std::vector<ProgressStatus> GetProgressStatusList(); | 132 ProgressStatusList GetProgressStatusList(); |
| 132 | 133 |
| 133 // Sets the observer. | 134 // Sets the observer. |
| 134 void AddObserver(Observer* observer); | 135 void AddObserver(Observer* observer); |
| 135 void RemoveObserver(Observer* observer); | 136 void RemoveObserver(Observer* observer); |
| 136 | 137 |
| 137 private: | 138 private: |
| 138 // Handlers for notifications from Operations. | 139 // Handlers for notifications from Operations. |
| 139 friend class Operation; | 140 friend class Operation; |
| 140 // The registry assigns a fresh operation ID and return it to *id. | 141 // The registry assigns a fresh operation ID and return it to *id. |
| 141 void OnOperationStart(Operation* operation, OperationID* id); | 142 void OnOperationStart(Operation* operation, OperationID* id); |
| 142 void OnOperationProgress(OperationID operation); | 143 void OnOperationProgress(OperationID operation); |
| 143 void OnOperationFinish(OperationID operation); | 144 void OnOperationFinish(OperationID operation); |
| 144 void OnOperationSuspend(OperationID operation); | 145 void OnOperationSuspend(OperationID operation); |
| 145 void OnOperationResume(Operation* operation, ProgressStatus* new_status); | 146 void OnOperationResume(Operation* operation, ProgressStatus* new_status); |
| 146 | 147 |
| 147 bool IsFileTransferOperation(const Operation* operation) const; | 148 bool IsFileTransferOperation(const Operation* operation) const; |
| 148 | 149 |
| 149 typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap; | 150 typedef IDMap<Operation, IDMapOwnPointer> OperationIDMap; |
| 150 OperationIDMap in_flight_operations_; | 151 OperationIDMap in_flight_operations_; |
| 151 ObserverList<Observer> observer_list_; | 152 ObserverList<Observer> observer_list_; |
| 152 | 153 |
| 153 DISALLOW_COPY_AND_ASSIGN(GDataOperationRegistry); | 154 DISALLOW_COPY_AND_ASSIGN(GDataOperationRegistry); |
| 154 }; | 155 }; |
| 155 | 156 |
| 156 } // namespace gdata | 157 } // namespace gdata |
| 157 | 158 |
| 158 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_ | 159 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_OPERATION_REGISTRY_H_ |
| OLD | NEW |