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

Side by Side Diff: chrome/browser/ui/cocoa/profile_menu_controller.mm

Issue 11661017: [Mac] Fix profile getting re-created / IO allowed dcheck with profile menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: [Mac] Fix profile getting re-created / IO allowed dcheck with profile menu. Created 7 years, 11 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 | « no previous file | chrome/browser/ui/cocoa/profile_menu_controller_unittest.mm » ('j') | 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) 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 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" 5 #import "chrome/browser/ui/cocoa/profile_menu_controller.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/avatar_menu_model.h" 9 #include "chrome/browser/profiles/avatar_menu_model.h"
10 #include "chrome/browser/profiles/avatar_menu_model_observer.h" 10 #include "chrome/browser/profiles/avatar_menu_model_observer.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 168
169 [self rebuildMenu]; 169 [self rebuildMenu];
170 } 170 }
171 171
172 // Notifies the controller that the active browser has changed and that the 172 // Notifies the controller that the active browser has changed and that the
173 // menu item and menu need to be updated to reflect that. 173 // menu item and menu need to be updated to reflect that.
174 - (void)activeBrowserChangedTo:(Browser*)browser { 174 - (void)activeBrowserChangedTo:(Browser*)browser {
175 // Tell the model that the browser has changed. 175 // Tell the model that the browser has changed.
176 model_->set_browser(browser); 176 model_->set_browser(browser);
177 177
178 // If |browser| is NULL, it may be because the current profile was deleted
179 // and there are no other loaded profiles. In this case, calling
180 // |model_->GetActiveProfileIndex()| may result in a profile being loaded,
181 // which is inappropriate to do on the UI thread.
182 //
183 // An early return provides the desired behavior:
184 // a) If the profile was deleted, the menu would have been rebuilt and no
185 // profile will have a check mark.
186 // b) If the profile was not deleted, but there is no active browser, then
187 // the previous profile will remain checked.
188 if (!browser)
189 return;
190
178 size_t active_profile_index = model_->GetActiveProfileIndex(); 191 size_t active_profile_index = model_->GetActiveProfileIndex();
179 192
180 // Update the state for the menu items. 193 // Update the state for the menu items.
181 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) { 194 for (size_t i = 0; i < model_->GetNumberOfItems(); ++i) {
182 size_t tag = model_->GetItemAt(i).model_index; 195 size_t tag = model_->GetItemAt(i).model_index;
183 [[[self menu] itemWithTag:tag] 196 [[[self menu] itemWithTag:tag]
184 setState:active_profile_index == tag ? NSOnState 197 setState:active_profile_index == tag ? NSOnState
185 : NSOffState]; 198 : NSOffState];
186 } 199 }
187 } 200 }
(...skipping 13 matching lines...) Expand all
201 } 214 }
202 215
203 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { 216 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel {
204 scoped_nsobject<NSMenuItem> item( 217 scoped_nsobject<NSMenuItem> item(
205 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); 218 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]);
206 [item setTarget:self]; 219 [item setTarget:self];
207 return [item.release() autorelease]; 220 return [item.release() autorelease];
208 } 221 }
209 222
210 @end 223 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/profile_menu_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698