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

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

Issue 10919066: Use BrowserContext as key in API. Switch Autofill to use BC in place of Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to parent Created 8 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) 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/autocomplete_history_manager.h" 5 #include "chrome/browser/autofill/autocomplete_history_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/api/prefs/pref_service_base.h" 12 #include "chrome/browser/api/prefs/pref_service_base.h"
13 #include "chrome/browser/autofill/autofill_external_delegate.h" 13 #include "chrome/browser/autofill/autofill_external_delegate.h"
14 #include "chrome/browser/autofill/credit_card.h" 14 #include "chrome/browser/autofill/credit_card.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/autofill_messages.h" 15 #include "chrome/common/autofill_messages.h"
17 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/render_view_host.h" 18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
20 #include "webkit/forms/form_data.h" 20 #include "webkit/forms/form_data.h"
21 21
22 using base::StringPiece16; 22 using base::StringPiece16;
23 using content::BrowserContext;
23 using content::WebContents; 24 using content::WebContents;
24 using webkit::forms::FormData; 25 using webkit::forms::FormData;
25 using webkit::forms::FormField; 26 using webkit::forms::FormField;
26 27
27 namespace { 28 namespace {
28 29
29 // Limit on the number of suggestions to appear in the pop-up menu under an 30 // Limit on the number of suggestions to appear in the pop-up menu under an
30 // text input element in a form. 31 // text input element in a form.
31 const int kMaxAutocompleteMenuItems = 6; 32 const int kMaxAutocompleteMenuItems = 6;
32 33
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 107 }
107 108
108 } // namespace 109 } // namespace
109 110
110 AutocompleteHistoryManager::AutocompleteHistoryManager( 111 AutocompleteHistoryManager::AutocompleteHistoryManager(
111 WebContents* web_contents) 112 WebContents* web_contents)
112 : content::WebContentsObserver(web_contents), 113 : content::WebContentsObserver(web_contents),
113 pending_query_handle_(0), 114 pending_query_handle_(0),
114 query_id_(0), 115 query_id_(0),
115 external_delegate_(NULL) { 116 external_delegate_(NULL) {
116 profile_ = Profile::FromBrowserContext(web_contents->GetBrowserContext()); 117 browser_context_ = web_contents->GetBrowserContext();
117 // May be NULL in unit tests. 118 // May be NULL in unit tests.
118 autofill_data_ = AutofillWebDataService::ForContext(profile_); 119 autofill_data_ = AutofillWebDataService::ForContext(browser_context_);
119 autofill_enabled_.Init( 120 autofill_enabled_.Init(prefs::kAutofillEnabled,
120 prefs::kAutofillEnabled, PrefServiceBase::ForProfile(profile_), NULL); 121 PrefServiceBase::ForContext(browser_context_),
122 NULL);
121 } 123 }
122 124
123 AutocompleteHistoryManager::~AutocompleteHistoryManager() { 125 AutocompleteHistoryManager::~AutocompleteHistoryManager() {
124 CancelPendingQuery(); 126 CancelPendingQuery();
125 } 127 }
126 128
127 bool AutocompleteHistoryManager::OnMessageReceived( 129 bool AutocompleteHistoryManager::OnMessageReceived(
128 const IPC::Message& message) { 130 const IPC::Message& message) {
129 bool handled = true; 131 bool handled = true;
130 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message) 132 IPC_BEGIN_MESSAGE_MAP(AutocompleteHistoryManager, message)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (autofill_data_.get()) { 187 if (autofill_data_.get()) {
186 pending_query_handle_ = autofill_data_->GetFormValuesForElementName( 188 pending_query_handle_ = autofill_data_->GetFormValuesForElementName(
187 name, prefix, kMaxAutocompleteMenuItems, this); 189 name, prefix, kMaxAutocompleteMenuItems, this);
188 } 190 }
189 } 191 }
190 192
191 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) { 193 void AutocompleteHistoryManager::OnFormSubmitted(const FormData& form) {
192 if (!*autofill_enabled_) 194 if (!*autofill_enabled_)
193 return; 195 return;
194 196
195 if (profile_->IsOffTheRecord()) 197 if (browser_context_->IsOffTheRecord())
196 return; 198 return;
197 199
198 // Don't save data that was submitted through JavaScript. 200 // Don't save data that was submitted through JavaScript.
199 if (!form.user_submitted) 201 if (!form.user_submitted)
200 return; 202 return;
201 203
202 // We put the following restriction on stored FormFields: 204 // We put the following restriction on stored FormFields:
203 // - non-empty name 205 // - non-empty name
204 // - non-empty value 206 // - non-empty value
205 // - text field 207 // - text field
(...skipping 22 matching lines...) Expand all
228 autofill_data_->RemoveFormValueForElementName(name, value); 230 autofill_data_->RemoveFormValueForElementName(name, value);
229 } 231 }
230 232
231 void AutocompleteHistoryManager::SetExternalDelegate( 233 void AutocompleteHistoryManager::SetExternalDelegate(
232 AutofillExternalDelegate* delegate) { 234 AutofillExternalDelegate* delegate) {
233 external_delegate_ = delegate; 235 external_delegate_ = delegate;
234 } 236 }
235 237
236 AutocompleteHistoryManager::AutocompleteHistoryManager( 238 AutocompleteHistoryManager::AutocompleteHistoryManager(
237 WebContents* web_contents, 239 WebContents* web_contents,
238 Profile* profile, 240 BrowserContext* browser_context,
239 scoped_ptr<AutofillWebDataService> awd) 241 scoped_ptr<AutofillWebDataService> awd)
240 : content::WebContentsObserver(web_contents), 242 : content::WebContentsObserver(web_contents),
241 profile_(profile), 243 browser_context_(browser_context),
242 autofill_data_(awd.Pass()), 244 autofill_data_(awd.Pass()),
243 pending_query_handle_(0), 245 pending_query_handle_(0),
244 query_id_(0), 246 query_id_(0),
245 external_delegate_(NULL) { 247 external_delegate_(NULL) {
246 autofill_enabled_.Init( 248 autofill_enabled_.Init(prefs::kAutofillEnabled,
247 prefs::kAutofillEnabled, PrefServiceBase::ForProfile(profile_), NULL); 249 PrefServiceBase::ForContext(browser_context_),
250 NULL);
248 } 251 }
249 252
250 void AutocompleteHistoryManager::CancelPendingQuery() { 253 void AutocompleteHistoryManager::CancelPendingQuery() {
251 if (pending_query_handle_) { 254 if (pending_query_handle_) {
252 SendSuggestions(NULL); 255 SendSuggestions(NULL);
253 if (autofill_data_.get()) 256 if (autofill_data_.get())
254 autofill_data_->CancelRequest(pending_query_handle_); 257 autofill_data_->CancelRequest(pending_query_handle_);
255 pending_query_handle_ = 0; 258 pending_query_handle_ = 0;
256 } 259 }
257 } 260 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 autofill_icons_, 297 autofill_icons_,
295 autofill_unique_ids_)); 298 autofill_unique_ids_));
296 } 299 }
297 300
298 query_id_ = 0; 301 query_id_ = 0;
299 autofill_values_.clear(); 302 autofill_values_.clear();
300 autofill_labels_.clear(); 303 autofill_labels_.clear();
301 autofill_icons_.clear(); 304 autofill_icons_.clear();
302 autofill_unique_ids_.clear(); 305 autofill_unique_ids_.clear();
303 } 306 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autocomplete_history_manager.h ('k') | chrome/browser/autofill/autofill_common_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698