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

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

Issue 9169096: Remove a bunch of GetProfileSyncService callers to use the new factory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm todos Created 8 years, 10 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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #include "chrome/browser/profiles/profile_manager.h" 81 #include "chrome/browser/profiles/profile_manager.h"
82 #include "chrome/browser/profiles/profile_metrics.h" 82 #include "chrome/browser/profiles/profile_metrics.h"
83 #include "chrome/browser/repost_form_warning_controller.h" 83 #include "chrome/browser/repost_form_warning_controller.h"
84 #include "chrome/browser/sessions/restore_tab_helper.h" 84 #include "chrome/browser/sessions/restore_tab_helper.h"
85 #include "chrome/browser/sessions/session_service.h" 85 #include "chrome/browser/sessions/session_service.h"
86 #include "chrome/browser/sessions/session_service_factory.h" 86 #include "chrome/browser/sessions/session_service_factory.h"
87 #include "chrome/browser/sessions/session_types.h" 87 #include "chrome/browser/sessions/session_types.h"
88 #include "chrome/browser/sessions/tab_restore_service.h" 88 #include "chrome/browser/sessions/tab_restore_service.h"
89 #include "chrome/browser/sessions/tab_restore_service_factory.h" 89 #include "chrome/browser/sessions/tab_restore_service_factory.h"
90 #include "chrome/browser/sync/profile_sync_service.h" 90 #include "chrome/browser/sync/profile_sync_service.h"
91 #include "chrome/browser/sync/profile_sync_service_factory.h"
91 #include "chrome/browser/sync/sync_ui_util.h" 92 #include "chrome/browser/sync/sync_ui_util.h"
92 #include "chrome/browser/tab_closeable_state_watcher.h" 93 #include "chrome/browser/tab_closeable_state_watcher.h"
93 #include "chrome/browser/tab_contents/background_contents.h" 94 #include "chrome/browser/tab_contents/background_contents.h"
94 #include "chrome/browser/tab_contents/retargeting_details.h" 95 #include "chrome/browser/tab_contents/retargeting_details.h"
95 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" 96 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
96 #include "chrome/browser/tab_contents/tab_util.h" 97 #include "chrome/browser/tab_contents/tab_util.h"
97 #include "chrome/browser/tabs/tab_finder.h" 98 #include "chrome/browser/tabs/tab_finder.h"
98 #include "chrome/browser/tabs/tab_strip_model.h" 99 #include "chrome/browser/tabs/tab_strip_model.h"
99 #include "chrome/browser/themes/theme_service.h" 100 #include "chrome/browser/themes/theme_service.h"
100 #include "chrome/browser/themes/theme_service_factory.h" 101 #include "chrome/browser/themes/theme_service_factory.h"
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // or you'll get a nasty surprise when you run the incognito tests. 390 // or you'll get a nasty surprise when you run the incognito tests.
390 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector, 391 encoding_auto_detect_.Init(prefs::kWebKitUsesUniversalDetector,
391 profile_->GetPrefs(), NULL); 392 profile_->GetPrefs(), NULL);
392 393
393 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile); 394 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile);
394 if (tab_restore_service_) { 395 if (tab_restore_service_) {
395 tab_restore_service_->AddObserver(this); 396 tab_restore_service_->AddObserver(this);
396 TabRestoreServiceChanged(tab_restore_service_); 397 TabRestoreServiceChanged(tab_restore_service_);
397 } 398 }
398 399
399 if (profile_->GetProfileSyncService()) 400 ProfileSyncService* service =
400 profile_->GetProfileSyncService()->AddObserver(this); 401 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
402 if (service)
403 service->AddObserver(this);
401 404
402 CreateInstantIfNecessary(); 405 CreateInstantIfNecessary();
403 406
404 // Make sure TabFinder has been created. This does nothing if TabFinder is 407 // Make sure TabFinder has been created. This does nothing if TabFinder is
405 // not enabled. 408 // not enabled.
406 TabFinder::GetInstance(); 409 TabFinder::GetInstance();
407 410
408 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT); 411 UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_INIT);
409 412
410 FilePath profile_path = profile->GetPath(); 413 FilePath profile_path = profile->GetPath();
411 ProfileMetrics::LogProfileLaunch(profile_path); 414 ProfileMetrics::LogProfileLaunch(profile_path);
412 } 415 }
413 416
414 Browser::~Browser() { 417 Browser::~Browser() {
415 if (profile_->GetProfileSyncService()) 418 ProfileSyncService* service =
416 profile_->GetProfileSyncService()->RemoveObserver(this); 419 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
420 if (service)
421 service->RemoveObserver(this);
417 422
418 BrowserList::RemoveBrowser(this); 423 BrowserList::RemoveBrowser(this);
419 424
420 #if !defined(OS_MACOSX) 425 #if !defined(OS_MACOSX)
421 if (!BrowserList::HasBrowserWithProfile(profile_)) { 426 if (!BrowserList::HasBrowserWithProfile(profile_)) {
422 // We're the last browser window with this profile. We need to nuke the 427 // We're the last browser window with this profile. We need to nuke the
423 // TabRestoreService, which will start the shutdown of the 428 // TabRestoreService, which will start the shutdown of the
424 // NavigationControllers and allow for proper shutdown. If we don't do this 429 // NavigationControllers and allow for proper shutdown. If we don't do this
425 // chrome won't shutdown cleanly, and may end up crashing when some 430 // chrome won't shutdown cleanly, and may end up crashing when some
426 // thread tries to use the IO thread (or another thread) that is no longer 431 // thread tries to use the IO thread (or another thread) that is no longer
(...skipping 3931 matching lines...) Expand 10 before | Expand all | Expand 10 after
4358 4363
4359 default: 4364 default:
4360 NOTREACHED() << "Got a notification we didn't register for."; 4365 NOTREACHED() << "Got a notification we didn't register for.";
4361 } 4366 }
4362 } 4367 }
4363 4368
4364 /////////////////////////////////////////////////////////////////////////////// 4369 ///////////////////////////////////////////////////////////////////////////////
4365 // Browser, ProfileSyncServiceObserver implementation: 4370 // Browser, ProfileSyncServiceObserver implementation:
4366 4371
4367 void Browser::OnStateChanged() { 4372 void Browser::OnStateChanged() {
4368 DCHECK(profile_->GetProfileSyncService()); 4373 DCHECK(ProfileSyncServiceFactory::GetInstance()->HasProfileSyncService(
4374 profile_));
4369 // For unit tests, we don't have a window. 4375 // For unit tests, we don't have a window.
4370 if (!window_) 4376 if (!window_)
4371 return; 4377 return;
4372 const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen()); 4378 const bool show_main_ui = IsShowingMainUI(window_->IsFullscreen());
4373 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS, 4379 command_updater_.UpdateCommandEnabled(IDC_SYNC_BOOKMARKS,
4374 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible()); 4380 show_main_ui && profile_->GetOriginalProfile()->IsSyncAccessible());
4375 } 4381 }
4376 4382
4377 /////////////////////////////////////////////////////////////////////////////// 4383 ///////////////////////////////////////////////////////////////////////////////
4378 // Browser, InstantDelegate implementation: 4384 // Browser, InstantDelegate implementation:
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
5459 5465
5460 BookmarkBar::AnimateChangeType animate_type = 5466 BookmarkBar::AnimateChangeType animate_type =
5461 (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ? 5467 (reason == BOOKMARK_BAR_STATE_CHANGE_PREF_CHANGE) ?
5462 BookmarkBar::ANIMATE_STATE_CHANGE : 5468 BookmarkBar::ANIMATE_STATE_CHANGE :
5463 BookmarkBar::DONT_ANIMATE_STATE_CHANGE; 5469 BookmarkBar::DONT_ANIMATE_STATE_CHANGE;
5464 window_->BookmarkBarStateChanged(animate_type); 5470 window_->BookmarkBarStateChanged(animate_type);
5465 } 5471 }
5466 5472
5467 void Browser::ShowSyncSetup() { 5473 void Browser::ShowSyncSetup() {
5468 ProfileSyncService* service = 5474 ProfileSyncService* service =
5469 profile()->GetOriginalProfile()->GetProfileSyncService(); 5475 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
5476 profile()->GetOriginalProfile());
5470 if (service->HasSyncSetupCompleted()) 5477 if (service->HasSyncSetupCompleted())
5471 ShowOptionsTab(chrome::kPersonalOptionsSubPage); 5478 ShowOptionsTab(chrome::kPersonalOptionsSubPage);
5472 else 5479 else
5473 service->ShowLoginDialog(); 5480 service->ShowLoginDialog();
5474 } 5481 }
5475 5482
5476 void Browser::ToggleSpeechInput() { 5483 void Browser::ToggleSpeechInput() {
5477 GetSelectedTabContentsWrapper()->web_contents()->GetRenderViewHost()-> 5484 GetSelectedTabContentsWrapper()->web_contents()->GetRenderViewHost()->
5478 ToggleSpeechInput(); 5485 ToggleSpeechInput();
5479 } 5486 }
(...skipping 19 matching lines...) Expand all
5499 local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, false); 5506 local_state->SetBoolean(prefs::kShouldShowFirstRunBubble, false);
5500 window_->GetLocationBar()->ShowFirstRunBubble(); 5507 window_->GetLocationBar()->ShowFirstRunBubble();
5501 } else { 5508 } else {
5502 GlobalErrorService* service = 5509 GlobalErrorService* service =
5503 GlobalErrorServiceFactory::GetForProfile(profile()); 5510 GlobalErrorServiceFactory::GetForProfile(profile());
5504 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView(); 5511 GlobalError* error = service->GetFirstGlobalErrorWithBubbleView();
5505 if (error) 5512 if (error)
5506 error->ShowBubbleView(this); 5513 error->ShowBubbleView(this);
5507 } 5514 }
5508 } 5515 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/auto_login_prompter.cc ('k') | chrome/browser/ui/toolbar/wrench_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698