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

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 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/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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/webdata/autofill_table.h" 11 #include "chrome/browser/webdata/autofill_table.h"
12 #include "chrome/browser/webdata/web_data_service.h" 12 #include "chrome/browser/webdata/web_data_service.h"
13 #include "chrome/browser/webdata/web_database.h" 13 #include "chrome/browser/webdata/web_database.h"
14 #include "chrome/common/chrome_notification_types.h"
15 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
16 #include "content/public/browser/notification_service.h"
17 #include "net/base/escape.h" 15 #include "net/base/escape.h"
18 #include "sync/api/sync_error.h" 16 #include "sync/api/sync_error.h"
19 #include "sync/api/sync_error_factory.h" 17 #include "sync/api/sync_error_factory.h"
20 #include "sync/protocol/autofill_specifics.pb.h" 18 #include "sync/protocol/autofill_specifics.pb.h"
21 #include "sync/protocol/sync.pb.h" 19 #include "sync/protocol/sync.pb.h"
22 20
23 using content::BrowserThread; 21 using content::BrowserThread;
24 22
25 namespace { 23 namespace {
26 24
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 78 }
81 79
82 } // namespace 80 } // namespace
83 81
84 AutocompleteSyncableService::AutocompleteSyncableService( 82 AutocompleteSyncableService::AutocompleteSyncableService(
85 WebDataService* web_data_service) 83 WebDataService* web_data_service)
86 : web_data_service_(web_data_service), 84 : web_data_service_(web_data_service),
87 cull_expired_entries_(false) { 85 cull_expired_entries_(false) {
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
89 DCHECK(web_data_service_); 87 DCHECK(web_data_service_);
90 notification_registrar_.Add( 88 web_data_service_->AddObserver(this);
91 this, chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
92 content::Source<WebDataService>(web_data_service));
93 } 89 }
94 90
95 AutocompleteSyncableService::~AutocompleteSyncableService() { 91 AutocompleteSyncableService::~AutocompleteSyncableService() {
96 DCHECK(CalledOnValidThread()); 92 DCHECK(CalledOnValidThread());
93 if (web_data_service_)
94 web_data_service_->RemoveObserver(this);
97 } 95 }
98 96
99 AutocompleteSyncableService::AutocompleteSyncableService() 97 AutocompleteSyncableService::AutocompleteSyncableService()
100 : web_data_service_(NULL), 98 : web_data_service_(NULL),
101 cull_expired_entries_(false) { 99 cull_expired_entries_(false) {
102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
103 } 101 }
104 102
105 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing( 103 syncer::SyncMergeResult AutocompleteSyncableService::MergeDataAndStartSyncing(
106 syncer::ModelType type, 104 syncer::ModelType type,
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 268
271 if (cull_expired_entries_) { 269 if (cull_expired_entries_) {
272 // This will schedule a deletion operation on the DB thread, which will 270 // This will schedule a deletion operation on the DB thread, which will
273 // trigger a notification to propagate the deletion to Sync. 271 // trigger a notification to propagate the deletion to Sync.
274 web_data_service_->RemoveExpiredFormElements(); 272 web_data_service_->RemoveExpiredFormElements();
275 } 273 }
276 274
277 return list_processing_error; 275 return list_processing_error;
278 } 276 }
279 277
280 void AutocompleteSyncableService::Observe(int type, 278 void AutocompleteSyncableService::AutofillEntriesChanged(
281 const content::NotificationSource& source, 279 const AutofillChangeList& changes) {
282 const content::NotificationDetails& details) {
283 DCHECK_EQ(chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, type);
284
285 // Check if sync is on. If we receive notification prior to the sync being set 280 // Check if sync is on. If we receive notification prior to the sync being set
286 // up we are going to process all when MergeData..() is called. If we receive 281 // up we are going to process all when MergeData..() is called. If we receive
287 // notification after the sync exited, it will be sinced next time Chrome 282 // notification after the sync exited, it will be sinced next time Chrome
288 // starts. 283 // starts.
289 if (!sync_processor_.get()) 284 if (sync_processor_.get())
290 return; 285 ActOnChanges(changes);
291 WebDataService* wds = content::Source<WebDataService>(source).ptr();
292
293 DCHECK_EQ(web_data_service_, wds);
294
295 AutofillChangeList* changes =
296 content::Details<AutofillChangeList>(details).ptr();
297 ActOnChanges(*changes);
298 } 286 }
299 287
300 bool AutocompleteSyncableService::LoadAutofillData( 288 bool AutocompleteSyncableService::LoadAutofillData(
301 std::vector<AutofillEntry>* entries) const { 289 std::vector<AutofillEntry>* entries) const {
302 return web_data_service_->GetDatabase()-> 290 return web_data_service_->GetDatabase()->
303 GetAutofillTable()->GetAllAutofillEntries(entries); 291 GetAutofillTable()->GetAllAutofillEntries(entries);
304 } 292 }
305 293
306 bool AutocompleteSyncableService::SaveChangesToWebData( 294 bool AutocompleteSyncableService::SaveChangesToWebData(
307 const std::vector<AutofillEntry>& new_entries) { 295 const std::vector<AutofillEntry>& new_entries) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 UTF16ToUTF8(entry.key().value()))); 443 UTF16ToUTF8(entry.key().value())));
456 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics); 444 return syncer::SyncData::CreateLocalData(tag, tag, autofill_specifics);
457 } 445 }
458 446
459 // static 447 // static
460 std::string AutocompleteSyncableService::KeyToTag(const std::string& name, 448 std::string AutocompleteSyncableService::KeyToTag(const std::string& name,
461 const std::string& value) { 449 const std::string& value) {
462 std::string ns(kAutofillEntryNamespaceTag); 450 std::string ns(kAutofillEntryNamespaceTag);
463 return ns + net::EscapePath(name) + "|" + net::EscapePath(value); 451 return ns + net::EscapePath(name) + "|" + net::EscapePath(value);
464 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698