OLD | NEW |
---|---|
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 set_state(ASSOCIATING); | |
akalin
2011/10/11 22:41:08
decomp this block (shared with Observe) into its o
Nicolas Zea
2011/10/12 04:24:19
Done.
| |
62 if (!StartAssociationAsync()) { | |
63 SyncError error(FROM_HERE, | |
64 "Failed to post association task.", | |
65 type()); | |
66 StartDoneImpl(ASSOCIATION_FAILED, NOT_RUNNING, error); | |
67 } | |
68 } else { | |
69 notification_registrar_.Add(this, chrome::NOTIFICATION_WEB_DATABASE_LOADED, | |
70 NotificationService::AllSources()); | |
71 } | |
72 } | |
73 | |
74 void AutofillProfileDataTypeController::Observe( | |
75 int notification_type, | |
76 const NotificationSource& source, | |
77 const NotificationDetails& details) { | |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
79 DCHECK_EQ(state(), MODEL_STARTING); | |
80 notification_registrar_.RemoveAll(); | |
81 set_state(ASSOCIATING); | |
82 if (!StartAssociationAsync()) { | |
83 SyncError error(FROM_HERE, | |
84 "Failed to post association task.", | |
85 type()); | |
86 StartDoneImpl(ASSOCIATION_FAILED, NOT_RUNNING, error); | |
87 } | |
88 } | |
89 | |
90 bool AutofillProfileDataTypeController::StartAssociationAsync() { | |
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
92 DCHECK_EQ(state(), ASSOCIATING); | |
93 return BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
94 base::Bind(&AutofillProfileDataTypeController::StartAssociation, | |
95 this)); | |
96 } | |
97 | |
98 WeakHandle<SyncableService> | |
99 AutofillProfileDataTypeController::GetWeakHandleToSyncableService() const { | |
100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
101 // TODO(isherman): This shouldn't create anything, but just get a weakptr to | |
akalin
2011/10/11 22:41:08
This will most likely conflict with isherman's cha
Nicolas Zea
2011/10/12 04:24:19
No longer doing weak handles and rebased to handle
| |
102 // the AutofillProfileSyncableService. See crbug.com/96922. | |
103 return MakeWeakHandle( | |
104 profile_sync_factory()->CreateAutofillProfileSyncComponents( | |
105 profile_sync_service(), | |
106 web_data_service_->GetDatabase())->AsWeakPtr()); | |
107 } | |
108 | |
109 void AutofillProfileDataTypeController::StopModels() { | |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
111 DCHECK(state() == STOPPING || state() == NOT_RUNNING); | |
112 notification_registrar_.RemoveAll(); | |
113 personal_data_->RemoveObserver(this); | |
114 } | |
115 | |
20 syncable::ModelType AutofillProfileDataTypeController::type() const { | 116 syncable::ModelType AutofillProfileDataTypeController::type() const { |
21 return syncable::AUTOFILL_PROFILE; | 117 return syncable::AUTOFILL_PROFILE; |
22 } | 118 } |
23 | 119 |
24 void AutofillProfileDataTypeController::CreateSyncComponents() { | 120 browser_sync::ModelSafeGroup |
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 121 AutofillProfileDataTypeController::model_safe_group() const { |
26 ProfileSyncFactory::SyncComponents sync_components = | 122 return browser_sync::GROUP_DB; |
27 profile_sync_factory()-> | |
28 CreateAutofillProfileSyncComponents( | |
29 profile_sync_service(), | |
30 web_data_service()->GetDatabase(), | |
31 this); | |
32 set_model_associator(sync_components.model_associator); | |
33 set_change_processor(sync_components.change_processor); | |
34 } | 123 } |
35 | 124 |
36 void AutofillProfileDataTypeController::RecordUnrecoverableError( | 125 void AutofillProfileDataTypeController::RecordUnrecoverableError( |
37 const tracked_objects::Location& from_here, | 126 const tracked_objects::Location& from_here, |
38 const std::string& message) { | 127 const std::string& message) { |
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
40 UMA_HISTOGRAM_COUNTS("Sync.AutofillProfileRunFailures", 1); | 129 UMA_HISTOGRAM_COUNTS("Sync.AutofillProfileRunFailures", 1); |
41 } | 130 } |
42 | 131 |
43 void AutofillProfileDataTypeController::RecordAssociationTime( | 132 void AutofillProfileDataTypeController::RecordAssociationTime( |
44 base::TimeDelta time) { | 133 base::TimeDelta time) { |
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
46 UMA_HISTOGRAM_TIMES("Sync.AutofillProfileAssociationTime", time); | 135 UMA_HISTOGRAM_TIMES("Sync.AutofillProfileAssociationTime", time); |
47 } | 136 } |
48 | 137 |
49 void AutofillProfileDataTypeController::RecordStartFailure(StartResult result) { | 138 void AutofillProfileDataTypeController::RecordStartFailure(StartResult result) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
51 UMA_HISTOGRAM_ENUMERATION("Sync.AutofillProfileStartFailures", | 140 UMA_HISTOGRAM_ENUMERATION("Sync.AutofillProfileStartFailures", |
52 result, | 141 result, |
53 MAX_START_RESULT); | 142 MAX_START_RESULT); |
54 } | 143 } |
55 | 144 |
56 } // namepsace browser_sync | 145 } // namepsace browser_sync |
OLD | NEW |