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

Side by Side Diff: components/webdata/common/web_data_request_manager.h

Issue 2087583002: Remove calls to MessageLoop::current() in components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test error Created 4 years, 5 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
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 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 #include <memory>
14 14
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/single_thread_task_runner.h"
17 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
18 #include "components/webdata/common/web_data_results.h" 19 #include "components/webdata/common/web_data_results.h"
19 #include "components/webdata/common/web_data_service_base.h" 20 #include "components/webdata/common/web_data_service_base.h"
20 #include "components/webdata/common/web_data_service_consumer.h" 21 #include "components/webdata/common/web_data_service_consumer.h"
21 #include "components/webdata/common/web_database_service.h" 22 #include "components/webdata/common/web_database_service.h"
22 23
23 class WebDataServiceConsumer; 24 class WebDataServiceConsumer;
24 class WebDataRequestManager; 25 class WebDataRequestManager;
25 26
26 namespace base {
27 class MessageLoop;
28 }
29
30 ////////////////////////////////////////////////////////////////////////////// 27 //////////////////////////////////////////////////////////////////////////////
31 // 28 //
32 // Webdata requests 29 // Webdata requests
33 // 30 //
34 // Every request is processed using a request object. The object contains 31 // Every request is processed using a request object. The object contains
35 // both the request parameters and the results. 32 // both the request parameters and the results.
36 ////////////////////////////////////////////////////////////////////////////// 33 //////////////////////////////////////////////////////////////////////////////
37 class WebDataRequest { 34 class WebDataRequest {
38 public: 35 public:
39 WebDataRequest(WebDataServiceConsumer* consumer, 36 WebDataRequest(WebDataServiceConsumer* consumer,
40 WebDataRequestManager* manager); 37 WebDataRequestManager* manager);
41 38
42 virtual ~WebDataRequest(); 39 virtual ~WebDataRequest();
43 40
44 WebDataServiceBase::Handle GetHandle() const; 41 WebDataServiceBase::Handle GetHandle() const;
45 42
46 // Retrieves the |consumer_| set in the constructor. 43 // Retrieves the |consumer_| set in the constructor.
47 WebDataServiceConsumer* GetConsumer() const; 44 WebDataServiceConsumer* GetConsumer() const;
48 45
49 // Retrieves the original message loop the of the request. 46 // Retrieves the original task runner of the request.
50 base::MessageLoop* GetMessageLoop() const; 47 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const;
51 48
52 // Returns |true| if the request was cancelled via the |Cancel()| method. 49 // Returns |true| if the request was cancelled via the |Cancel()| method.
53 bool IsCancelled() const; 50 bool IsCancelled() const;
54 51
55 // This can be invoked from any thread. From this point we assume that 52 // This can be invoked from any thread. From this point we assume that
56 // our consumer_ reference is invalid. 53 // our consumer_ reference is invalid.
57 void Cancel(); 54 void Cancel();
58 55
59 // Invoked when the request has been completed. 56 // Invoked when the request has been completed.
60 void OnComplete(); 57 void OnComplete();
61 58
62 // The result is owned by the request. 59 // The result is owned by the request.
63 void SetResult(std::unique_ptr<WDTypedResult> r); 60 void SetResult(std::unique_ptr<WDTypedResult> r);
64 61
65 // Transfers ownership pof result to caller. Should only be called once per 62 // Transfers ownership pof result to caller. Should only be called once per
66 // result. 63 // result.
67 std::unique_ptr<WDTypedResult> GetResult(); 64 std::unique_ptr<WDTypedResult> GetResult();
68 65
69 private: 66 private:
70 // Used to notify manager if request is cancelled. Uses a raw ptr instead of 67 // Used to notify manager if request is cancelled. Uses a raw ptr instead of
71 // a ref_ptr so that it can be set to NULL when a request is cancelled. 68 // a ref_ptr so that it can be set to NULL when a request is cancelled.
72 WebDataRequestManager* manager_; 69 WebDataRequestManager* manager_;
73 70
74 // Tracks loop that the request originated on. 71 // Tracks task runner that the request originated on.
75 base::MessageLoop* message_loop_; 72 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
76 73
77 // Identifier for this request. 74 // Identifier for this request.
78 WebDataServiceBase::Handle handle_; 75 WebDataServiceBase::Handle handle_;
79 76
80 // A lock to protect against simultaneous cancellations of the request. 77 // A lock to protect against simultaneous cancellations of the request.
81 // Cancellation affects both the |cancelled_| flag and |consumer_|. 78 // Cancellation affects both the |cancelled_| flag and |consumer_|.
82 mutable base::Lock cancel_lock_; 79 mutable base::Lock cancel_lock_;
83 bool cancelled_; 80 bool cancelled_;
84 81
85 // The originator of the service request. 82 // The originator of the service request.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Next handle to be used for requests. Incremented for each use. 127 // Next handle to be used for requests. Incremented for each use.
131 WebDataServiceBase::Handle next_request_handle_; 128 WebDataServiceBase::Handle next_request_handle_;
132 129
133 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap; 130 typedef std::map<WebDataServiceBase::Handle, WebDataRequest*> RequestMap;
134 RequestMap pending_requests_; 131 RequestMap pending_requests_;
135 132
136 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager); 133 DISALLOW_COPY_AND_ASSIGN(WebDataRequestManager);
137 }; 134 };
138 135
139 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__ 136 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_REQUEST_MANAGER_H__
OLDNEW
« no previous file with comments | « components/variations/variations_http_header_provider.cc ('k') | components/webdata/common/web_data_request_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698