| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ios/chrome/browser/ui/sync/sync_error_infobar_delegate.h" | 5 #include "ios/chrome/browser/ui/sync/sync_error_infobar_delegate.h" |
| 6 | 6 |
| 7 #import <UIKit/UIKit.h> | 7 #import <UIKit/UIKit.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/scoped_nsobject.h" | |
| 13 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 15 #include "components/browser_sync/profile_sync_service.h" | 14 #include "components/browser_sync/profile_sync_service.h" |
| 16 #include "components/infobars/core/infobar.h" | 15 #include "components/infobars/core/infobar.h" |
| 17 #include "components/infobars/core/infobar_delegate.h" | 16 #include "components/infobars/core/infobar_delegate.h" |
| 18 #include "components/infobars/core/infobar_manager.h" | 17 #include "components/infobars/core/infobar_manager.h" |
| 19 #include "components/sync/driver/sync_service.h" | 18 #include "components/sync/driver/sync_service.h" |
| 20 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" | 19 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 21 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" | 20 #include "ios/chrome/browser/sync/ios_chrome_profile_sync_service_factory.h" |
| 22 #include "ios/chrome/browser/sync/sync_setup_service.h" | 21 #include "ios/chrome/browser/sync/sync_setup_service.h" |
| 23 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" | 22 #include "ios/chrome/browser/sync/sync_setup_service_factory.h" |
| 24 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 23 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 25 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 24 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 26 #import "ios/chrome/browser/ui/sync/sync_util.h" | 25 #import "ios/chrome/browser/ui/sync/sync_util.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 28 | 27 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." |
| 30 #endif |
| 31 |
| 29 // static | 32 // static |
| 30 bool SyncErrorInfoBarDelegate::Create(infobars::InfoBarManager* infobar_manager, | 33 bool SyncErrorInfoBarDelegate::Create(infobars::InfoBarManager* infobar_manager, |
| 31 ios::ChromeBrowserState* browser_state) { | 34 ios::ChromeBrowserState* browser_state) { |
| 32 DCHECK(infobar_manager); | 35 DCHECK(infobar_manager); |
| 33 std::unique_ptr<ConfirmInfoBarDelegate> delegate( | 36 std::unique_ptr<ConfirmInfoBarDelegate> delegate( |
| 34 new SyncErrorInfoBarDelegate(browser_state)); | 37 new SyncErrorInfoBarDelegate(browser_state)); |
| 35 return !!infobar_manager->AddInfoBar( | 38 return !!infobar_manager->AddInfoBar( |
| 36 infobar_manager->CreateConfirmInfoBar(std::move(delegate))); | 39 infobar_manager->CreateConfirmInfoBar(std::move(delegate))); |
| 37 } | 40 } |
| 38 | 41 |
| 39 SyncErrorInfoBarDelegate::SyncErrorInfoBarDelegate( | 42 SyncErrorInfoBarDelegate::SyncErrorInfoBarDelegate( |
| 40 ios::ChromeBrowserState* browser_state) | 43 ios::ChromeBrowserState* browser_state) |
| 41 : browser_state_(browser_state) { | 44 : browser_state_(browser_state) { |
| 42 DCHECK(!browser_state->IsOffTheRecord()); | 45 DCHECK(!browser_state->IsOffTheRecord()); |
| 43 icon_ = gfx::Image([UIImage imageNamed:@"infobar_warning"]); | 46 icon_ = gfx::Image([UIImage imageNamed:@"infobar_warning"]); |
| 44 SyncSetupService* sync_setup_service = | 47 SyncSetupService* sync_setup_service = |
| 45 SyncSetupServiceFactory::GetForBrowserState(browser_state); | 48 SyncSetupServiceFactory::GetForBrowserState(browser_state); |
| 46 DCHECK(sync_setup_service); | 49 DCHECK(sync_setup_service); |
| 47 // Set all of the UI based on the sync state at the same time to ensure | 50 // Set all of the UI based on the sync state at the same time to ensure |
| 48 // they all correspond to the same sync error. | 51 // they all correspond to the same sync error. |
| 49 error_state_ = sync_setup_service->GetSyncServiceState(); | 52 error_state_ = sync_setup_service->GetSyncServiceState(); |
| 50 message_ = base::SysNSStringToUTF16( | 53 message_ = base::SysNSStringToUTF16( |
| 51 ios_internal::sync::GetSyncErrorMessageForBrowserState(browser_state_)); | 54 ios_internal::sync::GetSyncErrorMessageForBrowserState(browser_state_)); |
| 52 button_text_ = base::SysNSStringToUTF16( | 55 button_text_ = base::SysNSStringToUTF16( |
| 53 ios_internal::sync::GetSyncErrorButtonTitleForBrowserState( | 56 ios_internal::sync::GetSyncErrorButtonTitleForBrowserState( |
| 54 browser_state_)); | 57 browser_state_)); |
| 55 command_.reset([ios_internal::sync::GetSyncCommandForBrowserState( | 58 command_.reset( |
| 56 browser_state_) retain]); | 59 ios_internal::sync::GetSyncCommandForBrowserState(browser_state_)); |
| 57 | 60 |
| 58 // Register for sync status changes. | 61 // Register for sync status changes. |
| 59 syncer::SyncService* sync_service = | 62 syncer::SyncService* sync_service = |
| 60 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); | 63 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| 61 sync_service->AddObserver(this); | 64 sync_service->AddObserver(this); |
| 62 } | 65 } |
| 63 | 66 |
| 64 SyncErrorInfoBarDelegate::~SyncErrorInfoBarDelegate() { | 67 SyncErrorInfoBarDelegate::~SyncErrorInfoBarDelegate() { |
| 65 syncer::SyncService* sync_service = | 68 syncer::SyncService* sync_service = |
| 66 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); | 69 IOSChromeProfileSyncServiceFactory::GetForBrowserState(browser_state_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 infobars::InfoBarManager* infobar_manager = infobar->owner(); | 119 infobars::InfoBarManager* infobar_manager = infobar->owner(); |
| 117 if (infobar_manager) { | 120 if (infobar_manager) { |
| 118 std::unique_ptr<ConfirmInfoBarDelegate> new_infobar_delegate( | 121 std::unique_ptr<ConfirmInfoBarDelegate> new_infobar_delegate( |
| 119 new SyncErrorInfoBarDelegate(browser_state_)); | 122 new SyncErrorInfoBarDelegate(browser_state_)); |
| 120 infobar_manager->ReplaceInfoBar(infobar, | 123 infobar_manager->ReplaceInfoBar(infobar, |
| 121 infobar_manager->CreateConfirmInfoBar( | 124 infobar_manager->CreateConfirmInfoBar( |
| 122 std::move(new_infobar_delegate))); | 125 std::move(new_infobar_delegate))); |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 } | 128 } |
| OLD | NEW |