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_GOOGLE_APIS_REQUEST_REGISTRY_H_ | |
6 #define CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/id_map.h" | |
10 | |
11 namespace google_apis { | |
12 | |
13 // Unique ID to identify each request. | |
14 typedef int32 RequestID; | |
15 | |
16 // This class tracks all the in-flight Google API requests and manage | |
17 // their lifetime. | |
18 class RequestRegistry { | |
19 public: | |
20 RequestRegistry(); | |
21 ~RequestRegistry(); | |
22 | |
23 // Base class for requests that this registry class can maintain. | |
24 // NotifyStart() passes the ownership of the Request object to the registry. | |
25 // In particular, calling NotifyFinish() causes the registry to delete the | |
26 // Request object itself. | |
27 class Request { | |
28 public: | |
29 explicit Request(RequestRegistry* registry); | |
30 virtual ~Request(); | |
31 | |
32 protected: | |
33 // Notifies the registry about current status. | |
34 void NotifyStart(); | |
35 void NotifyFinish(); | |
36 | |
37 private: | |
38 RequestRegistry* const registry_; | |
39 RequestID id_; | |
40 }; | |
41 | |
42 private: | |
43 // Handlers for notifications from Requests. | |
44 friend class Request; | |
45 // Notifies that an request has started. This method passes the ownership of | |
46 // the request to the registry. A fresh request ID is returned to *id. | |
47 void OnRequestStart(Request* request, RequestID* id); | |
48 void OnRequestFinish(RequestID request_id); | |
49 | |
50 typedef IDMap<Request, IDMapOwnPointer> RequestIDMap; | |
51 RequestIDMap in_flight_requests_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(RequestRegistry); | |
54 }; | |
55 | |
56 } // namespace google_apis | |
57 | |
58 #endif // CHROME_BROWSER_GOOGLE_APIS_REQUEST_REGISTRY_H_ | |
OLD | NEW |