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

Side by Side Diff: chrome/browser/sync/glue/autofill_profile_syncable_service.cc

Issue 7967024: Profile shouldn't own PersonalDataManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/sync/glue/autofill_profile_syncable_service.h" 5 #include "chrome/browser/sync/glue/autofill_profile_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/autofill/autofill_profile.h"
11 #include "chrome/browser/autofill/form_group.h"
10 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/api/sync_error.h" 13 #include "chrome/browser/sync/api/sync_error.h"
12 #include "chrome/browser/sync/glue/do_optimistic_refresh_task.h"
13 #include "chrome/browser/webdata/autofill_table.h" 14 #include "chrome/browser/webdata/autofill_table.h"
14 #include "chrome/browser/webdata/web_database.h" 15 #include "chrome/browser/webdata/web_database.h"
16 #include "chrome/browser/webdata/web_data_service.h"
15 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/guid.h" 18 #include "chrome/common/guid.h"
19 #include "content/browser/browser_thread.h"
17 #include "content/common/notification_service.h" 20 #include "content/common/notification_service.h"
18 21
19 namespace { 22 namespace {
20 23
21 // Helper to compare the local value and cloud value of a field, merge into 24 // Helper to compare the local value and cloud value of a field, merge into
22 // the local value if they differ, and return whether the merge happened. 25 // the local value if they differ, and return whether the merge happened.
23 bool MergeField(FormGroup* form_group, 26 bool MergeField(FormGroup* form_group,
24 AutofillFieldType field_type, 27 AutofillFieldType field_type,
25 const std::string& specifics_field) { 28 const std::string& specifics_field) {
26 if (UTF16ToUTF8(form_group->GetInfo(field_type)) == specifics_field) 29 if (UTF16ToUTF8(form_group->GetInfo(field_type)) == specifics_field)
27 return false; 30 return false;
28 form_group->SetInfo(field_type, UTF8ToUTF16(specifics_field)); 31 form_group->SetInfo(field_type, UTF8ToUTF16(specifics_field));
29 return true; 32 return true;
30 } 33 }
31 34
35 // Helper to notify listeners of batch change to Autofill data. |profile| may
36 // be NULL for testing.
37 void NotifyOfMultipleAutofillChanges(Profile* profile) {
38 if (!profile)
39 return;
40
41 WebDataService* web_data_service =
42 profile->GetWebDataService(Profile::EXPLICIT_ACCESS);
43 if (web_data_service)
44 web_data_service->NotifyOfMultipleAutofillChanges();
45 }
46
32 } // namespace 47 } // namespace
33 48
34 namespace browser_sync { 49 namespace browser_sync {
35 50
36 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles"; 51 const char kAutofillProfileTag[] = "google_chrome_autofill_profiles";
37 52
38 AutofillProfileSyncableService::AutofillProfileSyncableService( 53 AutofillProfileSyncableService::AutofillProfileSyncableService(
39 WebDatabase* web_database, 54 WebDatabase* web_database,
40 PersonalDataManager* personal_data,
41 Profile* profile) 55 Profile* profile)
42 : web_database_(web_database), 56 : web_database_(web_database),
43 personal_data_(personal_data), 57 profile_(profile),
44 sync_processor_(NULL) { 58 sync_processor_(NULL) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
46 DCHECK(web_database_); 60 DCHECK(web_database_);
47 DCHECK(personal_data_);
48 DCHECK(profile); 61 DCHECK(profile);
49 notification_registrar_.Add(this, 62 notification_registrar_.Add(this,
50 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 63 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
51 Source<WebDataService>( 64 Source<WebDataService>(
52 profile->GetWebDataService(Profile::EXPLICIT_ACCESS))); 65 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)));
53 } 66 }
54 67
55 AutofillProfileSyncableService::~AutofillProfileSyncableService() { 68 AutofillProfileSyncableService::~AutofillProfileSyncableService() {
56 DCHECK(CalledOnValidThread()); 69 DCHECK(CalledOnValidThread());
57 } 70 }
58 71
59 AutofillProfileSyncableService::AutofillProfileSyncableService() 72 AutofillProfileSyncableService::AutofillProfileSyncableService()
60 : web_database_(NULL), 73 : web_database_(NULL),
61 personal_data_(NULL), 74 profile_(NULL),
62 sync_processor_(NULL) { 75 sync_processor_(NULL) {
63 } 76 }
64 77
65 SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing( 78 SyncError AutofillProfileSyncableService::MergeDataAndStartSyncing(
66 syncable::ModelType type, 79 syncable::ModelType type,
67 const SyncDataList& initial_sync_data, 80 const SyncDataList& initial_sync_data,
68 SyncChangeProcessor* sync_processor) { 81 SyncChangeProcessor* sync_processor) {
69 DCHECK(CalledOnValidThread()); 82 DCHECK(CalledOnValidThread());
70 DCHECK(sync_processor_ == NULL); 83 DCHECK(sync_processor_ == NULL);
71 VLOG(1) << "Associating Autofill: MergeDataAndStartSyncing"; 84 VLOG(1) << "Associating Autofill: MergeDataAndStartSyncing";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 SyncChangeList new_changes; 125 SyncChangeList new_changes;
113 for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); 126 for (GUIDToProfileMap::iterator i = remaining_profiles.begin();
114 i != remaining_profiles.end(); ++i) { 127 i != remaining_profiles.end(); ++i) {
115 new_changes.push_back( 128 new_changes.push_back(
116 SyncChange(SyncChange::ACTION_ADD, CreateData(*(i->second)))); 129 SyncChange(SyncChange::ACTION_ADD, CreateData(*(i->second))));
117 profiles_map_[i->first] = i->second; 130 profiles_map_[i->first] = i->second;
118 } 131 }
119 132
120 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); 133 SyncError error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes);
121 134
122 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 135 NotifyOfMultipleAutofillChanges(profile_);
123 new DoOptimisticRefreshForAutofill(personal_data_));
124 136
125 return error; 137 return error;
126 } 138 }
127 139
128 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) { 140 void AutofillProfileSyncableService::StopSyncing(syncable::ModelType type) {
129 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
130 DCHECK(sync_processor_ != NULL); 142 DCHECK(sync_processor_ != NULL);
131 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE); 143 DCHECK_EQ(type, syncable::AUTOFILL_PROFILE);
132 144
133 sync_processor_ = NULL; 145 sync_processor_ = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 NOTREACHED() << "Unexpected sync change state."; 193 NOTREACHED() << "Unexpected sync change state.";
182 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " + 194 return SyncError(FROM_HERE, "ProcessSyncChanges failed on ChangeType " +
183 SyncChange::ChangeTypeToString(i->change_type()), 195 SyncChange::ChangeTypeToString(i->change_type()),
184 syncable::AUTOFILL_PROFILE); 196 syncable::AUTOFILL_PROFILE);
185 } 197 }
186 } 198 }
187 199
188 if (!SaveChangesToWebData(bundle)) 200 if (!SaveChangesToWebData(bundle))
189 return SyncError(FROM_HERE, "Failed to update webdata.", model_type()); 201 return SyncError(FROM_HERE, "Failed to update webdata.", model_type());
190 202
191 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 203 NotifyOfMultipleAutofillChanges(profile_);
192 new DoOptimisticRefreshForAutofill(personal_data_)); 204
193 return SyncError(); 205 return SyncError();
194 } 206 }
195 207
196 void AutofillProfileSyncableService::Observe(int type, 208 void AutofillProfileSyncableService::Observe(int type,
197 const NotificationSource& source, 209 const NotificationSource& source,
198 const NotificationDetails& details) { 210 const NotificationDetails& details) {
199 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED); 211 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED);
200 // Check if sync is on. If we receive notification prior to the sync being set 212 // Check if sync is on. If we receive notification prior to the sync being set
201 // up we are going to process all when MergeData..() is called. If we receive 213 // up we are going to process all when MergeData..() is called. If we receive
202 // notification after the sync exited, it will be sinced next time Chrome 214 // notification after the sync exited, it will be sinced next time Chrome
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 WriteAutofillProfile(profile, &specifics); 419 WriteAutofillProfile(profile, &specifics);
408 return SyncData::CreateLocalData(profile.guid(), profile.guid(), specifics); 420 return SyncData::CreateLocalData(profile.guid(), profile.guid(), specifics);
409 } 421 }
410 422
411 AutofillProfileSyncableService::DataBundle::DataBundle() {} 423 AutofillProfileSyncableService::DataBundle::DataBundle() {}
412 424
413 AutofillProfileSyncableService::DataBundle::~DataBundle() { 425 AutofillProfileSyncableService::DataBundle::~DataBundle() {
414 } 426 }
415 427
416 } // namespace browser_sync 428 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698