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_GOOGLE_APIS_REQUEST_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ |
6 #define CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/id_map.h" | 10 #include "base/id_map.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 REQUEST_IN_PROGRESS, | 22 REQUEST_IN_PROGRESS, |
23 REQUEST_COMPLETED, | 23 REQUEST_COMPLETED, |
24 REQUEST_FAILED, | 24 REQUEST_FAILED, |
25 }; | 25 }; |
26 | 26 |
27 // Returns string representations of the request state. | 27 // Returns string representations of the request state. |
28 std::string RequestTransferStateToString(RequestTransferState state); | 28 std::string RequestTransferStateToString(RequestTransferState state); |
29 | 29 |
30 // Structure that packs progress information of each request. | 30 // Structure that packs progress information of each request. |
31 struct RequestProgressStatus { | 31 struct RequestProgressStatus { |
32 explicit RequestProgressStatus(const base::FilePath& file_path); | 32 RequestProgressStatus(); |
33 | 33 |
34 RequestID request_id; | 34 RequestID request_id; |
35 | 35 |
36 // Drive path of the file dealt with the current request. | |
37 base::FilePath file_path; | |
38 // Current state of the transfer; | 36 // Current state of the transfer; |
39 RequestTransferState transfer_state; | 37 RequestTransferState transfer_state; |
40 }; | 38 }; |
41 | 39 |
42 // This class tracks all the in-flight Google API requests and manage | 40 // This class tracks all the in-flight Google API requests and manage |
43 // their lifetime. | 41 // their lifetime. |
44 class RequestRegistry { | 42 class RequestRegistry { |
45 public: | 43 public: |
46 RequestRegistry(); | 44 RequestRegistry(); |
47 ~RequestRegistry(); | 45 ~RequestRegistry(); |
48 | 46 |
49 // Base class for requests that this registry class can maintain. | 47 // Base class for requests that this registry class can maintain. |
50 // NotifyStart() passes the ownership of the Request object to the registry. | 48 // NotifyStart() passes the ownership of the Request object to the registry. |
51 // In particular, calling NotifyFinish() causes the registry to delete the | 49 // In particular, calling NotifyFinish() causes the registry to delete the |
52 // Request object itself. | 50 // Request object itself. |
53 class Request { | 51 class Request { |
54 public: | 52 public: |
55 explicit Request(RequestRegistry* registry); | 53 explicit Request(RequestRegistry* registry); |
56 Request(RequestRegistry* registry, const base::FilePath& file_path); | |
57 virtual ~Request(); | 54 virtual ~Request(); |
58 | 55 |
59 // Cancels the ongoing request. NotifyFinish() is called and the Request | 56 // Cancels the ongoing request. NotifyFinish() is called and the Request |
60 // object is deleted once the cancellation is done in DoCancel(). | 57 // object is deleted once the cancellation is done in DoCancel(). |
61 void Cancel(); | 58 void Cancel(); |
62 | 59 |
63 // Retrieves the current progress status of the request. | 60 // Retrieves the current progress status of the request. |
64 const RequestProgressStatus& progress_status() const { | 61 const RequestProgressStatus& progress_status() const { |
65 return progress_status_; | 62 return progress_status_; |
66 } | 63 } |
(...skipping 24 matching lines...) Expand all Loading... |
91 | 88 |
92 typedef IDMap<Request, IDMapOwnPointer> RequestIDMap; | 89 typedef IDMap<Request, IDMapOwnPointer> RequestIDMap; |
93 RequestIDMap in_flight_requests_; | 90 RequestIDMap in_flight_requests_; |
94 | 91 |
95 DISALLOW_COPY_AND_ASSIGN(RequestRegistry); | 92 DISALLOW_COPY_AND_ASSIGN(RequestRegistry); |
96 }; | 93 }; |
97 | 94 |
98 } // namespace google_apis | 95 } // namespace google_apis |
99 | 96 |
100 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ | 97 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ |
OLD | NEW |