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

Side by Side Diff: chrome/browser/autofill/autofill_manager.cc

Issue 10168017: Only enable password generation if password manager and autofill are both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove autofill requirement Created 8 years, 8 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/autofill/autofill_manager.h" 5 #include "chrome/browser/autofill/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/autofill/autofill_profile.h" 27 #include "chrome/browser/autofill/autofill_profile.h"
28 #include "chrome/browser/autofill/autofill_type.h" 28 #include "chrome/browser/autofill/autofill_type.h"
29 #include "chrome/browser/autofill/credit_card.h" 29 #include "chrome/browser/autofill/credit_card.h"
30 #include "chrome/browser/autofill/form_structure.h" 30 #include "chrome/browser/autofill/form_structure.h"
31 #include "chrome/browser/autofill/personal_data_manager.h" 31 #include "chrome/browser/autofill/personal_data_manager.h"
32 #include "chrome/browser/autofill/personal_data_manager_factory.h" 32 #include "chrome/browser/autofill/personal_data_manager_factory.h"
33 #include "chrome/browser/autofill/phone_number.h" 33 #include "chrome/browser/autofill/phone_number.h"
34 #include "chrome/browser/autofill/phone_number_i18n.h" 34 #include "chrome/browser/autofill/phone_number_i18n.h"
35 #include "chrome/browser/autofill/select_control_handler.h" 35 #include "chrome/browser/autofill/select_control_handler.h"
36 #include "chrome/browser/infobars/infobar_tab_helper.h" 36 #include "chrome/browser/infobars/infobar_tab_helper.h"
37 #include "chrome/browser/password_manager/password_manager.h"
37 #include "chrome/browser/prefs/pref_service.h" 38 #include "chrome/browser/prefs/pref_service.h"
38 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
39 #include "chrome/browser/sync/profile_sync_service_factory.h" 40 #include "chrome/browser/sync/profile_sync_service_factory.h"
40 #include "chrome/browser/sync/profile_sync_service.h" 41 #include "chrome/browser/sync/profile_sync_service.h"
41 #include "chrome/browser/ui/browser.h" 42 #include "chrome/browser/ui/browser.h"
42 #include "chrome/browser/ui/browser_list.h" 43 #include "chrome/browser/ui/browser_list.h"
43 #include "chrome/browser/ui/browser_window.h" 44 #include "chrome/browser/ui/browser_window.h"
44 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 45 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
45 #include "chrome/common/autofill_messages.h" 46 #include "chrome/common/autofill_messages.h"
46 #include "chrome/common/chrome_notification_types.h" 47 #include "chrome/common/chrome_notification_types.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 personal_data_(NULL), 182 personal_data_(NULL),
182 download_manager_(tab_contents->profile(), this), 183 download_manager_(tab_contents->profile(), this),
183 disable_download_manager_requests_(false), 184 disable_download_manager_requests_(false),
184 metric_logger_(new AutofillMetrics), 185 metric_logger_(new AutofillMetrics),
185 has_logged_autofill_enabled_(false), 186 has_logged_autofill_enabled_(false),
186 has_logged_address_suggestions_count_(false), 187 has_logged_address_suggestions_count_(false),
187 did_show_suggestions_(false), 188 did_show_suggestions_(false),
188 user_did_type_(false), 189 user_did_type_(false),
189 user_did_autofill_(false), 190 user_did_autofill_(false),
190 user_did_edit_autofilled_field_(false), 191 user_did_edit_autofilled_field_(false),
191 password_sync_enabled_(false), 192 password_generation_enabled_(false),
192 external_delegate_(NULL) { 193 external_delegate_(NULL) {
193 // |personal_data_| is NULL when using test-enabled WebContents. 194 // |personal_data_| is NULL when using test-enabled WebContents.
194 personal_data_ = PersonalDataManagerFactory::GetForProfile( 195 personal_data_ = PersonalDataManagerFactory::GetForProfile(
195 tab_contents->profile()->GetOriginalProfile()); 196 tab_contents->profile()->GetOriginalProfile());
196 RegisterWithSyncService(); 197 RegisterWithSyncService();
197 } 198 }
198 199
199 AutofillManager::~AutofillManager() { 200 AutofillManager::~AutofillManager() {
200 if (sync_service_ && sync_service_->HasObserver(this)) 201 if (sync_service_ && sync_service_->HasObserver(this))
201 sync_service_->RemoveObserver(this); 202 sync_service_->RemoveObserver(this);
(...skipping 24 matching lines...) Expand all
226 void AutofillManager::RegisterWithSyncService() { 227 void AutofillManager::RegisterWithSyncService() {
227 ProfileSyncService* temp_sync_service = 228 ProfileSyncService* temp_sync_service =
228 ProfileSyncServiceFactory::GetForProfile( 229 ProfileSyncServiceFactory::GetForProfile(
229 tab_contents_wrapper_->profile()); 230 tab_contents_wrapper_->profile());
230 if (temp_sync_service) { 231 if (temp_sync_service) {
231 sync_service_ = temp_sync_service->AsWeakPtr(); 232 sync_service_ = temp_sync_service->AsWeakPtr();
232 sync_service_->AddObserver(this); 233 sync_service_->AddObserver(this);
233 } 234 }
234 } 235 }
235 236
236 void AutofillManager::SendPasswordSyncStateToRenderer( 237 void AutofillManager::SendPasswordGenerationStateToRenderer(
237 content::RenderViewHost* host, bool enabled) { 238 content::RenderViewHost* host, bool enabled) {
238 host->Send(new AutofillMsg_PasswordSyncEnabled(host->GetRoutingID(), 239 host->Send(new AutofillMsg_PasswordGenerationEnabled(host->GetRoutingID(),
239 enabled)); 240 enabled));
240 } 241 }
241 242
242 void AutofillManager::UpdatePasswordSyncState(content::RenderViewHost* host, 243 void AutofillManager::UpdatePasswordGenerationState(
243 bool new_renderer) { 244 content::RenderViewHost* host,
245 bool new_renderer) {
244 if (!sync_service_) 246 if (!sync_service_)
245 return; 247 return;
246 248
249 // Password generation requires sync for passwords and the password manager
250 // to all be enabled.
Ilya Sherman 2012/04/24 21:57:45 nit: "all" -> "both"
247 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes(); 251 syncable::ModelTypeSet sync_set = sync_service_->GetPreferredDataTypes();
248 bool new_password_sync_enabled = (sync_service_->HasSyncSetupCompleted() && 252 bool password_sync_enabled = (sync_service_->HasSyncSetupCompleted() &&
249 sync_set.Has(syncable::PASSWORDS)); 253 sync_set.Has(syncable::PASSWORDS));
250 if (new_password_sync_enabled != password_sync_enabled_ || 254 bool new_password_generation_enabled =
255 password_sync_enabled &&
256 tab_contents_wrapper_->password_manager()->IsEnabled();
257 if (new_password_generation_enabled != password_generation_enabled_ ||
251 new_renderer) { 258 new_renderer) {
252 password_sync_enabled_ = new_password_sync_enabled; 259 password_generation_enabled_ = new_password_generation_enabled;
253 SendPasswordSyncStateToRenderer(host, password_sync_enabled_); 260 SendPasswordGenerationStateToRenderer(host, password_generation_enabled_);
254 } 261 }
255 } 262 }
256 263
257 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) { 264 void AutofillManager::RenderViewCreated(content::RenderViewHost* host) {
258 UpdatePasswordSyncState(host, true); 265 UpdatePasswordGenerationState(host, true);
259 } 266 }
260 267
261 void AutofillManager::OnStateChanged() { 268 void AutofillManager::OnStateChanged() {
262 // It is possible for sync state to change during tab contents destruction. 269 // It is possible for sync state to change during tab contents destruction.
263 // In this case, we don't need to update the renderer since it's going away. 270 // In this case, we don't need to update the renderer since it's going away.
264 if (web_contents() && web_contents()->GetRenderViewHost()) { 271 if (web_contents() && web_contents()->GetRenderViewHost()) {
265 UpdatePasswordSyncState(web_contents()->GetRenderViewHost(), false); 272 UpdatePasswordGenerationState(web_contents()->GetRenderViewHost(),
273 false);
266 } 274 }
267 } 275 }
268 276
269 void AutofillManager::DidNavigateMainFrame( 277 void AutofillManager::DidNavigateMainFrame(
270 const content::LoadCommittedDetails& details, 278 const content::LoadCommittedDetails& details,
271 const content::FrameNavigateParams& params) { 279 const content::FrameNavigateParams& params) {
272 Reset(); 280 Reset();
273 } 281 }
274 282
275 bool AutofillManager::HasExternalDelegate() { 283 bool AutofillManager::HasExternalDelegate() {
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 personal_data_(personal_data), 832 personal_data_(personal_data),
825 download_manager_(tab_contents->profile(), this), 833 download_manager_(tab_contents->profile(), this),
826 disable_download_manager_requests_(true), 834 disable_download_manager_requests_(true),
827 metric_logger_(new AutofillMetrics), 835 metric_logger_(new AutofillMetrics),
828 has_logged_autofill_enabled_(false), 836 has_logged_autofill_enabled_(false),
829 has_logged_address_suggestions_count_(false), 837 has_logged_address_suggestions_count_(false),
830 did_show_suggestions_(false), 838 did_show_suggestions_(false),
831 user_did_type_(false), 839 user_did_type_(false),
832 user_did_autofill_(false), 840 user_did_autofill_(false),
833 user_did_edit_autofilled_field_(false), 841 user_did_edit_autofilled_field_(false),
834 password_sync_enabled_(false), 842 password_generation_enabled_(false),
835 external_delegate_(NULL) { 843 external_delegate_(NULL) {
836 DCHECK(tab_contents); 844 DCHECK(tab_contents);
837 RegisterWithSyncService(); 845 RegisterWithSyncService();
838 } 846 }
839 847
840 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) { 848 void AutofillManager::set_metric_logger(const AutofillMetrics* metric_logger) {
841 metric_logger_.reset(metric_logger); 849 metric_logger_.reset(metric_logger);
842 } 850 }
843 851
844 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles, 852 bool AutofillManager::GetHost(const std::vector<AutofillProfile*>& profiles,
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 *profile_guid = IDToGUID(profile_id); 1327 *profile_guid = IDToGUID(profile_id);
1320 } 1328 }
1321 1329
1322 void AutofillManager::UpdateInitialInteractionTimestamp( 1330 void AutofillManager::UpdateInitialInteractionTimestamp(
1323 const TimeTicks& interaction_timestamp) { 1331 const TimeTicks& interaction_timestamp) {
1324 if (initial_interaction_timestamp_.is_null() || 1332 if (initial_interaction_timestamp_.is_null() ||
1325 interaction_timestamp < initial_interaction_timestamp_) { 1333 interaction_timestamp < initial_interaction_timestamp_) {
1326 initial_interaction_timestamp_ = interaction_timestamp; 1334 initial_interaction_timestamp_ = interaction_timestamp;
1327 } 1335 }
1328 } 1336 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698