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

Side by Side Diff: chrome/browser/permissions/permission_request_manager.cc

Issue 2922933002: Remove |accept_states_| from PermissionRequestManager (Closed)
Patch Set: Remove |accept_states_| from PermissionRequestManager Created 3 years, 6 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
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/permissions/permission_request_manager.h" 5 #include "chrome/browser/permissions/permission_request_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 for (queued_requests_iter = queued_requests_.begin(); 174 for (queued_requests_iter = queued_requests_.begin();
175 queued_requests_iter != queued_requests_.end(); queued_requests_iter++) { 175 queued_requests_iter != queued_requests_.end(); queued_requests_iter++) {
176 if (*queued_requests_iter == request) { 176 if (*queued_requests_iter == request) {
177 RequestFinishedIncludingDuplicates(*queued_requests_iter); 177 RequestFinishedIncludingDuplicates(*queued_requests_iter);
178 queued_requests_.erase(queued_requests_iter); 178 queued_requests_.erase(queued_requests_iter);
179 return; 179 return;
180 } 180 }
181 } 181 }
182 182
183 std::vector<PermissionRequest*>::iterator requests_iter; 183 std::vector<PermissionRequest*>::iterator requests_iter;
184 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); 184 for (requests_iter = requests_.begin(); requests_iter != requests_.end();
185 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); 185 requests_iter++) {
186 requests_iter != requests_.end();
187 requests_iter++, accepts_iter++) {
188 if (*requests_iter != request) 186 if (*requests_iter != request)
189 continue; 187 continue;
190 188
191 // We can simply erase the current entry in the request table if we aren't 189 // We can simply erase the current entry in the request table if we aren't
192 // showing the dialog, or if we are showing it and it can accept the update. 190 // showing the dialog, or if we are showing it and it can accept the update.
193 bool can_erase = !view_ || view_->CanAcceptRequestUpdate(); 191 bool can_erase = !view_ || view_->CanAcceptRequestUpdate();
194 if (can_erase) { 192 if (can_erase) {
195 RequestFinishedIncludingDuplicates(*requests_iter); 193 RequestFinishedIncludingDuplicates(*requests_iter);
196 requests_.erase(requests_iter); 194 requests_.erase(requests_iter);
197 accept_states_.erase(accepts_iter);
198 195
199 if (view_) { 196 if (view_) {
200 view_->Hide(); 197 view_->Hide();
201 // Will redraw the bubble if it is being shown. 198 // Will redraw the bubble if it is being shown.
202 DequeueRequestsAndShowBubble(); 199 DequeueRequestsAndShowBubble();
203 } 200 }
204 return; 201 return;
205 } 202 }
206 203
207 // Cancel the existing request and replace it with a dummy. 204 // Cancel the existing request and replace it with a dummy.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 web_contents()->RemoveUserData(UserDataKey()); 318 web_contents()->RemoveUserData(UserDataKey());
322 // That was the equivalent of "delete this". This object is now destroyed; 319 // That was the equivalent of "delete this". This object is now destroyed;
323 // returning from this function is the only safe thing to do. 320 // returning from this function is the only safe thing to do.
324 } 321 }
325 322
326 const std::vector<PermissionRequest*>& PermissionRequestManager::Requests() { 323 const std::vector<PermissionRequest*>& PermissionRequestManager::Requests() {
327 return requests_; 324 return requests_;
328 } 325 }
329 326
330 const std::vector<bool>& PermissionRequestManager::AcceptStates() { 327 const std::vector<bool>& PermissionRequestManager::AcceptStates() {
331 return accept_states_; 328 // TODO(crbug.com/728483): Remove this function.
329 CR_DEFINE_STATIC_LOCAL(std::vector<bool>, accept_states, ());
330 return accept_states;
332 } 331 }
333 332
334 void PermissionRequestManager::ToggleAccept(int request_index, bool new_value) { 333 void PermissionRequestManager::ToggleAccept(int request_index, bool new_value) {
335 DCHECK(request_index < static_cast<int>(accept_states_.size())); 334 // TODO(crbug.com/728483): Remove this function.
336 accept_states_[request_index] = new_value;
337 } 335 }
338 336
339 void PermissionRequestManager::TogglePersist(bool new_value) { 337 void PermissionRequestManager::TogglePersist(bool new_value) {
340 persist_ = new_value; 338 persist_ = new_value;
341 } 339 }
342 340
343 void PermissionRequestManager::Accept() { 341 void PermissionRequestManager::Accept() {
344 PermissionUmaUtil::PermissionPromptAccepted(requests_, accept_states_); 342 PermissionUmaUtil::PermissionPromptAccepted(requests_);
345 343
346 std::vector<PermissionRequest*>::iterator requests_iter; 344 std::vector<PermissionRequest*>::iterator requests_iter;
347 std::vector<bool>::iterator accepts_iter = accept_states_.begin(); 345 for (requests_iter = requests_.begin(); requests_iter != requests_.end();
348 for (requests_iter = requests_.begin(), accepts_iter = accept_states_.begin(); 346 requests_iter++) {
349 requests_iter != requests_.end(); 347 PermissionGrantedIncludingDuplicates(*requests_iter);
350 requests_iter++, accepts_iter++) {
351 if (*accepts_iter) {
352 PermissionGrantedIncludingDuplicates(*requests_iter);
353 } else {
354 PermissionDeniedIncludingDuplicates(*requests_iter);
355 }
356 } 348 }
357 FinalizeBubble(); 349 FinalizeBubble();
358 } 350 }
359 351
360 void PermissionRequestManager::Deny() { 352 void PermissionRequestManager::Deny() {
361 DCHECK_EQ(1u, requests_.size());
362 PermissionUmaUtil::PermissionPromptDenied(requests_); 353 PermissionUmaUtil::PermissionPromptDenied(requests_);
363 354
364 std::vector<PermissionRequest*>::iterator requests_iter; 355 std::vector<PermissionRequest*>::iterator requests_iter;
365 for (requests_iter = requests_.begin(); 356 for (requests_iter = requests_.begin();
366 requests_iter != requests_.end(); 357 requests_iter != requests_.end();
367 requests_iter++) { 358 requests_iter++) {
368 PermissionDeniedIncludingDuplicates(*requests_iter); 359 PermissionDeniedIncludingDuplicates(*requests_iter);
369 } 360 }
370 FinalizeBubble(); 361 FinalizeBubble();
371 } 362 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 395
405 requests_.push_back(queued_requests_.front()); 396 requests_.push_back(queued_requests_.front());
406 queued_requests_.pop_front(); 397 queued_requests_.pop_front();
407 398
408 if (!queued_requests_.empty() && 399 if (!queued_requests_.empty() &&
409 ShouldGroupRequests(requests_.front(), queued_requests_.front())) { 400 ShouldGroupRequests(requests_.front(), queued_requests_.front())) {
410 requests_.push_back(queued_requests_.front()); 401 requests_.push_back(queued_requests_.front());
411 queued_requests_.pop_front(); 402 queued_requests_.pop_front();
412 } 403 }
413 404
414 // Sets the default value for each request to be 'accept'.
415 accept_states_.resize(requests_.size(), true);
416
417 ShowBubble(); 405 ShowBubble();
418 } 406 }
419 407
420 void PermissionRequestManager::ShowBubble() { 408 void PermissionRequestManager::ShowBubble() {
421 DCHECK(view_); 409 DCHECK(view_);
422 DCHECK(!requests_.empty()); 410 DCHECK(!requests_.empty());
423 DCHECK(main_frame_has_fully_loaded_); 411 DCHECK(main_frame_has_fully_loaded_);
424 412
425 view_->Show(); 413 view_->Show();
426 PermissionUmaUtil::PermissionPromptShown(requests_); 414 PermissionUmaUtil::PermissionPromptShown(requests_);
427 NotifyBubbleAdded(); 415 NotifyBubbleAdded();
428 416
429 // If in testing mode, automatically respond to the bubble that was shown. 417 // If in testing mode, automatically respond to the bubble that was shown.
430 if (auto_response_for_test_ != NONE) 418 if (auto_response_for_test_ != NONE)
431 DoAutoResponseForTesting(); 419 DoAutoResponseForTesting();
432 } 420 }
433 421
434 void PermissionRequestManager::FinalizeBubble() { 422 void PermissionRequestManager::FinalizeBubble() {
435 if (view_ && !view_->HidesAutomatically()) 423 if (view_ && !view_->HidesAutomatically())
436 view_->Hide(); 424 view_->Hide();
437 425
438 std::vector<PermissionRequest*>::iterator requests_iter; 426 std::vector<PermissionRequest*>::iterator requests_iter;
439 for (requests_iter = requests_.begin(); 427 for (requests_iter = requests_.begin();
440 requests_iter != requests_.end(); 428 requests_iter != requests_.end();
441 requests_iter++) { 429 requests_iter++) {
442 RequestFinishedIncludingDuplicates(*requests_iter); 430 RequestFinishedIncludingDuplicates(*requests_iter);
443 } 431 }
444 requests_.clear(); 432 requests_.clear();
445 accept_states_.clear();
446 if (queued_requests_.size()) 433 if (queued_requests_.size())
447 DequeueRequestsAndShowBubble(); 434 DequeueRequestsAndShowBubble();
448 } 435 }
449 436
450 void PermissionRequestManager::CancelPendingQueues() { 437 void PermissionRequestManager::CancelPendingQueues() {
451 std::deque<PermissionRequest*>::iterator requests_iter; 438 std::deque<PermissionRequest*>::iterator requests_iter;
452 for (requests_iter = queued_requests_.begin(); 439 for (requests_iter = queued_requests_.begin();
453 requests_iter != queued_requests_.end(); 440 requests_iter != queued_requests_.end();
454 requests_iter++) { 441 requests_iter++) {
455 RequestFinishedIncludingDuplicates(*requests_iter); 442 RequestFinishedIncludingDuplicates(*requests_iter);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 for (Observer& observer : observer_list_) 517 for (Observer& observer : observer_list_)
531 observer.OnBubbleAdded(); 518 observer.OnBubbleAdded();
532 } 519 }
533 520
534 void PermissionRequestManager::DoAutoResponseForTesting() { 521 void PermissionRequestManager::DoAutoResponseForTesting() {
535 switch (auto_response_for_test_) { 522 switch (auto_response_for_test_) {
536 case ACCEPT_ALL: 523 case ACCEPT_ALL:
537 Accept(); 524 Accept();
538 break; 525 break;
539 case DENY_ALL: 526 case DENY_ALL:
540 // Deny() assumes there is only 1 request. 527 Deny();
541 if (accept_states_.size() == 1) {
542 Deny();
543 } else {
544 for (size_t i = 0; i < accept_states_.size(); ++i)
545 accept_states_[i] = false;
546 Accept();
547 }
548 break; 528 break;
549 case DISMISS: 529 case DISMISS:
550 Closing(); 530 Closing();
551 break; 531 break;
552 case NONE: 532 case NONE:
553 NOTREACHED(); 533 NOTREACHED();
554 } 534 }
555 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698