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

Side by Side Diff: chrome/browser/profiles/profile_manager.cc

Issue 9853010: ProfileManager: Remove CHECKs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. 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
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <set> 5 #include <set>
6 6
7 #include "chrome/browser/profiles/profile_manager.h" 7 #include "chrome/browser/profiles/profile_manager.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 // Ignore any browsers closing from now on. 520 // Ignore any browsers closing from now on.
521 shutdown_started_ = true; 521 shutdown_started_ = true;
522 break; 522 break;
523 } 523 }
524 case chrome::NOTIFICATION_BROWSER_OPENED: { 524 case chrome::NOTIFICATION_BROWSER_OPENED: {
525 Browser* browser = content::Source<Browser>(source).ptr(); 525 Browser* browser = content::Source<Browser>(source).ptr();
526 DCHECK(browser); 526 DCHECK(browser);
527 Profile* profile = browser->profile(); 527 Profile* profile = browser->profile();
528 DCHECK(profile); 528 DCHECK(profile);
529 if (!profile->IsOffTheRecord() && ++browser_counts_[profile] == 1) { 529 if (!profile->IsOffTheRecord() && ++browser_counts_[profile] == 1) {
530 CHECK(std::find(active_profiles_.begin(), active_profiles_.end(),
531 profile) == active_profiles_.end());
532 active_profiles_.push_back(profile); 530 active_profiles_.push_back(profile);
533 update_active_profiles = true; 531 update_active_profiles = true;
534 } 532 }
535 break; 533 break;
536 } 534 }
537 case chrome::NOTIFICATION_BROWSER_CLOSED: { 535 case chrome::NOTIFICATION_BROWSER_CLOSED: {
538 Browser* browser = content::Source<Browser>(source).ptr(); 536 Browser* browser = content::Source<Browser>(source).ptr();
539 DCHECK(browser); 537 DCHECK(browser);
540 Profile* profile = browser->profile(); 538 Profile* profile = browser->profile();
541 DCHECK(profile); 539 DCHECK(profile);
542 if (!profile->IsOffTheRecord() && --browser_counts_[profile] == 0) { 540 if (!profile->IsOffTheRecord() && --browser_counts_[profile] == 0) {
543 CHECK(std::find(active_profiles_.begin(), active_profiles_.end(), 541 active_profiles_.erase(std::find(active_profiles_.begin(),
544 profile) != active_profiles_.end()); 542 active_profiles_.end(), profile));
545 active_profiles_.erase(
546 std::remove(active_profiles_.begin(), active_profiles_.end(),
547 profile),
548 active_profiles_.end());
549 CHECK(std::find(active_profiles_.begin(), active_profiles_.end(),
550 profile) == active_profiles_.end());
551 update_active_profiles = true; 543 update_active_profiles = true;
552 } 544 }
553 break; 545 break;
554 } 546 }
555 default: { 547 default: {
556 NOTREACHED(); 548 NOTREACHED();
557 break; 549 break;
558 } 550 }
559 } 551 }
560 if (update_active_profiles) { 552 if (update_active_profiles) {
561 PrefService* local_state = g_browser_process->local_state(); 553 PrefService* local_state = g_browser_process->local_state();
562 DCHECK(local_state); 554 DCHECK(local_state);
563 ListPrefUpdate update(local_state, prefs::kProfilesLastActive); 555 ListPrefUpdate update(local_state, prefs::kProfilesLastActive);
564 ListValue* profile_list = update.Get(); 556 ListValue* profile_list = update.Get();
565 557
566 profile_list->Clear(); 558 profile_list->Clear();
567 559
568 // Check that the same profile doesn't occur twice in last_opened_profiles. 560 // crbug.com/120112 -> several non-incognito profiles might have the same
569 { 561 // GetPath().BaseName(). In that case, we cannot restore both
570 std::set<Profile*> active_profiles_set; 562 // profiles. Include each base name only once in the last active profile
571 for (std::vector<Profile*>::const_iterator it = active_profiles_.begin(); 563 // list.
572 it != active_profiles_.end(); ++it) {
573 CHECK(active_profiles_set.find(*it) ==
574 active_profiles_set.end());
575 active_profiles_set.insert(*it);
576 }
577 }
578 // Used for checking that the string representations of the profiles differ.
579 std::set<std::string> profile_paths; 564 std::set<std::string> profile_paths;
580
581 std::vector<Profile*>::const_iterator it; 565 std::vector<Profile*>::const_iterator it;
582 for (it = active_profiles_.begin(); it != active_profiles_.end(); ++it) { 566 for (it = active_profiles_.begin(); it != active_profiles_.end(); ++it) {
583 std::string profile_path = (*it)->GetPath().BaseName().MaybeAsASCII(); 567 std::string profile_path = (*it)->GetPath().BaseName().MaybeAsASCII();
584 CHECK(profile_paths.find(profile_path) == 568 if (profile_paths.find(profile_path) == profile_paths.end()) {
585 profile_paths.end()); 569 profile_paths.insert(profile_path);
586 profile_paths.insert(profile_path); 570 profile_list->Append(new StringValue(profile_path));
587 profile_list->Append( 571 }
588 new StringValue((*it)->GetPath().BaseName().MaybeAsASCII()));
589 } 572 }
590 } 573 }
591 } 574 }
592 575
593 void ProfileManager::SetWillImport() { 576 void ProfileManager::SetWillImport() {
594 will_import_ = true; 577 will_import_ = true;
595 } 578 }
596 579
597 void ProfileManager::OnImportFinished(Profile* profile) { 580 void ProfileManager::OnImportFinished(Profile* profile) {
598 will_import_ = false; 581 will_import_ = false;
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 AddProfileToCache(profile); 945 AddProfileToCache(profile);
963 } 946 }
964 } 947 }
965 948
966 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks, 949 void ProfileManager::RunCallbacks(const std::vector<CreateCallback>& callbacks,
967 Profile* profile, 950 Profile* profile,
968 Profile::CreateStatus status) { 951 Profile::CreateStatus status) {
969 for (size_t i = 0; i < callbacks.size(); ++i) 952 for (size_t i = 0; i < callbacks.size(); ++i)
970 callbacks[i].Run(profile, status); 953 callbacks[i].Run(profile, status);
971 } 954 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698