OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Chromium settings and storage represent user-selected preferences and | 5 // Chromium settings and storage represent user-selected preferences and |
6 // information and MUST not be extracted, overwritten or modified except | 6 // information and MUST not be extracted, overwritten or modified except |
7 // through Chromium defined APIs. | 7 // through Chromium defined APIs. |
8 | 8 |
9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ | 9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ |
10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ | 10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ |
11 | 11 |
12 #include <map> | 12 #include <map> |
| 13 #include <memory> |
13 | 14 |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
16 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
17 #include "components/webdata/common/web_data_results.h" | 18 #include "components/webdata/common/web_data_results.h" |
18 #include "components/webdata/common/web_data_service_base.h" | 19 #include "components/webdata/common/web_data_service_base.h" |
19 #include "components/webdata/common/web_data_service_consumer.h" | 20 #include "components/webdata/common/web_data_service_consumer.h" |
20 #include "components/webdata/common/web_database_service.h" | 21 #include "components/webdata/common/web_database_service.h" |
21 | 22 |
22 class WebDataServiceConsumer; | 23 class WebDataServiceConsumer; |
(...skipping 29 matching lines...) Expand all Loading... |
52 bool IsCancelled() const; | 53 bool IsCancelled() const; |
53 | 54 |
54 // This can be invoked from any thread. From this point we assume that | 55 // This can be invoked from any thread. From this point we assume that |
55 // our consumer_ reference is invalid. | 56 // our consumer_ reference is invalid. |
56 void Cancel(); | 57 void Cancel(); |
57 | 58 |
58 // Invoked when the request has been completed. | 59 // Invoked when the request has been completed. |
59 void OnComplete(); | 60 void OnComplete(); |
60 | 61 |
61 // The result is owned by the request. | 62 // The result is owned by the request. |
62 void SetResult(scoped_ptr<WDTypedResult> r); | 63 void SetResult(std::unique_ptr<WDTypedResult> r); |
63 | 64 |
64 // Transfers ownership pof result to caller. Should only be called once per | 65 // Transfers ownership pof result to caller. Should only be called once per |
65 // result. | 66 // result. |
66 scoped_ptr<WDTypedResult> GetResult(); | 67 std::unique_ptr<WDTypedResult> GetResult(); |
67 | 68 |
68 private: | 69 private: |
69 // Used to notify manager if request is cancelled. Uses a raw ptr instead of | 70 // Used to notify manager if request is cancelled. Uses a raw ptr instead of |
70 // a ref_ptr so that it can be set to NULL when a request is cancelled. | 71 // a ref_ptr so that it can be set to NULL when a request is cancelled. |
71 WebDataRequestManager* manager_; | 72 WebDataRequestManager* manager_; |
72 | 73 |
73 // Tracks loop that the request originated on. | 74 // Tracks loop that the request originated on. |
74 base::MessageLoop* message_loop_; | 75 base::MessageLoop* message_loop_; |
75 | 76 |
76 // Identifier for this request. | 77 // Identifier for this request. |
77 WebDataServiceBase::Handle handle_; | 78 WebDataServiceBase::Handle handle_; |
78 | 79 |
79 // A lock to protect against simultaneous cancellations of the request. | 80 // A lock to protect against simultaneous cancellations of the request. |
80 // Cancellation affects both the |cancelled_| flag and |consumer_|. | 81 // Cancellation affects both the |cancelled_| flag and |consumer_|. |
81 mutable base::Lock cancel_lock_; | 82 mutable base::Lock cancel_lock_; |
82 bool cancelled_; | 83 bool cancelled_; |
83 | 84 |
84 // The originator of the service request. | 85 // The originator of the service request. |
85 WebDataServiceConsumer* consumer_; | 86 WebDataServiceConsumer* consumer_; |
86 | 87 |
87 scoped_ptr<WDTypedResult> result_; | 88 std::unique_ptr<WDTypedResult> result_; |
88 | 89 |
89 DISALLOW_COPY_AND_ASSIGN(WebDataRequest); | 90 DISALLOW_COPY_AND_ASSIGN(WebDataRequest); |
90 }; | 91 }; |
91 | 92 |
92 ////////////////////////////////////////////////////////////////////////////// | 93 ////////////////////////////////////////////////////////////////////////////// |
93 // | 94 // |
94 // Webdata Request Manager | 95 // Webdata Request Manager |
95 // | 96 // |
96 // Tracks all WebDataRequests for a WebDataService. | 97 // Tracks all WebDataRequests for a WebDataService. |
97 // | 98 // |
98 // Note: This is an internal interface, not to be used outside of webdata/ | 99 // Note: This is an internal interface, not to be used outside of webdata/ |
99 ////////////////////////////////////////////////////////////////////////////// | 100 ////////////////////////////////////////////////////////////////////////////// |
100 class WebDataRequestManager | 101 class WebDataRequestManager |
101 : public base::RefCountedThreadSafe<WebDataRequestManager> { | 102 : public base::RefCountedThreadSafe<WebDataRequestManager> { |
102 public: | 103 public: |
103 WebDataRequestManager(); | 104 WebDataRequestManager(); |
104 | 105 |
105 // Cancel any pending request. | 106 // Cancel any pending request. |
106 void CancelRequest(WebDataServiceBase::Handle h); | 107 void CancelRequest(WebDataServiceBase::Handle h); |
107 | 108 |
108 // Invoked by the WebDataService when |request| has been completed. | 109 // Invoked by the WebDataService when |request| has been completed. |
109 void RequestCompleted(scoped_ptr<WebDataRequest> request); | 110 void RequestCompleted(std::unique_ptr<WebDataRequest> request); |
110 | 111 |
111 // Register the request as a pending request. | 112 // Register the request as a pending request. |
112 void RegisterRequest(WebDataRequest* request); | 113 void RegisterRequest(WebDataRequest* request); |
113 | 114 |
114 // Return the next request handle. | 115 // Return the next request handle. |
115 int GetNextRequestHandle(); | 116 int GetNextRequestHandle(); |
116 | 117 |
117 private: | 118 private: |
118 friend class base::RefCountedThreadSafe<WebDataRequestManager>; | 119 friend class base::RefCountedThreadSafe<WebDataRequestManager>; |
119 | 120 |
120 ~WebDataRequestManager(); | 121 ~WebDataRequestManager(); |
121 | 122 |
122 // This will notify the consumer in whatever thread was used to create this | 123 // This will notify the consumer in whatever thread was used to create this |
123 // request. | 124 // request. |
124 void RequestCompletedOnThread(scoped_ptr<WebDataRequest> request); | 125 void RequestCompletedOnThread(std::unique_ptr<WebDataRequest> request); |
125 | 126 |
126 // A lock to protect pending requests and next request handle. | 127 // A lock to protect pending requests and next request handle. |
127 base::Lock pending_lock_; | 128 base::Lock pending_lock_; |
128 | 129 |
129 // Next handle to be used for requests. Incremented for each use. | 130 // Next handle to be used for requests. Incremented for each use. |
130 WebDataServiceBase::Handle next_request_handle_; | 131 WebDataServiceBase::Handle next_request_handle_; |
131 | 132 |
132 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; | 133 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; |
133 RequestMap pending_requests_; | 134 RequestMap pending_requests_; |
134 | 135 |
135 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); | 136 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); |
136 }; | 137 }; |
137 | 138 |
138 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ | 139 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ |
OLD | NEW |