| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" | 5 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
| 10 #include "base/scoped_nsobject.h" | 10 #include "base/scoped_nsobject.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 - (id)initWithProfile:(Profile*)profile { | 116 - (id)initWithProfile:(Profile*)profile { |
| 117 DCHECK(profile); | 117 DCHECK(profile); |
| 118 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we | 118 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we |
| 119 // can override it in a unit test. | 119 // can override it in a unit test. |
| 120 NSString *nibpath = [mac_util::MainAppBundle() | 120 NSString *nibpath = [mac_util::MainAppBundle() |
| 121 pathForResource:@"ClearBrowsingData" | 121 pathForResource:@"ClearBrowsingData" |
| 122 ofType:@"nib"]; | 122 ofType:@"nib"]; |
| 123 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 123 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 124 profile_ = profile; |
| 124 observer_.reset(new ClearBrowsingObserver(self)); | 125 observer_.reset(new ClearBrowsingObserver(self)); |
| 125 | 126 profile_->GetProfileSyncService()->ResetClearServerDataState(); |
| 126 // Always show preferences for the original profile. Most state when off | 127 profile_->GetProfileSyncService()->AddObserver(observer_.get()); |
| 127 // the record comes from the original profile, but we explicitly use | |
| 128 // the original profile to avoid potential problems. | |
| 129 profile_ = profile->GetOriginalProfile(); | |
| 130 sync_service_ = profile_->GetProfileSyncService(); | |
| 131 | |
| 132 if (sync_service_) { | |
| 133 sync_service_->ResetClearServerDataState(); | |
| 134 sync_service_->AddObserver(observer_.get()); | |
| 135 } | |
| 136 | |
| 137 [self initFromPrefs]; | 128 [self initFromPrefs]; |
| 138 } | 129 } |
| 139 return self; | 130 return self; |
| 140 } | 131 } |
| 141 | 132 |
| 142 - (void)dealloc { | 133 - (void)dealloc { |
| 143 if (remover_) { | 134 if (remover_) { |
| 144 // We were destroyed while clearing history was in progress. This can only | 135 // We were destroyed while clearing history was in progress. This can only |
| 145 // occur during automated tests (normally the user can't close the dialog | 136 // occur during automated tests (normally the user can't close the dialog |
| 146 // while clearing is in progress as the dialog is modal and not closeable). | 137 // while clearing is in progress as the dialog is modal and not closeable). |
| 147 remover_->RemoveObserver(observer_.get()); | 138 remover_->RemoveObserver(observer_.get()); |
| 148 } | 139 } |
| 149 if (sync_service_) | 140 profile_->GetProfileSyncService()->RemoveObserver(observer_.get()); |
| 150 sync_service_->RemoveObserver(observer_.get()); | |
| 151 [self setClearingStatus:nil]; | 141 [self setClearingStatus:nil]; |
| 152 | 142 |
| 153 [super dealloc]; | 143 [super dealloc]; |
| 154 } | 144 } |
| 155 | 145 |
| 156 // Run application modal. | 146 // Run application modal. |
| 157 - (void)runModalDialog { | 147 - (void)runModalDialog { |
| 158 // Check again to make sure there is only one window. Since we use | 148 // Check again to make sure there is only one window. Since we use |
| 159 // |performSelector:afterDelay:| it is possible for this to somehow be | 149 // |performSelector:afterDelay:| it is possible for this to somehow be |
| 160 // triggered twice. | 150 // triggered twice. |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 [self setClearingStatus:nil]; | 334 [self setClearingStatus:nil]; |
| 345 [self setIsClearing:NO]; | 335 [self setIsClearing:NO]; |
| 346 remover_ = NULL; | 336 remover_ = NULL; |
| 347 } | 337 } |
| 348 | 338 |
| 349 - (IBAction)stopSyncAndDeleteData:(id)sender { | 339 - (IBAction)stopSyncAndDeleteData:(id)sender { |
| 350 // Protect against the unlikely case where the server received a message, and | 340 // Protect against the unlikely case where the server received a message, and |
| 351 // the syncer syncs and resets itself before the user tries pressing the Clear | 341 // the syncer syncs and resets itself before the user tries pressing the Clear |
| 352 // button in this dialog again. TODO(raz) Confirm whether we have an issue | 342 // button in this dialog again. TODO(raz) Confirm whether we have an issue |
| 353 // here | 343 // here |
| 354 if (sync_service_->HasSyncSetupCompleted()) { | 344 if (profile_->GetProfileSyncService()->HasSyncSetupCompleted()) { |
| 355 bool clear = platform_util::SimpleYesNoBox( | 345 bool clear = platform_util::SimpleYesNoBox( |
| 356 nil, | 346 nil, |
| 357 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_TITLE), | 347 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_TITLE), |
| 358 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_DESCRIPTION)); | 348 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_DESCRIPTION)); |
| 359 if (clear) { | 349 if (clear) { |
| 360 sync_service_->ClearServerData(); | 350 profile_->GetProfileSyncService()->ClearServerData(); |
| 361 [self syncStateChanged]; | 351 [self syncStateChanged]; |
| 362 } | 352 } |
| 363 } | 353 } |
| 364 } | 354 } |
| 365 | 355 |
| 366 - (void)syncStateChanged { | 356 - (void)syncStateChanged { |
| 367 bool deleteInProgress = false; | 357 bool deleteInProgress = false; |
| 368 | 358 |
| 369 ProfileSyncService::ClearServerDataState clearState = | 359 ProfileSyncService::ClearServerDataState clearState = |
| 370 sync_service_->GetClearServerDataState(); | 360 profile_->GetProfileSyncService()->GetClearServerDataState(); |
| 371 sync_service_->ResetClearServerDataState(); | 361 profile_->GetProfileSyncService()->ResetClearServerDataState(); |
| 372 | 362 |
| 373 switch (clearState) { | 363 switch (clearState) { |
| 374 case ProfileSyncService::CLEAR_NOT_STARTED: | 364 case ProfileSyncService::CLEAR_NOT_STARTED: |
| 375 // This can occur on a first start and after a failed clear (which does | 365 // This can occur on a first start and after a failed clear (which does |
| 376 // not close the tab). Do nothing. | 366 // not close the tab). Do nothing. |
| 377 break; | 367 break; |
| 378 case ProfileSyncService::CLEAR_CLEARING: | 368 case ProfileSyncService::CLEAR_CLEARING: |
| 379 // Clearing buttons on all tabs are disabled at this point, throbber is | 369 // Clearing buttons on all tabs are disabled at this point, throbber is |
| 380 // going. | 370 // going. |
| 381 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_SENDING)]; | 371 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_SENDING)]; |
| 382 deleteInProgress = true; | 372 deleteInProgress = true; |
| 383 break; | 373 break; |
| 384 case ProfileSyncService::CLEAR_FAILED: | 374 case ProfileSyncService::CLEAR_FAILED: |
| 385 // Show an error and reallow clearing. | 375 // Show an error and reallow clearing. |
| 386 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_ERROR)]; | 376 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_ERROR)]; |
| 387 deleteInProgress = false; | 377 deleteInProgress = false; |
| 388 break; | 378 break; |
| 389 case ProfileSyncService::CLEAR_SUCCEEDED: | 379 case ProfileSyncService::CLEAR_SUCCEEDED: |
| 390 // Close the dialog box, success! | 380 // Close the dialog box, success! |
| 391 [self setClearingStatus:nil]; | 381 [self setClearingStatus:nil]; |
| 392 deleteInProgress = false; | 382 deleteInProgress = false; |
| 393 [self closeDialog]; | 383 [self closeDialog]; |
| 394 break; | 384 break; |
| 395 } | 385 } |
| 396 | 386 |
| 397 [self setIsClearing:deleteInProgress]; | 387 [self setIsClearing:deleteInProgress]; |
| 398 } | 388 } |
| 399 | 389 |
| 400 - (BOOL)isSyncVisible { | 390 - (BOOL)isSyncEnabled { |
| 401 return CommandLine::ForCurrentProcess()->HasSwitch( | 391 BOOL allowClearServerDataUI = |
| 402 switches::kEnableClearServerData); | 392 CommandLine::ForCurrentProcess()->HasSwitch( |
| 403 } | 393 switches::kEnableClearServerData); |
| 404 | 394 |
| 405 - (BOOL)isSyncEnabled { | 395 return allowClearServerDataUI && |
| 406 return sync_service_ && sync_service_->HasSyncSetupCompleted(); | 396 profile_->GetProfileSyncService()->HasSyncSetupCompleted(); |
| 407 } | 397 } |
| 408 | 398 |
| 409 - (NSFont*)labelFont { | 399 - (NSFont*)labelFont { |
| 410 return [NSFont boldSystemFontOfSize:13]; | 400 return [NSFont boldSystemFontOfSize:13]; |
| 411 } | 401 } |
| 412 | 402 |
| 413 @end | 403 @end |
| OLD | NEW |