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

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

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again Created 7 years, 9 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/autofill_profile_syncable_service.h" 5 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/webdata/autofill_table.h" 12 #include "chrome/browser/webdata/autofill_table.h"
13 #include "chrome/browser/webdata/web_data_service.h" 13 #include "chrome/browser/webdata/web_data_service.h"
14 #include "chrome/browser/webdata/web_database.h" 14 #include "chrome/browser/webdata/web_database.h"
15 #include "chrome/common/chrome_notification_types.h"
16 #include "components/autofill/browser/autofill_profile.h" 15 #include "components/autofill/browser/autofill_profile.h"
17 #include "components/autofill/browser/form_group.h" 16 #include "components/autofill/browser/form_group.h"
18 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/notification_details.h"
20 #include "content/public/browser/notification_source.h"
21 #include "sync/api/sync_error.h" 18 #include "sync/api/sync_error.h"
22 #include "sync/api/sync_error_factory.h" 19 #include "sync/api/sync_error_factory.h"
23 #include "sync/protocol/sync.pb.h" 20 #include "sync/protocol/sync.pb.h"
24 21
25 using content::BrowserThread; 22 using content::BrowserThread;
26 23
27 namespace { 24 namespace {
28 25
29 std::string LimitData(const std::string& data) { 26 std::string LimitData(const std::string& data) {
30 std::string sanitized_value(data); 27 std::string sanitized_value(data);
31 if (sanitized_value.length() > AutofillTable::kMaxDataLength) 28 if (sanitized_value.length() > AutofillTable::kMaxDataLength)
32 sanitized_value.resize(AutofillTable::kMaxDataLength); 29 sanitized_value.resize(AutofillTable::kMaxDataLength);
33 return sanitized_value; 30 return sanitized_value;
34 } 31 }
35 32
36 } // namespace 33 } // namespace
37 34
38 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 35 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
39 36
40 AutofillProfileSyncableService::AutofillProfileSyncableService( 37 AutofillProfileSyncableService::AutofillProfileSyncableService(
41 WebDataService* web_data_service) 38 WebDataService* web_data_service)
42 : web_data_service_(web_data_service) { 39 : web_data_service_(web_data_service) {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
44 DCHECK(web_data_service_); 41 DCHECK(web_data_service_);
45 notification_registrar_.Add( 42 web_data_service_->AddObserver(this);
46 this,
47 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
48 content::Source<WebDataService>(web_data_service_));
49 } 43 }
50 44
51 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 45 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
52 DCHECK(CalledOnValidThread()); 46 DCHECK(CalledOnValidThread());
47 if (web_data_service_)
48 web_data_service_->RemoveObserver(this);
53 } 49 }
54 50
55 AutofillProfileSyncableService::AutofillProfileSyncableService() 51 AutofillProfileSyncableService::AutofillProfileSyncableService()
56 : web_data_service_(NULL) { 52 : web_data_service_(NULL) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
58 } 54 }
59 55
60 syncer::SyncMergeResult 56 syncer::SyncMergeResult
61 AutofillProfileSyncableService::MergeDataAndStartSyncing( 57 AutofillProfileSyncableService::MergeDataAndStartSyncing(
62 syncer::ModelType type, 58 syncer::ModelType type,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 return sync_error_factory_->CreateAndUploadError( 227 return sync_error_factory_->CreateAndUploadError(
232 FROM_HERE, 228 FROM_HERE,
233 "Failed to update webdata."); 229 "Failed to update webdata.");
234 } 230 }
235 231
236 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); 232 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_);
237 233
238 return syncer::SyncError(); 234 return syncer::SyncError();
239 } 235 }
240 236
241 void AutofillProfileSyncableService::Observe(int type, 237 void AutofillProfileSyncableService::AutofillProfileChanged(
242 const content::NotificationSource& source, 238 const AutofillProfileChange& change) {
243 const content::NotificationDetails& details) {
244 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED);
245 DCHECK_EQ(web_data_service_, content::Source<WebDataService>(source).ptr());
246 // Check if sync is on. If we receive notification prior to the sync being set 239 // Check if sync is on. If we receive notification prior to the sync being set
247 // up we are going to process all when MergeData..() is called. If we receive 240 // up we are going to process all when MergeData..() is called. If we receive
248 // notification after the sync exited, it will be sinced next time Chrome 241 // notification after the sync exited, it will be sinced next time Chrome
249 // starts. 242 // starts.
250 if (!sync_processor_.get()) 243 if (sync_processor_.get())
251 return; 244 ActOnChange(change);
252
253 AutofillProfileChange* change =
254 content::Details<AutofillProfileChange>(details).ptr();
255 ActOnChange(*change);
256 } 245 }
257 246
258 bool AutofillProfileSyncableService::LoadAutofillData( 247 bool AutofillProfileSyncableService::LoadAutofillData(
259 std::vector<AutofillProfile*>* profiles) { 248 std::vector<AutofillProfile*>* profiles) {
260 return GetAutofillTable()->GetAutofillProfiles(profiles); 249 return GetAutofillTable()->GetAutofillProfiles(profiles);
261 } 250 }
262 251
263 bool AutofillProfileSyncableService::SaveChangesToWebData( 252 bool AutofillProfileSyncableService::SaveChangesToWebData(
264 const DataBundle& bundle) { 253 const DataBundle& bundle) {
265 DCHECK(CalledOnValidThread()); 254 DCHECK(CalledOnValidThread());
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 } 535 }
547 536
548 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { 537 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {
549 return web_data_service_->GetDatabase()->GetAutofillTable(); 538 return web_data_service_->GetDatabase()->GetAutofillTable();
550 } 539 }
551 540
552 AutofillProfileSyncableService::DataBundle::DataBundle() {} 541 AutofillProfileSyncableService::DataBundle::DataBundle() {}
553 542
554 AutofillProfileSyncableService::DataBundle::~DataBundle() { 543 AutofillProfileSyncableService::DataBundle::~DataBundle() {
555 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698