OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
dhollowa
2013/01/04 01:34:50
nit: remove the "(c)" bit.
Cait (Slow)
2013/01/04 22:59:29
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Chromium settings and storage represent user-selected preferences and | |
6 // information and MUST not be extracted, overwritten or modified except | |
7 // through Chromium defined APIs. | |
8 | |
9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | |
10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | |
11 | |
12 #include <map> | |
13 #include <string> | |
dhollowa
2013/01/04 01:34:50
string and vector not used.
Cait (Slow)
2013/01/04 22:59:29
Done.
| |
14 #include <vector> | |
15 | |
16 #include "base/callback_forward.h" | |
dhollowa
2013/01/04 01:34:50
A good chunk of these are not required.
Cait (Slow)
2013/01/04 22:59:29
Done.
| |
17 #include "base/file_path.h" | |
18 #include "base/location.h" | |
19 #include "base/memory/ref_counted.h" | |
20 #include "base/sequenced_task_runner_helpers.h" | |
21 #include "base/synchronization/lock.h" | |
22 #include "chrome/browser/api/webdata/web_data_results.h" | |
23 #include "chrome/browser/api/webdata/web_data_service_base.h" | |
24 #include "chrome/browser/api/webdata/web_data_service_consumer.h" | |
25 #include "chrome/browser/search_engines/template_url.h" | |
26 #include "chrome/browser/search_engines/template_url_id.h" | |
27 #include "chrome/browser/webdata/keyword_table.h" | |
28 #include "content/public/browser/browser_thread.h" | |
29 #include "sql/init_status.h" | |
30 | |
31 class MessageLoop; | |
32 class WebDataService; | |
33 class WebDataServiceConsumer; | |
34 | |
35 ////////////////////////////////////////////////////////////////////////////// | |
36 // | |
37 // Webdata requests | |
38 // | |
39 // Every request is processed using a request object. The object contains | |
40 // both the request parameters and the results. | |
41 ////////////////////////////////////////////////////////////////////////////// | |
42 class WebDataRequest { | |
43 public: | |
44 WebDataRequest(WebDataService* service, | |
45 WebDataServiceBase::Handle handle, | |
46 WebDataServiceConsumer* consumer); | |
47 | |
48 virtual ~WebDataRequest(); | |
49 | |
50 WebDataServiceBase::Handle GetHandle() const; | |
51 | |
52 // Retrieves the |consumer_| set in the constructor. If the request was | |
53 // cancelled via the |Cancel()| method then |true| is returned and | |
54 // |*consumer| is set to NULL. The |consumer| parameter may be set to NULL | |
55 // if only the return value is desired. | |
56 bool IsCancelled(WebDataServiceConsumer** consumer) const; | |
dhollowa
2013/01/04 01:34:50
Let's take the opportunity to split out a separate
Cait (Slow)
2013/01/04 22:59:29
Done.
| |
57 | |
58 // This can be invoked from any thread. From this point we assume that | |
59 // our consumer_ reference is invalid. | |
60 void Cancel(); | |
61 | |
62 // Invoked by the service when this request has been completed. | |
63 // This will notify the service in whatever thread was used to create this | |
64 // request. | |
65 void RequestComplete(); | |
66 | |
67 // The result is owned by the request. | |
68 void SetResult(WDTypedResult* r); | |
69 const WDTypedResult* GetResult() const; | |
70 | |
71 private: | |
72 scoped_refptr<WebDataService> service_; | |
dhollowa
2013/01/04 01:34:50
Let's add some doc to these members. Eg.
servic
Cait (Slow)
2013/01/04 22:59:29
Done.
| |
73 MessageLoop* message_loop_; | |
74 WebDataServiceBase::Handle handle_; | |
75 | |
76 // A lock to protect against simultaneous cancellations of the request. | |
77 // Cancellation affects both the |cancelled_| flag and |consumer_|. | |
78 mutable base::Lock cancel_lock_; | |
79 bool cancelled_; | |
80 WebDataServiceConsumer* consumer_; | |
81 | |
82 WDTypedResult* result_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(WebDataRequest); | |
85 }; | |
86 | |
87 class WebDataRequestManager { | |
dhollowa
2013/01/04 01:34:50
The order of the classes in this header is opposit
dhollowa
2013/01/04 01:34:50
Add description of this class, making note that th
Cait (Slow)
2013/01/04 22:59:29
Done.
Cait (Slow)
2013/01/04 22:59:29
Done.
| |
88 public: | |
89 WebDataRequestManager(); | |
90 | |
91 // Cancel any pending request. | |
92 virtual void CancelRequest(WebDataServiceBase::Handle h); | |
93 | |
94 // Invoked by request implementations when a request has been processed. | |
95 virtual void RequestCompleted(WebDataServiceBase::Handle h); | |
96 | |
97 // Register the request as a pending request. | |
98 virtual void RegisterRequest(WebDataRequest* request); | |
99 | |
100 // Return the next request handle. | |
101 virtual int GetNextRequestHandle(); | |
102 | |
103 private: | |
104 // A lock to protect pending requests and next request handle. | |
105 base::Lock pending_lock_; | |
106 | |
107 // Next handle to be used for requests. Incremented for each use. | |
108 WebDataServiceBase::Handle next_request_handle_; | |
109 | |
110 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; | |
111 RequestMap pending_requests_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); | |
114 }; | |
115 | |
116 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_REQUEST_MANAGER_H__ | |
OLD | NEW |