OLD | NEW |
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 Loading... |
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 | 41 |
39 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
40 // | 43 // |
(...skipping 30 matching lines...) Expand all Loading... |
71 WDKeywordsResult::WDKeywordsResult() | 74 WDKeywordsResult::WDKeywordsResult() |
72 : default_search_provider_id(0), | 75 : default_search_provider_id(0), |
73 builtin_keyword_version(0), | 76 builtin_keyword_version(0), |
74 backup_valid(false), | 77 backup_valid(false), |
75 did_default_search_provider_change(false) { | 78 did_default_search_provider_change(false) { |
76 } | 79 } |
77 | 80 |
78 WDKeywordsResult::~WDKeywordsResult() {} | 81 WDKeywordsResult::~WDKeywordsResult() {} |
79 | 82 |
80 WebDataService::WebDataService() | 83 WebDataService::WebDataService() |
81 : is_running_(false), | 84 : RefcountedProfileKeyedService(BrowserThread::UI), |
82 db_(NULL), | 85 is_running_(false), |
83 autocomplete_syncable_service_(NULL), | 86 db_(NULL), |
84 autofill_profile_syncable_service_(NULL), | 87 autocomplete_syncable_service_(NULL), |
85 failed_init_(false), | 88 autofill_profile_syncable_service_(NULL), |
86 should_commit_(false), | 89 failed_init_(false), |
87 next_request_handle_(1), | 90 should_commit_(false), |
88 main_loop_(MessageLoop::current()) { | 91 next_request_handle_(1), |
| 92 main_loop_(MessageLoop::current()) { |
| 93 // WebDataService requires DB thread if instantiated. |
| 94 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
| 95 // if you do not want to instantiate WebDataService in your test. |
| 96 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
89 } | 97 } |
90 | 98 |
91 // static | 99 // static |
92 void WebDataService::NotifyOfMultipleAutofillChanges( | 100 void WebDataService::NotifyOfMultipleAutofillChanges( |
93 WebDataService* web_data_service) { | 101 WebDataService* web_data_service) { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
95 | 103 |
96 if (!web_data_service) | 104 if (!web_data_service) |
97 return; | 105 return; |
98 | 106 |
99 BrowserThread::PostTask( | 107 BrowserThread::PostTask( |
100 BrowserThread::UI, FROM_HERE, | 108 BrowserThread::UI, FROM_HERE, |
101 Bind(&NotifyOfMultipleAutofillChangesTask, | 109 Bind(&NotifyOfMultipleAutofillChangesTask, |
102 make_scoped_refptr(web_data_service))); | 110 make_scoped_refptr(web_data_service))); |
103 } | 111 } |
104 | 112 |
| 113 void WebDataService::ShutdownOnUIThread() { |
| 114 ScheduleTask(FROM_HERE, |
| 115 Bind(&WebDataService::ShutdownSyncableServices, this)); |
| 116 UnloadDatabase(); |
| 117 } |
| 118 |
105 bool WebDataService::Init(const FilePath& profile_path) { | 119 bool WebDataService::Init(const FilePath& profile_path) { |
106 FilePath path = profile_path; | 120 FilePath path = profile_path; |
107 path = path.Append(chrome::kWebDataFilename); | 121 path = path.Append(chrome::kWebDataFilename); |
108 return InitWithPath(path); | 122 return InitWithPath(path); |
109 } | 123 } |
110 | 124 |
111 void WebDataService::Shutdown() { | |
112 ScheduleTask(FROM_HERE, | |
113 Bind(&WebDataService::ShutdownSyncableServices, this)); | |
114 UnloadDatabase(); | |
115 } | |
116 | |
117 bool WebDataService::IsRunning() const { | 125 bool WebDataService::IsRunning() const { |
118 return is_running_; | 126 return is_running_; |
119 } | 127 } |
120 | 128 |
121 void WebDataService::UnloadDatabase() { | 129 void WebDataService::UnloadDatabase() { |
122 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); | 130 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); |
123 } | 131 } |
124 | 132 |
125 void WebDataService::CancelRequest(Handle h) { | 133 void WebDataService::CancelRequest(Handle h) { |
126 base::AutoLock l(pending_lock_); | 134 base::AutoLock l(pending_lock_); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 delete_end); | 555 delete_end); |
548 RegisterRequest(request); | 556 RegisterRequest(request); |
549 ScheduleTask(FROM_HERE, Bind( | 557 ScheduleTask(FROM_HERE, Bind( |
550 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, | 558 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
551 this, request)); | 559 this, request)); |
552 } | 560 } |
553 | 561 |
554 WebDataService::~WebDataService() { | 562 WebDataService::~WebDataService() { |
555 if (is_running_ && db_) { | 563 if (is_running_ && db_) { |
556 DLOG_ASSERT("WebDataService dtor called without Shutdown"); | 564 DLOG_ASSERT("WebDataService dtor called without Shutdown"); |
| 565 NOTREACHED(); |
557 } | 566 } |
558 } | 567 } |
559 | 568 |
560 bool WebDataService::InitWithPath(const FilePath& path) { | 569 bool WebDataService::InitWithPath(const FilePath& path) { |
561 path_ = path; | 570 path_ = path; |
562 is_running_ = true; | 571 is_running_ = true; |
563 | 572 |
564 // TODO(isherman): For now, to avoid a data race on shutdown | 573 // TODO(isherman): For now, to avoid a data race on shutdown |
565 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to | 574 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to |
566 // cache the application locale before we try to access it on the DB thread. | 575 // cache the application locale before we try to access it on the DB thread. |
567 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed. | 576 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed. |
568 AutofillCountry::ApplicationLocale(); | 577 // Do not do it if the thread is not UI (can happen only in some tests). |
| 578 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) |
| 579 AutofillCountry::ApplicationLocale(); |
569 | 580 |
570 ScheduleTask(FROM_HERE, | 581 ScheduleTask(FROM_HERE, |
571 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); | 582 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); |
572 ScheduleTask(FROM_HERE, | 583 ScheduleTask(FROM_HERE, |
573 Bind(&WebDataService::InitializeSyncableServices, this)); | 584 Bind(&WebDataService::InitializeSyncableServices, this)); |
574 return true; | 585 return true; |
575 } | 586 } |
576 | 587 |
577 void WebDataService::RequestCompleted(Handle h) { | 588 void WebDataService::RequestCompleted(Handle h) { |
578 pending_lock_.Acquire(); | 589 pending_lock_.Acquire(); |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 } | 1490 } |
1480 | 1491 |
1481 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { | 1492 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { |
1482 return result_; | 1493 return result_; |
1483 } | 1494 } |
1484 | 1495 |
1485 void WebDataService::WebDataRequest::RequestComplete() { | 1496 void WebDataService::WebDataRequest::RequestComplete() { |
1486 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, | 1497 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, |
1487 service_.get(), handle_)); | 1498 service_.get(), handle_)); |
1488 } | 1499 } |
OLD | NEW |