Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: chrome/browser/webdata/web_data_request_manager.h

Issue 11783091: Remove GenericRequest templates from WebDataService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch result_ to scopted_ptr Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/webdata/web_data_request_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // This can be invoked from any thread. From this point we assume that 48 // This can be invoked from any thread. From this point we assume that
49 // our consumer_ reference is invalid. 49 // our consumer_ reference is invalid.
50 void Cancel(); 50 void Cancel();
51 51
52 // Invoked by the service when this request has been completed. 52 // Invoked by the service when this request has been completed.
53 // This will notify the service in whatever thread was used to create this 53 // This will notify the service in whatever thread was used to create this
54 // request. 54 // request.
55 void RequestComplete(); 55 void RequestComplete();
56 56
57 // The result is owned by the request. 57 // The result is owned by the request.
58 void SetResult(WDTypedResult* r); 58 void SetResult(scoped_ptr<WDTypedResult> r);
59 const WDTypedResult* GetResult() const; 59 const WDTypedResult* GetResult() const;
60 60
61 private: 61 private:
62 // Used to notify service of request completion. 62 // Used to notify service of request completion.
63 scoped_refptr<WebDataService> service_; 63 scoped_refptr<WebDataService> service_;
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 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 templates
87 //
88 // Internally we use instances of the following template to represent
89 // requests.
90 //////////////////////////////////////////////////////////////////////////////
91
92 template <class T>
93 class GenericRequest : public WebDataRequest {
94 public:
95 GenericRequest(WebDataService* service,
96 WebDataServiceConsumer* consumer,
97 WebDataRequestManager* manager,
98 const T& arg)
99 : WebDataRequest(service, consumer, manager),
100 arg_(arg) {
101 }
102
103 virtual ~GenericRequest() {
104 }
105
106 const T& arg() const { return arg_; }
107
108 private:
109 T arg_;
110 };
111
112 template <class T, class U>
113 class GenericRequest2 : public WebDataRequest {
114 public:
115 GenericRequest2(WebDataService* service,
116 WebDataServiceConsumer* consumer,
117 WebDataRequestManager* manager,
118 const T& arg1,
119 const U& arg2)
120 : WebDataRequest(service, consumer, manager),
121 arg1_(arg1),
122 arg2_(arg2) {
123 }
124
125 virtual ~GenericRequest2() { }
126
127 const T& arg1() const { return arg1_; }
128
129 const U& arg2() const { return arg2_; }
130
131 private:
132 T arg1_;
133 U arg2_;
134 };
135
136 //////////////////////////////////////////////////////////////////////////////
137 //
138 // Webdata Request Manager 86 // Webdata Request Manager
139 // 87 //
140 // Tracks all WebDataRequests for a WebDataService. 88 // Tracks all WebDataRequests for a WebDataService.
141 // 89 //
142 // 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/
143 ////////////////////////////////////////////////////////////////////////////// 91 //////////////////////////////////////////////////////////////////////////////
144 class WebDataRequestManager { 92 class WebDataRequestManager {
145 public: 93 public:
146 WebDataRequestManager(); 94 WebDataRequestManager();
147 95
(...skipping 18 matching lines...) Expand all
166 // Next handle to be used for requests. Incremented for each use. 114 // Next handle to be used for requests. Incremented for each use.
167 WebDataServiceBase::Handle next_request_handle_; 115 WebDataServiceBase::Handle next_request_handle_;
168 116
169 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; 117 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap;
170 RequestMap pending_requests_; 118 RequestMap pending_requests_;
171 119
172 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); 120 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager);
173 }; 121 };
174 122
175 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ 123 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/webdata/web_data_request_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698