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

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

Issue 10006037: Moved WebDataService to ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reverted one unneeded change Created 8 years, 8 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 #include "chrome/browser/webdata/web_data_service.h" 5 #include "chrome/browser/webdata/web_data_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 21 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
22 #include "chrome/browser/webdata/autofill_table.h" 22 #include "chrome/browser/webdata/autofill_table.h"
23 #include "chrome/browser/webdata/keyword_table.h" 23 #include "chrome/browser/webdata/keyword_table.h"
24 #include "chrome/browser/webdata/logins_table.h" 24 #include "chrome/browser/webdata/logins_table.h"
25 #include "chrome/browser/webdata/token_service_table.h" 25 #include "chrome/browser/webdata/token_service_table.h"
26 #include "chrome/browser/webdata/web_apps_table.h" 26 #include "chrome/browser/webdata/web_apps_table.h"
27 #include "chrome/browser/webdata/web_database.h" 27 #include "chrome/browser/webdata/web_database.h"
28 #include "chrome/browser/webdata/web_intents_table.h" 28 #include "chrome/browser/webdata/web_intents_table.h"
29 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
31 #ifdef DEBUG
32 #include "content/public/browser/browser_thread.h"
33 #endif
31 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
34 #include "grit/chromium_strings.h" 37 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
36 #include "third_party/skia/include/core/SkBitmap.h" 39 #include "third_party/skia/include/core/SkBitmap.h"
37 #include "webkit/forms/form_field.h" 40 #include "webkit/forms/form_field.h"
38 #include "webkit/forms/password_form.h" 41 #include "webkit/forms/password_form.h"
39 42
40 //////////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////////
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 WDKeywordsResult::WDKeywordsResult() 76 WDKeywordsResult::WDKeywordsResult()
74 : default_search_provider_id(0), 77 : default_search_provider_id(0),
75 builtin_keyword_version(0), 78 builtin_keyword_version(0),
76 backup_valid(false), 79 backup_valid(false),
77 did_default_search_provider_change(false) { 80 did_default_search_provider_change(false) {
78 } 81 }
79 82
80 WDKeywordsResult::~WDKeywordsResult() {} 83 WDKeywordsResult::~WDKeywordsResult() {}
81 84
82 WebDataService::WebDataService() 85 WebDataService::WebDataService()
83 : is_running_(false), 86 : RefcountedProfileKeyedService(BrowserThread::UI),
84 db_(NULL), 87 is_running_(false),
85 autocomplete_syncable_service_(NULL), 88 db_(NULL),
86 autofill_profile_syncable_service_(NULL), 89 autocomplete_syncable_service_(NULL),
87 failed_init_(false), 90 autofill_profile_syncable_service_(NULL),
88 should_commit_(false), 91 failed_init_(false),
89 next_request_handle_(1), 92 should_commit_(false),
90 main_loop_(MessageLoop::current()) { 93 next_request_handle_(1),
94 main_loop_(MessageLoop::current()) {
95 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
91 } 96 }
92 97
93 // static 98 // static
94 void WebDataService::NotifyOfMultipleAutofillChanges( 99 void WebDataService::NotifyOfMultipleAutofillChanges(
95 WebDataService* web_data_service) { 100 WebDataService* web_data_service) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
97 102
98 if (!web_data_service) 103 if (!web_data_service)
99 return; 104 return;
100 105
101 BrowserThread::PostTask( 106 BrowserThread::PostTask(
102 BrowserThread::UI, FROM_HERE, 107 BrowserThread::UI, FROM_HERE,
103 Bind(&NotifyOfMultipleAutofillChangesTask, 108 Bind(&NotifyOfMultipleAutofillChangesTask,
104 make_scoped_refptr(web_data_service))); 109 make_scoped_refptr(web_data_service)));
105 } 110 }
106 111
112 void WebDataService::ShutdownOnUIThread() {
113 ScheduleTask(FROM_HERE,
114 Bind(&WebDataService::ShutdownSyncableServices, this));
115 UnloadDatabase();
116 }
117
107 bool WebDataService::Init(const FilePath& profile_path) { 118 bool WebDataService::Init(const FilePath& profile_path) {
108 FilePath path = profile_path; 119 FilePath path = profile_path;
109 path = path.Append(chrome::kWebDataFilename); 120 path = path.Append(chrome::kWebDataFilename);
110 return InitWithPath(path); 121 return InitWithPath(path);
111 } 122 }
112 123
113 void WebDataService::Shutdown() {
114 ScheduleTask(FROM_HERE,
115 Bind(&WebDataService::ShutdownSyncableServices, this));
116 UnloadDatabase();
117 }
118
119 bool WebDataService::IsRunning() const { 124 bool WebDataService::IsRunning() const {
120 return is_running_; 125 return is_running_;
121 } 126 }
122 127
123 void WebDataService::UnloadDatabase() { 128 void WebDataService::UnloadDatabase() {
124 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); 129 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this));
125 } 130 }
126 131
127 void WebDataService::CancelRequest(Handle h) { 132 void WebDataService::CancelRequest(Handle h) {
128 base::AutoLock l(pending_lock_); 133 base::AutoLock l(pending_lock_);
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 } 649 }
645 650
646 bool WebDataService::InitWithPath(const FilePath& path) { 651 bool WebDataService::InitWithPath(const FilePath& path) {
647 path_ = path; 652 path_ = path;
648 is_running_ = true; 653 is_running_ = true;
649 654
650 // TODO(isherman): For now, to avoid a data race on shutdown 655 // TODO(isherman): For now, to avoid a data race on shutdown
651 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to 656 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to
652 // cache the application locale before we try to access it on the DB thread. 657 // cache the application locale before we try to access it on the DB thread.
653 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed. 658 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed.
654 AutofillCountry::ApplicationLocale(); 659 // Do not do it if the thread is not UI (can happen only in some tests).
660 if (BrowserThread::CurrentlyOn(BrowserThread::UI))
661 AutofillCountry::ApplicationLocale();
655 662
656 ScheduleTask(FROM_HERE, 663 ScheduleTask(FROM_HERE,
657 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); 664 Bind(&WebDataService::InitializeDatabaseIfNecessary, this));
658 ScheduleTask(FROM_HERE, 665 ScheduleTask(FROM_HERE,
659 Bind(&WebDataService::InitializeSyncableServices, this)); 666 Bind(&WebDataService::InitializeSyncableServices, this));
660 return true; 667 return true;
661 } 668 }
662 669
663 void WebDataService::RequestCompleted(Handle h) { 670 void WebDataService::RequestCompleted(Handle h) {
664 pending_lock_.Acquire(); 671 pending_lock_.Acquire();
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1659 }
1653 1660
1654 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { 1661 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const {
1655 return result_; 1662 return result_;
1656 } 1663 }
1657 1664
1658 void WebDataService::WebDataRequest::RequestComplete() { 1665 void WebDataService::WebDataRequest::RequestComplete() {
1659 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, 1666 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted,
1660 service_.get(), handle_)); 1667 service_.get(), handle_));
1661 } 1668 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698