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

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

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase 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/autocomplete_syncable_service.h" 5 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/webdata/autofill_table.h" 10 #include "chrome/browser/webdata/autofill_table.h"
11 #include "chrome/browser/webdata/autofill_web_data_service.h" 11 #include "chrome/browser/webdata/autofill_web_data_service.h"
12 #include "chrome/browser/webdata/web_database.h" 12 #include "chrome/browser/webdata/web_database.h"
13 #include "chrome/common/chrome_notification_types.h"
14 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_service.h"
16 #include "net/base/escape.h" 14 #include "net/base/escape.h"
17 #include "sync/api/sync_error.h" 15 #include "sync/api/sync_error.h"
18 #include "sync/api/sync_error_factory.h" 16 #include "sync/api/sync_error_factory.h"
19 #include "sync/protocol/autofill_specifics.pb.h" 17 #include "sync/protocol/autofill_specifics.pb.h"
20 #include "sync/protocol/sync.pb.h" 18 #include "sync/protocol/sync.pb.h"
21 19
22 using content::BrowserThread; 20 using content::BrowserThread;
23 21
24 namespace { 22 namespace {
25 23
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // with something else. 81 // with something else.
84 static int user_data_key = 0; 82 static int user_data_key = 0;
85 return reinterpret_cast<void*>(&user_data_key); 83 return reinterpret_cast<void*>(&user_data_key);
86 } 84 }
87 85
88 } // namespace 86 } // namespace
89 87
90 AutocompleteSyncableService::AutocompleteSyncableService( 88 AutocompleteSyncableService::AutocompleteSyncableService(
91 AutofillWebDataService* web_data_service) 89 AutofillWebDataService* web_data_service)
92 : web_data_service_(web_data_service), 90 : web_data_service_(web_data_service),
91 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_observer_(this)),
93 cull_expired_entries_(false) { 92 cull_expired_entries_(false) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
95 DCHECK(web_data_service_); 94 DCHECK(web_data_service_);
96 notification_registrar_.Add( 95
97 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 96 scoped_observer_.Add(web_data_service_);
98 content::Source<AutofillWebDataService>(web_data_service));
99 } 97 }
100 98
101 AutocompleteSyncableService::~AutocompleteSyncableService() { 99 AutocompleteSyncableService::~AutocompleteSyncableService() {
102 DCHECK(CalledOnValidThread()); 100 DCHECK(CalledOnValidThread());
103 } 101 }
104 102
105 // static 103 // static
106 void AutocompleteSyncableService::CreateForWebDataService( 104 void AutocompleteSyncableService::CreateForWebDataService(
107 AutofillWebDataService* web_data_service) { 105 AutofillWebDataService* web_data_service) {
108 web_data_service->GetDBUserData()->SetUserData( 106 web_data_service->GetDBUserData()->SetUserData(
109 UserDataKey(), new AutocompleteSyncableService(web_data_service)); 107 UserDataKey(), new AutocompleteSyncableService(web_data_service));
110 } 108 }
111 109
112 // static 110 // static
113 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService( 111 AutocompleteSyncableService* AutocompleteSyncableService::FromWebDataService(
114 AutofillWebDataService* web_data_service) { 112 AutofillWebDataService* web_data_service) {
115 return static_cast<AutocompleteSyncableService*>( 113 return static_cast<AutocompleteSyncableService*>(
116 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); 114 web_data_service->GetDBUserData()->GetUserData(UserDataKey()));
117 } 115 }
118 116
119 AutocompleteSyncableService::AutocompleteSyncableService() 117 AutocompleteSyncableService::AutocompleteSyncableService()
120 : web_data_service_(NULL), 118 : web_data_service_(NULL),
119 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_observer_(this)),
121 cull_expired_entries_(false) { 120 cull_expired_entries_(false) {
122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
123 } 122 }
124 123
125 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( 124 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing(
126 syncer::ModelType type, 125 syncer::ModelType type,
127 const syncer::SyncDataList& initial_sync_data, 126 const syncer::SyncDataList& initial_sync_data,
128 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 127 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
129 scoped_ptr<syncer::SyncErrorFactory> error_handler) { 128 scoped_ptr<syncer::SyncErrorFactory> error_handler) {
130 DCHECK(CalledOnValidThread()); 129 DCHECK(CalledOnValidThread());
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 289
291 if (cull_expired_entries_) { 290 if (cull_expired_entries_) {
292 // This will schedule a deletion operation on the DB thread, which will 291 // This will schedule a deletion operation on the DB thread, which will
293 // trigger a notification to propagate the deletion to Sync. 292 // trigger a notification to propagate the deletion to Sync.
294 web_data_service_->RemoveExpiredFormElements(); 293 web_data_service_->RemoveExpiredFormElements();
295 } 294 }
296 295
297 return list_processing_error; 296 return list_processing_error;
298 } 297 }
299 298
300 void AutocompleteSyncableService::Observe(int type, 299 void AutocompleteSyncableService::AutofillEntriesChanged(
301 const content::NotificationSource& source, 300 const AutofillChangeList& changes) {
302 const content::NotificationDetails& details) {
303 DCHECK_EQ(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, type);
304
305 // Check if sync is on. If we receive notification prior to the sync being set 301 // Check if sync is on. If we receive notification prior to the sync being set
306 // up we are going to process all when MergeData..() is called. If we receive 302 // up we are going to process all when MergeData..() is called. If we receive
307 // notification after the sync exited, it will be sinced next time Chrome 303 // notification after the sync exited, it will be sinced next time Chrome
308 // starts. 304 // starts.
309 if (!sync_processor_.get()) 305 if (sync_processor_.get())
310 return; 306 ActOnChanges(changes);
311 AutofillWebDataService* web_data_service =
312 content::Source<AutofillWebDataService>(source).ptr();
313
314 DCHECK_EQ(web_data_service_, web_data_service);
315
316 AutofillChangeList* changes =
317 content::Details<AutofillChangeList>(details).ptr();
318 ActOnChanges(*changes);
319 } 307 }
320 308
321 bool AutocompleteSyncableService::LoadAutofillData( 309 bool AutocompleteSyncableService::LoadAutofillData(
322 std::vector<AutofillEntry>* entries) const { 310 std::vector<AutofillEntry>* entries) const {
323 return AutofillTable::FromWebDatabase( 311 return AutofillTable::FromWebDatabase(
324 web_data_service_->GetDatabase())->GetAllAutofillEntries(entries); 312 web_data_service_->GetDatabase())->GetAllAutofillEntries(entries);
325 } 313 }
326 314
327 bool AutocompleteSyncableService::SaveChangesToWebData( 315 bool AutocompleteSyncableService::SaveChangesToWebData(
328 const std::vector<AutofillEntry>& new_entries) { 316 const std::vector<AutofillEntry>& new_entries) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 UTF16ToUTF8(entry.key().value()))); 466 UTF16ToUTF8(entry.key().value())));
479 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); 467 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics);
480 } 468 }
481 469
482 // static 470 // static
483 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, 471 std::string AutocompleteSyncableService::KeyToTag(const std::string& name,
484 const std::string& value) { 472 const std::string& value) {
485 std::string ns(kAutofillEntryNamespaceTag); 473 std::string ns(kAutofillEntryNamespaceTag);
486 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); 474 return ns + net::EscapePath(name) + "|" + net::EscapePath(value);
487 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autocomplete_syncable_service.h ('k') | chrome/browser/webdata/autofill_change.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698