Chromium Code Reviews| 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 CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ |
| 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 ////////////////////////////////////////////////////////////////////////////// | 25 ////////////////////////////////////////////////////////////////////////////// |
| 26 // | 26 // |
| 27 // Webdata requests | 27 // Webdata requests |
| 28 // | 28 // |
| 29 // Every request is processed using a request object. The object contains | 29 // Every request is processed using a request object. The object contains |
| 30 // both the request parameters and the results. | 30 // both the request parameters and the results. |
| 31 ////////////////////////////////////////////////////////////////////////////// | 31 ////////////////////////////////////////////////////////////////////////////// |
| 32 class WebDataRequest { | 32 class WebDataRequest { |
| 33 public: | 33 public: |
| 34 WebDataRequest(WebDataService* service, | 34 WebDataRequest(WebDataServiceConsumer* consumer, |
| 35 WebDataServiceConsumer* consumer, | |
| 36 WebDataRequestManager* manager); | 35 WebDataRequestManager* manager); |
| 37 | 36 |
| 38 virtual ~WebDataRequest(); | 37 virtual ~WebDataRequest(); |
| 39 | 38 |
| 40 WebDataServiceBase::Handle GetHandle() const; | 39 WebDataServiceBase::Handle GetHandle() const; |
| 41 | 40 |
| 42 // Retrieves the |consumer_| set in the constructor. | 41 // Retrieves the |consumer_| set in the constructor. |
| 43 WebDataServiceConsumer* GetConsumer() const; | 42 WebDataServiceConsumer* GetConsumer() const; |
| 44 | 43 |
| 44 // Retrieves the original message loop the of the request. | |
| 45 MessageLoop* GetMessageLoop() const; | |
| 46 | |
| 45 // Returns |true| if the request was cancelled via the |Cancel()| method. | 47 // Returns |true| if the request was cancelled via the |Cancel()| method. |
| 46 bool IsCancelled() const; | 48 bool IsCancelled() const; |
| 47 | 49 |
| 48 // This can be invoked from any thread. From this point we assume that | 50 // This can be invoked from any thread. From this point we assume that |
| 49 // our consumer_ reference is invalid. | 51 // our consumer_ reference is invalid. |
| 50 void Cancel(); | 52 void Cancel(); |
| 51 | 53 |
| 52 // Invoked by the service when this request has been completed. | 54 // Invoked when the request has been completed. |
| 53 // This will notify the service in whatever thread was used to create this | 55 void OnComplete(); |
| 54 // request. | |
| 55 void RequestComplete(); | |
| 56 | 56 |
| 57 // The result is owned by the request. | 57 // The result is owned by the request. |
| 58 void SetResult(scoped_ptr<WDTypedResult> r); | 58 void SetResult(scoped_ptr<WDTypedResult> r); |
| 59 const WDTypedResult* GetResult() const; | 59 scoped_ptr<WDTypedResult> GetResult(); |
|
erikwright (departed)
2013/01/28 20:01:05
A note that the caller should only invoke this one
Cait (Slow)
2013/01/29 01:10:29
Done.
| |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 // Used to notify service of request completion. | 62 // Used to notify manager if request is cancelled. |
|
erikwright (departed)
2013/01/28 20:01:05
A note about why a raw pointer is used vs. a ref_p
Cait (Slow)
2013/01/29 01:10:29
Done.
| |
| 63 scoped_refptr<WebDataService> service_; | 63 WebDataRequestManager* manager_; |
| 64 | 64 |
| 65 // Tracks loop that the request originated on. | 65 // Tracks loop that the request originated on. |
| 66 MessageLoop* message_loop_; | 66 MessageLoop* message_loop_; |
| 67 | 67 |
| 68 // Identifier for this request. | 68 // Identifier for this request. |
| 69 WebDataServiceBase::Handle handle_; | 69 WebDataServiceBase::Handle handle_; |
| 70 | 70 |
| 71 // A lock to protect against simultaneous cancellations of the request. | 71 // A lock to protect against simultaneous cancellations of the request. |
| 72 // Cancellation affects both the |cancelled_| flag and |consumer_|. | 72 // Cancellation affects both the |cancelled_| flag and |consumer_|. |
| 73 mutable base::Lock cancel_lock_; | 73 mutable base::Lock cancel_lock_; |
| 74 bool cancelled_; | 74 bool cancelled_; |
| 75 | 75 |
| 76 // The originator of the service request. | 76 // The originator of the service request. |
| 77 WebDataServiceConsumer* consumer_; | 77 WebDataServiceConsumer* consumer_; |
| 78 | 78 |
| 79 scoped_ptr<WDTypedResult> result_; | 79 scoped_ptr<WDTypedResult> result_; |
| 80 | 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(WebDataRequest); | 81 DISALLOW_COPY_AND_ASSIGN(WebDataRequest); |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 ////////////////////////////////////////////////////////////////////////////// | 84 ////////////////////////////////////////////////////////////////////////////// |
| 85 // | 85 // |
| 86 // Webdata Request Manager | 86 // Webdata Request Manager |
| 87 // | 87 // |
| 88 // Tracks all WebDataRequests for a WebDataService. | 88 // Tracks all WebDataRequests for a WebDataService. |
| 89 // | 89 // |
| 90 // Note: This is an internal interface, not to be used outside of webdata/ | 90 // Note: This is an internal interface, not to be used outside of webdata/ |
| 91 ////////////////////////////////////////////////////////////////////////////// | 91 ////////////////////////////////////////////////////////////////////////////// |
| 92 class WebDataRequestManager { | 92 class WebDataRequestManager : public base::RefCounted<WebDataRequestManager> { |
| 93 public: | 93 public: |
| 94 WebDataRequestManager(); | 94 WebDataRequestManager(); |
| 95 | 95 |
| 96 ~WebDataRequestManager(); | |
| 97 | |
| 98 // Cancel any pending request. | 96 // Cancel any pending request. |
| 99 void CancelRequest(WebDataServiceBase::Handle h); | 97 void CancelRequest(WebDataServiceBase::Handle h); |
| 100 | 98 |
| 101 // Invoked by request implementations when a request has been processed. | 99 // Invoked by the WebDataService when |request| has been completed. |
| 102 void RequestCompleted(WebDataServiceBase::Handle h); | 100 void RequestCompleted(scoped_ptr<WebDataRequest> request); |
| 101 | |
| 102 // This will notify the consumer in whatever thread was used to create this | |
| 103 // request. | |
| 104 void RequestCompletedOnThread(scoped_ptr<WebDataRequest> request); | |
|
erikwright (departed)
2013/01/28 20:01:05
needs to be public?
Cait (Slow)
2013/01/29 01:10:29
Done.
| |
| 103 | 105 |
| 104 // Register the request as a pending request. | 106 // Register the request as a pending request. |
| 105 void RegisterRequest(WebDataRequest* request); | 107 void RegisterRequest(WebDataRequest* request); |
| 106 | 108 |
| 107 // Return the next request handle. | 109 // Return the next request handle. |
| 108 int GetNextRequestHandle(); | 110 int GetNextRequestHandle(); |
| 109 | 111 |
| 110 private: | 112 private: |
| 113 friend class base::RefCounted<WebDataRequestManager>; | |
| 114 | |
| 115 ~WebDataRequestManager(); | |
| 116 | |
| 111 // A lock to protect pending requests and next request handle. | 117 // A lock to protect pending requests and next request handle. |
| 112 base::Lock pending_lock_; | 118 base::Lock pending_lock_; |
| 113 | 119 |
| 114 // Next handle to be used for requests. Incremented for each use. | 120 // Next handle to be used for requests. Incremented for each use. |
| 115 WebDataServiceBase::Handle next_request_handle_; | 121 WebDataServiceBase::Handle next_request_handle_; |
| 116 | 122 |
| 117 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; | 123 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; |
| 118 RequestMap pending_requests_; | 124 RequestMap pending_requests_; |
| 119 | 125 |
| 120 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); | 126 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); |
| 121 }; | 127 }; |
| 122 | 128 |
| 123 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | 129 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ |
| OLD | NEW |