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

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

Issue 8065016: [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Try harder trybot (rebase). Created 9 years, 2 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_data_type_controller.h" 5 #include "chrome/browser/sync/glue/autofill_profile_data_type_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/task.h"
9 #include "chrome/browser/autofill/personal_data_manager.h"
10 #include "chrome/browser/autofill/personal_data_manager_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/sync/api/sync_error.h"
13 #include "chrome/browser/sync/api/syncable_service.h"
8 #include "chrome/browser/sync/profile_sync_factory.h" 14 #include "chrome/browser/sync/profile_sync_factory.h"
15 #include "chrome/browser/sync/profile_sync_service.h"
9 #include "chrome/browser/webdata/web_data_service.h" 16 #include "chrome/browser/webdata/web_data_service.h"
17 #include "chrome/common/chrome_notification_types.h"
18 #include "content/browser/browser_thread.h"
19 #include "content/common/notification_service.h"
20 #include "content/common/notification_source.h"
10 21
11 namespace browser_sync { 22 namespace browser_sync {
12 23
13 AutofillProfileDataTypeController::AutofillProfileDataTypeController( 24 AutofillProfileDataTypeController::AutofillProfileDataTypeController(
14 ProfileSyncFactory* profile_sync_factory, 25 ProfileSyncFactory* profile_sync_factory,
15 Profile* profile) 26 Profile* profile)
16 : AutofillDataTypeController(profile_sync_factory, profile) {} 27 : NewNonFrontendDataTypeController(profile_sync_factory, profile),
28 personal_data_(NULL) {
29 }
17 30
18 AutofillProfileDataTypeController::~AutofillProfileDataTypeController() {} 31 AutofillProfileDataTypeController::~AutofillProfileDataTypeController() {}
19 32
33 bool AutofillProfileDataTypeController::StartModels() {
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
35 DCHECK_EQ(state(), MODEL_STARTING);
36 // Waiting for the personal data is subtle: we do this as the PDM resets
37 // its cache of unique IDs once it gets loaded. If we were to proceed with
38 // association, the local ids in the mappings would wind up colliding.
39 personal_data_ = PersonalDataManagerFactory::GetForProfile(profile());
40 if (!personal_data_->IsDataLoaded()) {
41 personal_data_->SetObserver(this);
42 return false;
43 }
44
45 web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS);
46 if (web_data_service_.get() && web_data_service_->IsDatabaseLoaded()) {
47 return true;
48 } else {
49 notification_registrar_.Add(this, chrome::NOTIFICATION_WEB_DATABASE_LOADED,
50 NotificationService::AllSources());
51 return false;
52 }
53 }
54
55 void AutofillProfileDataTypeController::OnPersonalDataChanged() {
56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
57 DCHECK_EQ(state(), MODEL_STARTING);
58 personal_data_->RemoveObserver(this);
59 web_data_service_ = profile()->GetWebDataService(Profile::IMPLICIT_ACCESS);
60 if (web_data_service_.get() && web_data_service_->IsDatabaseLoaded()) {
61 DoStartAssociationAsync();
62 } else {
63 notification_registrar_.Add(this, chrome::NOTIFICATION_WEB_DATABASE_LOADED,
64 NotificationService::AllSources());
65 }
66 }
67
68 void AutofillProfileDataTypeController::Observe(
69 int notification_type,
70 const NotificationSource& source,
71 const NotificationDetails& details) {
72 notification_registrar_.RemoveAll();
73 DoStartAssociationAsync();
74 }
75
76 void AutofillProfileDataTypeController::DoStartAssociationAsync() {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 DCHECK_EQ(state(), MODEL_STARTING);
79 set_state(ASSOCIATING);
80 if (!StartAssociationAsync()) {
81 SyncError error(FROM_HERE,
82 "Failed to post association task.",
83 type());
84 StartDoneImpl(ASSOCIATION_FAILED, NOT_RUNNING, error);
85 }
86 }
87
88 bool AutofillProfileDataTypeController::StartAssociationAsync() {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
90 DCHECK_EQ(state(), ASSOCIATING);
91 return BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
92 base::Bind(&AutofillProfileDataTypeController::StartAssociation,
93 this));
94 }
95
96 base::WeakPtr<SyncableService>
97 AutofillProfileDataTypeController::GetWeakPtrToSyncableService() const {
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
99 // TODO(isherman): This shouldn't create anything, but just get a weakptr to
akalin 2011/10/12 19:54:21 this TODO is now obsolete, isn't it? Or do you ne
Nicolas Zea 2011/10/12 23:47:43 Done.
100 // the AutofillProfileSyncableService. See crbug.com/96922.
101 return profile_sync_factory()->GetAutofillProfileSyncableService(
102 web_data_service_.get());
103 }
104
105 void AutofillProfileDataTypeController::StopModels() {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
107 DCHECK(state() == STOPPING || state() == NOT_RUNNING);
108 notification_registrar_.RemoveAll();
109 personal_data_->RemoveObserver(this);
110 }
111
112 void AutofillProfileDataTypeController::StopLocalServiceAsync() {
113 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
114 base::Bind(&AutofillProfileDataTypeController::StopLocalService,
115 this));
116 }
20 syncable::ModelType AutofillProfileDataTypeController::type() const { 117 syncable::ModelType AutofillProfileDataTypeController::type() const {
21 return syncable::AUTOFILL_PROFILE; 118 return syncable::AUTOFILL_PROFILE;
22 } 119 }
23 120
24 void AutofillProfileDataTypeController::CreateSyncComponents() { 121 browser_sync::ModelSafeGroup
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 122 AutofillProfileDataTypeController::model_safe_group() const {
26 ProfileSyncFactory::SyncComponents sync_components = 123 return browser_sync::GROUP_DB;
27 profile_sync_factory()->
28 CreateAutofillProfileSyncComponents(profile_sync_service(),
29 web_data_service(),
30 this);
31 set_model_associator(sync_components.model_associator);
32 set_change_processor(sync_components.change_processor);
33 } 124 }
34 125
35 void AutofillProfileDataTypeController::RecordUnrecoverableError( 126 void AutofillProfileDataTypeController::RecordUnrecoverableError(
36 const tracked_objects::Location& from_here, 127 const tracked_objects::Location& from_here,
37 const std::string& message) { 128 const std::string& message) {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
39 UMA_HISTOGRAM_COUNTS("Sync.AutofillProfileRunFailures", 1); 130 UMA_HISTOGRAM_COUNTS("Sync.AutofillProfileRunFailures", 1);
40 } 131 }
41 132
42 void AutofillProfileDataTypeController::RecordAssociationTime( 133 void AutofillProfileDataTypeController::RecordAssociationTime(
43 base::TimeDelta time) { 134 base::TimeDelta time) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
45 UMA_HISTOGRAM_TIMES("Sync.AutofillProfileAssociationTime", time); 136 UMA_HISTOGRAM_TIMES("Sync.AutofillProfileAssociationTime", time);
46 } 137 }
47 138
48 void AutofillProfileDataTypeController::RecordStartFailure(StartResult result) { 139 void AutofillProfileDataTypeController::RecordStartFailure(StartResult result) {
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
50 UMA_HISTOGRAM_ENUMERATION("Sync.AutofillProfileStartFailures", 141 UMA_HISTOGRAM_ENUMERATION("Sync.AutofillProfileStartFailures",
51 result, 142 result,
52 MAX_START_RESULT); 143 MAX_START_RESULT);
53 } 144 }
54 145
55 } // namepsace browser_sync 146 } // namepsace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698