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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_ui_controller.cc

Issue 777423004: Skeleton code for experiment setup, which will determine should "Allow to collect URL?" bubble be s… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ui/passwords/manage_passwords_ui_controller.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
6 6
7 #include "base/json/json_writer.h"
7 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/browsing_data/browsing_data_helper.h" 9 #include "chrome/browser/browsing_data/browsing_data_helper.h"
9 #include "chrome/browser/password_manager/password_store_factory.h" 10 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/ui/browser_command_controller.h" 11 #include "chrome/browser/ui/browser_command_controller.h"
11 #include "chrome/browser/ui/browser_dialogs.h" 12 #include "chrome/browser/ui/browser_dialogs.h"
12 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/chrome_pages.h" 14 #include "chrome/browser/ui/chrome_pages.h"
14 #include "chrome/browser/ui/location_bar/location_bar.h" 15 #include "chrome/browser/ui/location_bar/location_bar.h"
15 #include "chrome/browser/ui/passwords/manage_passwords_icon.h" 16 #include "chrome/browser/ui/passwords/manage_passwords_icon.h"
16 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" 17 #include "chrome/browser/ui/passwords/password_bubble_experiment.h"
17 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "components/feedback/feedback_data.h"
20 #include "components/feedback/feedback_util.h"
18 #include "components/password_manager/content/common/credential_manager_types.h" 21 #include "components/password_manager/content/common/credential_manager_types.h"
19 #include "components/password_manager/core/browser/password_form_manager.h" 22 #include "components/password_manager/core/browser/password_form_manager.h"
23 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/navigation_details.h" 24 #include "content/public/browser/navigation_details.h"
21 25
22 #if defined(OS_ANDROID) 26 #if defined(OS_ANDROID)
23 #include "chrome/browser/android/chromium_application.h" 27 #include "chrome/browser/android/chromium_application.h"
24 #endif 28 #endif
25 29
26 using autofill::PasswordFormMap; 30 using autofill::PasswordFormMap;
31 using feedback::FeedbackData;
27 using password_manager::PasswordFormManager; 32 using password_manager::PasswordFormManager;
28 33
29 namespace { 34 namespace {
30 35
31 password_manager::PasswordStore* GetPasswordStore( 36 password_manager::PasswordStore* GetPasswordStore(
32 content::WebContents* web_contents) { 37 content::WebContents* web_contents) {
33 return PasswordStoreFactory::GetForProfile( 38 return PasswordStoreFactory::GetForProfile(
34 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 39 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
35 Profile::EXPLICIT_ACCESS).get(); 40 Profile::EXPLICIT_ACCESS).get();
36 } 41 }
(...skipping 14 matching lines...) Expand all
51 deleter->clear(); 56 deleter->clear();
52 for (autofill::ConstPasswordFormMap::iterator i = ret->begin(); 57 for (autofill::ConstPasswordFormMap::iterator i = ret->begin();
53 i != ret->end(); ++i) { 58 i != ret->end(); ++i) {
54 deleter->push_back(new autofill::PasswordForm(*i->second)); 59 deleter->push_back(new autofill::PasswordForm(*i->second));
55 i->second = deleter->back(); 60 i->second = deleter->back();
56 } 61 }
57 } 62 }
58 63
59 } // namespace 64 } // namespace
60 65
66 class ManagePasswordsUIController::URLCollectionFeedbackSender {
67 public:
68 explicit URLCollectionFeedbackSender(ManagePasswordsUIController* parent);
69 ~URLCollectionFeedbackSender() = default;
70
71 void SendFeedback();
72
73 private:
74 std::string FormReport();
75 static constexpr char kPasswordManagerURLCollectionBucket[] =
76 "PasswordManagerURLCollection";
77 ManagePasswordsUIController* parent_;
78 };
79 constexpr char ManagePasswordsUIController::URLCollectionFeedbackSender::
80 kPasswordManagerURLCollectionBucket[];
81
82 ManagePasswordsUIController::URLCollectionFeedbackSender::
83 URLCollectionFeedbackSender(ManagePasswordsUIController* parent)
84 : parent_(parent) {
85 }
86
87 void ManagePasswordsUIController::URLCollectionFeedbackSender::SendFeedback() {
88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
89 scoped_refptr<FeedbackData> feedback_data = new FeedbackData();
90 feedback_data->set_category_tag(kPasswordManagerURLCollectionBucket);
91 feedback_data->set_description(FormReport());
92
93 feedback_data->set_image(make_scoped_ptr(new std::string));
94
95 feedback_data->set_page_url("");
96 feedback_data->set_user_email("");
97 feedback_data->set_context(parent_->web_contents()->GetBrowserContext());
98 feedback_util::SendReport(feedback_data);
99 }
100
101 std::string
102 ManagePasswordsUIController::URLCollectionFeedbackSender::FormReport() {
103 base::DictionaryValue dict;
104 dict.SetString("url", parent_->origin().GetAsReferrer().spec());
105 std::string json;
106 base::JSONWriter::Write(&dict, &json);
107 return json;
108 }
61 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController); 109 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagePasswordsUIController);
62 110
63 ManagePasswordsUIController::ManagePasswordsUIController( 111 ManagePasswordsUIController::ManagePasswordsUIController(
64 content::WebContents* web_contents) 112 content::WebContents* web_contents)
65 : content::WebContentsObserver(web_contents), 113 : content::WebContentsObserver(web_contents),
66 state_(password_manager::ui::INACTIVE_STATE), 114 state_(password_manager::ui::INACTIVE_STATE),
67 bubble_shown_(false) { 115 bubble_shown_(false) {
68 password_manager::PasswordStore* password_store = 116 password_manager::PasswordStore* password_store =
69 GetPasswordStore(web_contents); 117 GetPasswordStore(web_contents);
70 if (password_store) 118 if (password_store)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 #endif 237 #endif
190 } 238 }
191 239
192 void ManagePasswordsUIController::SavePassword() { 240 void ManagePasswordsUIController::SavePassword() {
193 DCHECK(PasswordPendingUserDecision()); 241 DCHECK(PasswordPendingUserDecision());
194 SavePasswordInternal(); 242 SavePasswordInternal();
195 state_ = password_manager::ui::MANAGE_STATE; 243 state_ = password_manager::ui::MANAGE_STATE;
196 UpdateBubbleAndIconVisibility(); 244 UpdateBubbleAndIconVisibility();
197 } 245 }
198 246
247 void ManagePasswordsUIController::SendURLFeedback() {
248 ManagePasswordsUIController::URLCollectionFeedbackSender feedback_sender(
249 this);
250 feedback_sender.SendFeedback();
251 }
252
199 void ManagePasswordsUIController::ChooseCredential( 253 void ManagePasswordsUIController::ChooseCredential(
200 bool was_chosen, 254 bool was_chosen,
201 const autofill::PasswordForm& form) { 255 const autofill::PasswordForm& form) {
202 DCHECK(password_manager::ui::IsCredentialsState(state_)); 256 DCHECK(password_manager::ui::IsCredentialsState(state_));
203 DCHECK(!credentials_callback_.is_null()); 257 DCHECK(!credentials_callback_.is_null());
204 password_manager::CredentialInfo info = was_chosen ? 258 password_manager::CredentialInfo info = was_chosen ?
205 password_manager::CredentialInfo(form) : 259 password_manager::CredentialInfo(form) :
206 password_manager::CredentialInfo(); 260 password_manager::CredentialInfo();
207 credentials_callback_.Run(info); 261 credentials_callback_.Run(info);
208 state_ = password_manager::ui::INACTIVE_STATE; 262 state_ = password_manager::ui::INACTIVE_STATE;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 bool ManagePasswordsUIController::PasswordPendingUserDecision() const { 379 bool ManagePasswordsUIController::PasswordPendingUserDecision() const {
326 return password_manager::ui::IsPendingState(state_); 380 return password_manager::ui::IsPendingState(state_);
327 } 381 }
328 382
329 void ManagePasswordsUIController::WebContentsDestroyed() { 383 void ManagePasswordsUIController::WebContentsDestroyed() {
330 password_manager::PasswordStore* password_store = 384 password_manager::PasswordStore* password_store =
331 GetPasswordStore(web_contents()); 385 GetPasswordStore(web_contents());
332 if (password_store) 386 if (password_store)
333 password_store->RemoveObserver(this); 387 password_store->RemoveObserver(this);
334 } 388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698