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

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

Issue 8274020: Revert 105404 - [Sync] Refactor non-frontend DTC to handle new API properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
14 #include "chrome/browser/sync/profile_sync_factory.h" 8 #include "chrome/browser/sync/profile_sync_factory.h"
15 #include "chrome/browser/sync/profile_sync_service.h"
16 #include "chrome/browser/webdata/web_data_service.h" 9 #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"
21 10
22 namespace browser_sync { 11 namespace browser_sync {
23 12
24 AutofillProfileDataTypeController::AutofillProfileDataTypeController( 13 AutofillProfileDataTypeController::AutofillProfileDataTypeController(
25 ProfileSyncFactory* profile_sync_factory, 14 ProfileSyncFactory* profile_sync_factory,
26 Profile* profile) 15 Profile* profile)
27 : NewNonFrontendDataTypeController(profile_sync_factory, profile), 16 : AutofillDataTypeController(profile_sync_factory, profile) {}
28 personal_data_(NULL) {
29 }
30 17
31 AutofillProfileDataTypeController::~AutofillProfileDataTypeController() {} 18 AutofillProfileDataTypeController::~AutofillProfileDataTypeController() {}
32 19
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 return profile_sync_factory()->GetAutofillProfileSyncableService(
100 web_data_service_.get());
101 }
102
103 void AutofillProfileDataTypeController::StopModels() {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 DCHECK(state() == STOPPING || state() == NOT_RUNNING);
106 notification_registrar_.RemoveAll();
107 personal_data_->RemoveObserver(this);
108 }
109
110 void AutofillProfileDataTypeController::StopLocalServiceAsync() {
111 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
112 base::Bind(&AutofillProfileDataTypeController::StopLocalService,
113 this));
114 }
115 syncable::ModelType AutofillProfileDataTypeController::type() const { 20 syncable::ModelType AutofillProfileDataTypeController::type() const {
116 return syncable::AUTOFILL_PROFILE; 21 return syncable::AUTOFILL_PROFILE;
117 } 22 }
118 23
119 browser_sync::ModelSafeGroup 24 void AutofillProfileDataTypeController::CreateSyncComponents() {
120 AutofillProfileDataTypeController::model_safe_group() const { 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
121 return browser_sync::GROUP_DB; 26 ProfileSyncFactory::SyncComponents sync_components =
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);
122 } 33 }
123 34
124 void AutofillProfileDataTypeController::RecordUnrecoverableError( 35 void AutofillProfileDataTypeController::RecordUnrecoverableError(
125 const tracked_objects::Location& from_here, 36 const tracked_objects::Location& from_here,
126 const std::string& message) { 37 const std::string& message) {
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
128 UMA_HISTOGRAM_COUNTS("Sync.AutofillProfileRunFailures", 1); 39 UMA_HISTOGRAM_COUNTS("Sync.AutofillProfileRunFailures", 1);
129 } 40 }
130 41
131 void AutofillProfileDataTypeController::RecordAssociationTime( 42 void AutofillProfileDataTypeController::RecordAssociationTime(
132 base::TimeDelta time) { 43 base::TimeDelta time) {
133 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
134 UMA_HISTOGRAM_TIMES("Sync.AutofillProfileAssociationTime", time); 45 UMA_HISTOGRAM_TIMES("Sync.AutofillProfileAssociationTime", time);
135 } 46 }
136 47
137 void AutofillProfileDataTypeController::RecordStartFailure(StartResult result) { 48 void AutofillProfileDataTypeController::RecordStartFailure(StartResult result) {
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
139 UMA_HISTOGRAM_ENUMERATION("Sync.AutofillProfileStartFailures", 50 UMA_HISTOGRAM_ENUMERATION("Sync.AutofillProfileStartFailures",
140 result, 51 result,
141 MAX_START_RESULT); 52 MAX_START_RESULT);
142 } 53 }
143 54
144 } // namepsace browser_sync 55 } // namepsace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/autofill_profile_data_type_controller.h ('k') | chrome/browser/sync/glue/change_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698