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

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

Issue 11761016: Separate WebDataRequest functionality from WebDataService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_SERVICE_H__ 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
11 11
12 #include <map> 12 #include <map>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/callback_forward.h" 16 #include "base/callback_forward.h"
17 #include "base/file_path.h" 17 #include "base/file_path.h"
18 #include "base/location.h" 18 #include "base/location.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/sequenced_task_runner_helpers.h" 20 #include "base/sequenced_task_runner_helpers.h"
21 #include "base/synchronization/lock.h" 21 #include "base/synchronization/lock.h"
22 #include "chrome/browser/api/webdata/autofill_web_data_service.h" 22 #include "chrome/browser/api/webdata/autofill_web_data_service.h"
23 #include "chrome/browser/api/webdata/web_data_results.h" 23 #include "chrome/browser/api/webdata/web_data_results.h"
24 #include "chrome/browser/api/webdata/web_data_service_base.h" 24 #include "chrome/browser/api/webdata/web_data_service_base.h"
25 #include "chrome/browser/api/webdata/web_data_service_consumer.h" 25 #include "chrome/browser/api/webdata/web_data_service_consumer.h"
26 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" 26 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h"
27 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/browser/search_engines/template_url_id.h" 28 #include "chrome/browser/search_engines/template_url_id.h"
29 #include "chrome/browser/webdata/keyword_table.h" 29 #include "chrome/browser/webdata/keyword_table.h"
30 #include "chrome/browser/webdata/web_data_request_manager.h"
30 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
31 #include "sql/init_status.h" 32 #include "sql/init_status.h"
32 33
33 class AutocompleteSyncableService; 34 class AutocompleteSyncableService;
34 class AutofillChange; 35 class AutofillChange;
35 class AutofillProfileSyncableService; 36 class AutofillProfileSyncableService;
36 struct DefaultWebIntentService; 37 struct DefaultWebIntentService;
37 class GURL; 38 class GURL;
38 #if defined(OS_WIN) 39 #if defined(OS_WIN)
39 struct IE7PasswordInfo; 40 struct IE7PasswordInfo;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 int builtin_keyword_version; 94 int builtin_keyword_version;
94 }; 95 };
95 96
96 class WebDataServiceConsumer; 97 class WebDataServiceConsumer;
97 98
98 class WebDataService 99 class WebDataService
99 : public WebDataServiceBase, 100 : public WebDataServiceBase,
100 public AutofillWebData, 101 public AutofillWebData,
101 public RefcountedProfileKeyedService { 102 public RefcountedProfileKeyedService {
102 public: 103 public:
103 //////////////////////////////////////////////////////////////////////////////
104 //
105 // Internal requests
106 //
107 // Every request is processed using a request object. The object contains
108 // both the request parameters and the results.
109 //////////////////////////////////////////////////////////////////////////////
110 class WebDataRequest {
111 public:
112 WebDataRequest(WebDataService* service,
113 Handle handle,
114 WebDataServiceConsumer* consumer);
115
116 virtual ~WebDataRequest();
117
118 Handle GetHandle() const;
119
120 // Retrieves the |consumer_| set in the constructor. If the request was
121 // cancelled via the |Cancel()| method then |true| is returned and
122 // |*consumer| is set to NULL. The |consumer| parameter may be set to NULL
123 // if only the return value is desired.
124 bool IsCancelled(WebDataServiceConsumer** consumer) const;
125
126 // This can be invoked from any thread. From this point we assume that
127 // our consumer_ reference is invalid.
128 void Cancel();
129
130 // Invoked by the service when this request has been completed.
131 // This will notify the service in whatever thread was used to create this
132 // request.
133 void RequestComplete();
134
135 // The result is owned by the request.
136 void SetResult(WDTypedResult* r);
137 const WDTypedResult* GetResult() const;
138
139 private:
140 scoped_refptr<WebDataService> service_;
141 MessageLoop* message_loop_;
142 Handle handle_;
143
144 // A lock to protect against simultaneous cancellations of the request.
145 // Cancellation affects both the |cancelled_| flag and |consumer_|.
146 mutable base::Lock cancel_lock_;
147 bool cancelled_;
148 WebDataServiceConsumer* consumer_;
149
150 WDTypedResult* result_;
151
152 DISALLOW_COPY_AND_ASSIGN(WebDataRequest);
153 };
154
155 // 104 //
156 // Internally we use instances of the following template to represent 105 // Internally we use instances of the following template to represent
157 // requests. 106 // requests.
158 // 107 //
159 template <class T> 108 template <class T>
160 class GenericRequest : public WebDataRequest { 109 class GenericRequest : public WebDataRequest {
dhollowa 2013/01/04 01:34:50 These templates should be moved into web_data_requ
Cait (Slow) 2013/01/04 22:59:29 Done.
161 public: 110 public:
162 GenericRequest(WebDataService* service, 111 GenericRequest(WebDataService* service,
163 Handle handle, 112 Handle handle,
164 WebDataServiceConsumer* consumer, 113 WebDataServiceConsumer* consumer,
165 const T& arg) 114 const T& arg)
166 : WebDataRequest(service, handle, consumer), 115 : WebDataRequest(service, handle, consumer),
167 arg_(arg) { 116 arg_(arg) {
168 } 117 }
169 118
170 virtual ~GenericRequest() { 119 virtual ~GenericRequest() {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 friend class WebDataRequest; 369 friend class WebDataRequest;
421 370
422 virtual ~WebDataService(); 371 virtual ~WebDataService();
423 372
424 // This is invoked by the unit test; path is the path of the Web Data file. 373 // This is invoked by the unit test; path is the path of the Web Data file.
425 bool InitWithPath(const FilePath& path); 374 bool InitWithPath(const FilePath& path);
426 375
427 // Invoked by request implementations when a request has been processed. 376 // Invoked by request implementations when a request has been processed.
428 void RequestCompleted(Handle h); 377 void RequestCompleted(Handle h);
429 378
430 // Register the request as a pending request.
431 void RegisterRequest(WebDataRequest* request);
432
433 ////////////////////////////////////////////////////////////////////////////// 379 //////////////////////////////////////////////////////////////////////////////
434 // 380 //
435 // The following methods are only invoked in the web data service thread. 381 // The following methods are only invoked in the web data service thread.
436 // 382 //
437 ////////////////////////////////////////////////////////////////////////////// 383 //////////////////////////////////////////////////////////////////////////////
438 private: 384 private:
439 friend struct content::BrowserThread::DeleteOnThread< 385 friend struct content::BrowserThread::DeleteOnThread<
440 content::BrowserThread::UI>; 386 content::BrowserThread::UI>;
441 friend class base::DeleteHelper<WebDataService>; 387 friend class base::DeleteHelper<WebDataService>;
442 388
(...skipping 21 matching lines...) Expand all
464 // Commit the current transaction and creates a new one. 410 // Commit the current transaction and creates a new one.
465 void Commit(); 411 void Commit();
466 412
467 // Schedule a task on our worker thread. 413 // Schedule a task on our worker thread.
468 void ScheduleTask(const tracked_objects::Location& from_here, 414 void ScheduleTask(const tracked_objects::Location& from_here,
469 const base::Closure& task); 415 const base::Closure& task);
470 416
471 // Schedule a commit if one is not already pending. 417 // Schedule a commit if one is not already pending.
472 void ScheduleCommit(); 418 void ScheduleCommit();
473 419
474 // Return the next request handle.
475 int GetNextRequestHandle();
476
477 ////////////////////////////////////////////////////////////////////////////// 420 //////////////////////////////////////////////////////////////////////////////
478 // 421 //
479 // Keywords. 422 // Keywords.
480 // 423 //
481 ////////////////////////////////////////////////////////////////////////////// 424 //////////////////////////////////////////////////////////////////////////////
482 void AddKeywordImpl(GenericRequest<TemplateURLData>* request); 425 void AddKeywordImpl(GenericRequest<TemplateURLData>* request);
483 void RemoveKeywordImpl(GenericRequest<TemplateURLID>* request); 426 void RemoveKeywordImpl(GenericRequest<TemplateURLID>* request);
484 void UpdateKeywordImpl(GenericRequest<TemplateURLData>* request); 427 void UpdateKeywordImpl(GenericRequest<TemplateURLData>* request);
485 void GetKeywordsImpl(WebDataRequest* request); 428 void GetKeywordsImpl(WebDataRequest* request);
486 void SetDefaultSearchProviderImpl(GenericRequest<TemplateURLID>* r); 429 void SetDefaultSearchProviderImpl(GenericRequest<TemplateURLID>* r);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 // True once initialization has started. 511 // True once initialization has started.
569 bool is_running_; 512 bool is_running_;
570 513
571 // The path with which to initialize the database. 514 // The path with which to initialize the database.
572 FilePath path_; 515 FilePath path_;
573 516
574 // Our database. We own the |db_|, but don't use a |scoped_ptr| because the 517 // Our database. We own the |db_|, but don't use a |scoped_ptr| because the
575 // |db_| lifetime must be managed on the database thread. 518 // |db_| lifetime must be managed on the database thread.
576 WebDatabase* db_; 519 WebDatabase* db_;
577 520
521 // Keeps track of all pending requests made to the db.
522 scoped_ptr<WebDataRequestManager> wdr_mgr_;
dhollowa 2013/01/04 01:34:50 nit: no abbreviations. How about |request_manager
Cait (Slow) 2013/01/04 22:59:29 Done.
523
578 // Syncable services for the database data. We own the services, but don't 524 // Syncable services for the database data. We own the services, but don't
579 // use |scoped_ptr|s because the lifetimes must be managed on the database 525 // use |scoped_ptr|s because the lifetimes must be managed on the database
580 // thread. 526 // thread.
581 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 527 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
582 // all the database data should migrate to this API over time. 528 // all the database data should migrate to this API over time.
583 AutocompleteSyncableService* autocomplete_syncable_service_; 529 AutocompleteSyncableService* autocomplete_syncable_service_;
584 AutofillProfileSyncableService* autofill_profile_syncable_service_; 530 AutofillProfileSyncableService* autofill_profile_syncable_service_;
585 531
586 // Whether the database failed to initialize. We use this to avoid 532 // Whether the database failed to initialize. We use this to avoid
587 // continually trying to reinit. 533 // continually trying to reinit.
588 bool failed_init_; 534 bool failed_init_;
589 535
590 // Whether we should commit the database. 536 // Whether we should commit the database.
591 bool should_commit_; 537 bool should_commit_;
592 538
593 // A lock to protect pending requests and next request handle.
594 base::Lock pending_lock_;
595
596 // Next handle to be used for requests. Incremented for each use.
597 Handle next_request_handle_;
598
599 typedef std::map<Handle, WebDataRequest*> RequestMap;
600 RequestMap pending_requests_;
601
602 // MessageLoop the WebDataService is created on. 539 // MessageLoop the WebDataService is created on.
603 MessageLoop* main_loop_; 540 MessageLoop* main_loop_;
604 541
605 DISALLOW_COPY_AND_ASSIGN(WebDataService); 542 DISALLOW_COPY_AND_ASSIGN(WebDataService);
606 }; 543 };
607 544
608 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ 545 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698