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

Side by Side Diff: chrome/browser/cocoa/clear_browsing_data_controller.mm

Issue 3674005: [Mac] Update Clear Browsing dialog for proper functioning from incognito wind... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 2 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/cocoa/clear_browsing_data_controller.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) 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
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;
125 observer_.reset(new ClearBrowsingObserver(self)); 124 observer_.reset(new ClearBrowsingObserver(self));
126 profile_->GetProfileSyncService()->ResetClearServerDataState(); 125
127 profile_->GetProfileSyncService()->AddObserver(observer_.get()); 126 // Always show preferences for the original profile. Most state when off
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
128 [self initFromPrefs]; 137 [self initFromPrefs];
129 } 138 }
130 return self; 139 return self;
131 } 140 }
132 141
133 - (void)dealloc { 142 - (void)dealloc {
134 if (remover_) { 143 if (remover_) {
135 // We were destroyed while clearing history was in progress. This can only 144 // We were destroyed while clearing history was in progress. This can only
136 // occur during automated tests (normally the user can't close the dialog 145 // occur during automated tests (normally the user can't close the dialog
137 // while clearing is in progress as the dialog is modal and not closeable). 146 // while clearing is in progress as the dialog is modal and not closeable).
138 remover_->RemoveObserver(observer_.get()); 147 remover_->RemoveObserver(observer_.get());
139 } 148 }
140 profile_->GetProfileSyncService()->RemoveObserver(observer_.get()); 149 if (sync_service_)
150 sync_service_->RemoveObserver(observer_.get());
141 [self setClearingStatus:nil]; 151 [self setClearingStatus:nil];
142 152
143 [super dealloc]; 153 [super dealloc];
144 } 154 }
145 155
146 // Run application modal. 156 // Run application modal.
147 - (void)runModalDialog { 157 - (void)runModalDialog {
148 // Check again to make sure there is only one window. Since we use 158 // Check again to make sure there is only one window. Since we use
149 // |performSelector:afterDelay:| it is possible for this to somehow be 159 // |performSelector:afterDelay:| it is possible for this to somehow be
150 // triggered twice. 160 // triggered twice.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 [self setClearingStatus:nil]; 344 [self setClearingStatus:nil];
335 [self setIsClearing:NO]; 345 [self setIsClearing:NO];
336 remover_ = NULL; 346 remover_ = NULL;
337 } 347 }
338 348
339 - (IBAction)stopSyncAndDeleteData:(id)sender { 349 - (IBAction)stopSyncAndDeleteData:(id)sender {
340 // Protect against the unlikely case where the server received a message, and 350 // Protect against the unlikely case where the server received a message, and
341 // the syncer syncs and resets itself before the user tries pressing the Clear 351 // the syncer syncs and resets itself before the user tries pressing the Clear
342 // button in this dialog again. TODO(raz) Confirm whether we have an issue 352 // button in this dialog again. TODO(raz) Confirm whether we have an issue
343 // here 353 // here
344 if (profile_->GetProfileSyncService()->HasSyncSetupCompleted()) { 354 if (sync_service_->HasSyncSetupCompleted()) {
345 bool clear = platform_util::SimpleYesNoBox( 355 bool clear = platform_util::SimpleYesNoBox(
346 nil, 356 nil,
347 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_TITLE), 357 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_TITLE),
348 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_DESCRIPTION)); 358 l10n_util::GetStringUTF16(IDS_CONFIRM_CLEAR_DESCRIPTION));
349 if (clear) { 359 if (clear) {
350 profile_->GetProfileSyncService()->ClearServerData(); 360 sync_service_->ClearServerData();
351 [self syncStateChanged]; 361 [self syncStateChanged];
352 } 362 }
353 } 363 }
354 } 364 }
355 365
356 - (void)syncStateChanged { 366 - (void)syncStateChanged {
357 bool deleteInProgress = false; 367 bool deleteInProgress = false;
358 368
359 ProfileSyncService::ClearServerDataState clearState = 369 ProfileSyncService::ClearServerDataState clearState =
360 profile_->GetProfileSyncService()->GetClearServerDataState(); 370 sync_service_->GetClearServerDataState();
361 profile_->GetProfileSyncService()->ResetClearServerDataState(); 371 sync_service_->ResetClearServerDataState();
362 372
363 switch (clearState) { 373 switch (clearState) {
364 case ProfileSyncService::CLEAR_NOT_STARTED: 374 case ProfileSyncService::CLEAR_NOT_STARTED:
365 // This can occur on a first start and after a failed clear (which does 375 // This can occur on a first start and after a failed clear (which does
366 // not close the tab). Do nothing. 376 // not close the tab). Do nothing.
367 break; 377 break;
368 case ProfileSyncService::CLEAR_CLEARING: 378 case ProfileSyncService::CLEAR_CLEARING:
369 // Clearing buttons on all tabs are disabled at this point, throbber is 379 // Clearing buttons on all tabs are disabled at this point, throbber is
370 // going. 380 // going.
371 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_SENDING)]; 381 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_SENDING)];
372 deleteInProgress = true; 382 deleteInProgress = true;
373 break; 383 break;
374 case ProfileSyncService::CLEAR_FAILED: 384 case ProfileSyncService::CLEAR_FAILED:
375 // Show an error and reallow clearing. 385 // Show an error and reallow clearing.
376 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_ERROR)]; 386 [self setClearingStatus:l10n_util::GetNSString(IDS_CLEAR_DATA_ERROR)];
377 deleteInProgress = false; 387 deleteInProgress = false;
378 break; 388 break;
379 case ProfileSyncService::CLEAR_SUCCEEDED: 389 case ProfileSyncService::CLEAR_SUCCEEDED:
380 // Close the dialog box, success! 390 // Close the dialog box, success!
381 [self setClearingStatus:nil]; 391 [self setClearingStatus:nil];
382 deleteInProgress = false; 392 deleteInProgress = false;
383 [self closeDialog]; 393 [self closeDialog];
384 break; 394 break;
385 } 395 }
386 396
387 [self setIsClearing:deleteInProgress]; 397 [self setIsClearing:deleteInProgress];
388 } 398 }
389 399
400 - (BOOL)isSyncVisible {
401 return CommandLine::ForCurrentProcess()->HasSwitch(
402 switches::kEnableClearServerData);
403 }
404
390 - (BOOL)isSyncEnabled { 405 - (BOOL)isSyncEnabled {
391 BOOL allowClearServerDataUI = 406 return sync_service_ && sync_service_->HasSyncSetupCompleted();
392 CommandLine::ForCurrentProcess()->HasSwitch(
393 switches::kEnableClearServerData);
394
395 return allowClearServerDataUI &&
396 profile_->GetProfileSyncService()->HasSyncSetupCompleted();
397 } 407 }
398 408
399 - (NSFont*)labelFont { 409 - (NSFont*)labelFont {
400 return [NSFont boldSystemFontOfSize:13]; 410 return [NSFont boldSystemFontOfSize:13];
401 } 411 }
402 412
403 @end 413 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/clear_browsing_data_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698