| 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__ |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/api/webdata/web_data_results.h" | 16 #include "chrome/browser/api/webdata/web_data_results.h" |
| 17 #include "chrome/browser/api/webdata/web_data_service_base.h" | 17 #include "chrome/browser/api/webdata/web_data_service_base.h" |
| 18 #include "chrome/browser/api/webdata/web_data_service_consumer.h" | 18 #include "chrome/browser/api/webdata/web_data_service_consumer.h" |
| 19 | 19 |
| 20 class MessageLoop; | |
| 21 class WebDataService; | 20 class WebDataService; |
| 22 class WebDataServiceConsumer; | 21 class WebDataServiceConsumer; |
| 23 class WebDataRequestManager; | 22 class WebDataRequestManager; |
| 24 | 23 |
| 24 namespace base { |
| 25 class MessageLoop; |
| 26 } |
| 27 |
| 25 ////////////////////////////////////////////////////////////////////////////// | 28 ////////////////////////////////////////////////////////////////////////////// |
| 26 // | 29 // |
| 27 // Webdata requests | 30 // Webdata requests |
| 28 // | 31 // |
| 29 // Every request is processed using a request object. The object contains | 32 // Every request is processed using a request object. The object contains |
| 30 // both the request parameters and the results. | 33 // both the request parameters and the results. |
| 31 ////////////////////////////////////////////////////////////////////////////// | 34 ////////////////////////////////////////////////////////////////////////////// |
| 32 class WebDataRequest { | 35 class WebDataRequest { |
| 33 public: | 36 public: |
| 34 WebDataRequest(WebDataServiceConsumer* consumer, | 37 WebDataRequest(WebDataServiceConsumer* consumer, |
| 35 WebDataRequestManager* manager); | 38 WebDataRequestManager* manager); |
| 36 | 39 |
| 37 virtual ~WebDataRequest(); | 40 virtual ~WebDataRequest(); |
| 38 | 41 |
| 39 WebDataServiceBase::Handle GetHandle() const; | 42 WebDataServiceBase::Handle GetHandle() const; |
| 40 | 43 |
| 41 // Retrieves the |consumer_| set in the constructor. | 44 // Retrieves the |consumer_| set in the constructor. |
| 42 WebDataServiceConsumer* GetConsumer() const; | 45 WebDataServiceConsumer* GetConsumer() const; |
| 43 | 46 |
| 44 // Retrieves the original message loop the of the request. | 47 // Retrieves the original message loop the of the request. |
| 45 MessageLoop* GetMessageLoop() const; | 48 base::MessageLoop* GetMessageLoop() const; |
| 46 | 49 |
| 47 // Returns |true| if the request was cancelled via the |Cancel()| method. | 50 // Returns |true| if the request was cancelled via the |Cancel()| method. |
| 48 bool IsCancelled() const; | 51 bool IsCancelled() const; |
| 49 | 52 |
| 50 // This can be invoked from any thread. From this point we assume that | 53 // This can be invoked from any thread. From this point we assume that |
| 51 // our consumer_ reference is invalid. | 54 // our consumer_ reference is invalid. |
| 52 void Cancel(); | 55 void Cancel(); |
| 53 | 56 |
| 54 // Invoked when the request has been completed. | 57 // Invoked when the request has been completed. |
| 55 void OnComplete(); | 58 void OnComplete(); |
| 56 | 59 |
| 57 // The result is owned by the request. | 60 // The result is owned by the request. |
| 58 void SetResult(scoped_ptr<WDTypedResult> r); | 61 void SetResult(scoped_ptr<WDTypedResult> r); |
| 59 | 62 |
| 60 // Transfers ownership pof result to caller. Should only be called once per | 63 // Transfers ownership pof result to caller. Should only be called once per |
| 61 // result. | 64 // result. |
| 62 scoped_ptr<WDTypedResult> GetResult(); | 65 scoped_ptr<WDTypedResult> GetResult(); |
| 63 | 66 |
| 64 private: | 67 private: |
| 65 // Used to notify manager if request is cancelled. Uses a raw ptr instead of | 68 // Used to notify manager if request is cancelled. Uses a raw ptr instead of |
| 66 // a ref_ptr so that it can be set to NULL when a request is cancelled. | 69 // a ref_ptr so that it can be set to NULL when a request is cancelled. |
| 67 WebDataRequestManager* manager_; | 70 WebDataRequestManager* manager_; |
| 68 | 71 |
| 69 // Tracks loop that the request originated on. | 72 // Tracks loop that the request originated on. |
| 70 MessageLoop* message_loop_; | 73 base::MessageLoop* message_loop_; |
| 71 | 74 |
| 72 // Identifier for this request. | 75 // Identifier for this request. |
| 73 WebDataServiceBase::Handle handle_; | 76 WebDataServiceBase::Handle handle_; |
| 74 | 77 |
| 75 // A lock to protect against simultaneous cancellations of the request. | 78 // A lock to protect against simultaneous cancellations of the request. |
| 76 // Cancellation affects both the |cancelled_| flag and |consumer_|. | 79 // Cancellation affects both the |cancelled_| flag and |consumer_|. |
| 77 mutable base::Lock cancel_lock_; | 80 mutable base::Lock cancel_lock_; |
| 78 bool cancelled_; | 81 bool cancelled_; |
| 79 | 82 |
| 80 // The originator of the service request. | 83 // The originator of the service request. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Next handle to be used for requests. Incremented for each use. | 128 // Next handle to be used for requests. Incremented for each use. |
| 126 WebDataServiceBase::Handle next_request_handle_; | 129 WebDataServiceBase::Handle next_request_handle_; |
| 127 | 130 |
| 128 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; | 131 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; |
| 129 RequestMap pending_requests_; | 132 RequestMap pending_requests_; |
| 130 | 133 |
| 131 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); | 134 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); |
| 132 }; | 135 }; |
| 133 | 136 |
| 134 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | 137 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ |
| OLD | NEW |