Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/sync/sync_global_error.h" | 5 #include "chrome/browser/sync/sync_global_error.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/sync/sync_ui_util.h" | 8 #include "chrome/browser/sync/sync_ui_util.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
| 11 #include "chrome/browser/ui/chrome_pages.h" | 11 #include "chrome/browser/ui/chrome_pages.h" |
| 12 #include "chrome/browser/ui/global_error/global_error_service.h" | 12 #include "chrome/browser/ui/global_error/global_error_service.h" |
|
sky
2017/02/23 20:44:52
Remove include?
jlebel
2017/03/06 13:09:29
Done.
| |
| 13 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 13 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/browser_sync/profile_sync_service.h" | 16 #include "components/browser_sync/profile_sync_service.h" |
| 17 #include "components/signin/core/common/profile_management_switches.h" | 17 #include "components/signin/core/common/profile_management_switches.h" |
| 18 #include "google_apis/gaia/google_service_auth_error.h" | 18 #include "google_apis/gaia/google_service_auth_error.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 SyncGlobalError::SyncGlobalError( | 21 SyncGlobalError::SyncGlobalError( |
| 22 GlobalErrorService* global_error_service, | |
| 23 LoginUIService* login_ui_service, | 22 LoginUIService* login_ui_service, |
| 24 syncer::SyncErrorController* error_controller, | 23 syncer::SyncErrorController* error_controller, |
| 25 browser_sync::ProfileSyncService* profile_sync_service) | 24 browser_sync::ProfileSyncService* profile_sync_service) |
| 26 : global_error_service_(global_error_service), | 25 : login_ui_service_(login_ui_service), |
| 27 login_ui_service_(login_ui_service), | |
| 28 error_controller_(error_controller), | 26 error_controller_(error_controller), |
| 29 sync_service_(profile_sync_service) { | 27 sync_service_(profile_sync_service) { |
| 30 DCHECK(sync_service_); | 28 DCHECK(sync_service_); |
| 31 error_controller_->AddObserver(this); | 29 error_controller_->AddObserver(this); |
| 32 if (!switches::IsMaterialDesignUserMenu()) | |
| 33 global_error_service_->AddUnownedGlobalError(this); | |
|
sky
2017/02/23 20:44:52
Who owns this class now?
jlebel
2017/03/06 13:09:29
Are you talking about SyncGlobalError?
SyncGlobal
sky
2017/03/06 18:50:40
Acknowledged.
| |
| 34 } | 30 } |
| 35 | 31 |
| 36 SyncGlobalError::~SyncGlobalError() { | 32 SyncGlobalError::~SyncGlobalError() { |
| 37 DCHECK(!error_controller_) | 33 DCHECK(!error_controller_) |
| 38 << "SyncGlobalError::Shutdown() was not called"; | 34 << "SyncGlobalError::Shutdown() was not called"; |
| 39 } | 35 } |
| 40 | 36 |
| 41 void SyncGlobalError::Shutdown() { | 37 void SyncGlobalError::Shutdown() { |
| 42 if (!switches::IsMaterialDesignUserMenu()) | |
| 43 global_error_service_->RemoveUnownedGlobalError(this); | |
| 44 error_controller_->RemoveObserver(this); | 38 error_controller_->RemoveObserver(this); |
| 45 error_controller_ = nullptr; | 39 error_controller_ = nullptr; |
| 46 } | 40 } |
| 47 | 41 |
| 48 bool SyncGlobalError::HasMenuItem() { | 42 bool SyncGlobalError::HasMenuItem() { |
| 49 return !menu_label_.empty(); | 43 return !menu_label_.empty(); |
| 50 } | 44 } |
| 51 | 45 |
| 52 int SyncGlobalError::MenuItemCommandID() { | 46 int SyncGlobalError::MenuItemCommandID() { |
| 53 return IDC_SHOW_SYNC_ERROR; | 47 return IDC_SHOW_SYNC_ERROR; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 | 85 |
| 92 void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { | 86 void SyncGlobalError::BubbleViewAcceptButtonPressed(Browser* browser) { |
| 93 ExecuteMenuItem(browser); | 87 ExecuteMenuItem(browser); |
| 94 } | 88 } |
| 95 | 89 |
| 96 void SyncGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { | 90 void SyncGlobalError::BubbleViewCancelButtonPressed(Browser* browser) { |
| 97 NOTREACHED(); | 91 NOTREACHED(); |
| 98 } | 92 } |
| 99 | 93 |
| 100 void SyncGlobalError::OnErrorChanged() { | 94 void SyncGlobalError::OnErrorChanged() { |
| 101 if (switches::IsMaterialDesignUserMenu()) | |
| 102 return; | |
| 103 | |
| 104 base::string16 menu_label; | |
| 105 base::string16 bubble_message; | |
| 106 base::string16 bubble_accept_label; | |
| 107 sync_ui_util::GetStatusLabelsForSyncGlobalError( | |
| 108 sync_service_, &menu_label, &bubble_message, &bubble_accept_label); | |
| 109 | |
| 110 // All the labels should be empty or all of them non-empty. | |
| 111 DCHECK((menu_label.empty() && bubble_message.empty() && | |
| 112 bubble_accept_label.empty()) || | |
| 113 (!menu_label.empty() && !bubble_message.empty() && | |
| 114 !bubble_accept_label.empty())); | |
| 115 | |
| 116 if (menu_label != menu_label_ || bubble_message != bubble_message_ || | |
| 117 bubble_accept_label != bubble_accept_label_) { | |
| 118 menu_label_ = menu_label; | |
| 119 bubble_message_ = bubble_message; | |
| 120 bubble_accept_label_ = bubble_accept_label; | |
| 121 | |
| 122 global_error_service_->NotifyErrorsChanged(this); | |
| 123 } | |
| 124 } | 95 } |
| OLD | NEW |