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

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

Issue 5711001: Add a new GetInstance() method for remaining files with singleton classes under chrome/browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 10 years 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
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/ui/cocoa/clear_browsing_data_controller.h" 5 #import "chrome/browser/ui/cocoa/clear_browsing_data_controller.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/lazy_instance.h"
8 #include "base/mac_util.h" 9 #include "base/mac_util.h"
9 #include "base/scoped_nsobject.h" 10 #include "base/scoped_nsobject.h"
10 #include "base/singleton.h"
11 #include "chrome/browser/browsing_data_remover.h" 11 #include "chrome/browser/browsing_data_remover.h"
12 #include "chrome/browser/prefs/pref_service.h" 12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "grit/locale_settings.h" 17 #include "grit/locale_settings.h"
18 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 18 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
19 19
20 NSString* const kClearBrowsingDataControllerDidDelete = 20 NSString* const kClearBrowsingDataControllerDidDelete =
(...skipping 13 matching lines...) Expand all
34 : controller_(controller) { } 34 : controller_(controller) { }
35 void OnBrowsingDataRemoverDone() { [controller_ dataRemoverDidFinish]; } 35 void OnBrowsingDataRemoverDone() { [controller_ dataRemoverDidFinish]; }
36 private: 36 private:
37 ClearBrowsingDataController* controller_; 37 ClearBrowsingDataController* controller_;
38 }; 38 };
39 39
40 namespace { 40 namespace {
41 41
42 typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap; 42 typedef std::map<Profile*, ClearBrowsingDataController*> ProfileControllerMap;
43 43
44 static base::LazyInstance<ProfileControllerMap> g_profile_controller_map(
45 base::LINKER_INITIALIZED);
46
44 } // namespace 47 } // namespace
45 48
46 @implementation ClearBrowsingDataController 49 @implementation ClearBrowsingDataController
47 50
48 @synthesize clearBrowsingHistory = clearBrowsingHistory_; 51 @synthesize clearBrowsingHistory = clearBrowsingHistory_;
49 @synthesize clearDownloadHistory = clearDownloadHistory_; 52 @synthesize clearDownloadHistory = clearDownloadHistory_;
50 @synthesize emptyCache = emptyCache_; 53 @synthesize emptyCache = emptyCache_;
51 @synthesize deleteCookies = deleteCookies_; 54 @synthesize deleteCookies = deleteCookies_;
52 @synthesize clearSavedPasswords = clearSavedPasswords_; 55 @synthesize clearSavedPasswords = clearSavedPasswords_;
53 @synthesize clearFormData = clearFormData_; 56 @synthesize clearFormData = clearFormData_;
(...skipping 13 matching lines...) Expand all
67 afterDelay:0]; 70 afterDelay:0];
68 } 71 }
69 } 72 }
70 73
71 + (ClearBrowsingDataController *)controllerForProfile:(Profile*)profile { 74 + (ClearBrowsingDataController *)controllerForProfile:(Profile*)profile {
72 // Get the original profile in case we get here from an incognito window 75 // Get the original profile in case we get here from an incognito window
73 // |GetOriginalProfile()| will return the same profile if it is the original 76 // |GetOriginalProfile()| will return the same profile if it is the original
74 // profile. 77 // profile.
75 profile = profile->GetOriginalProfile(); 78 profile = profile->GetOriginalProfile();
76 79
77 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); 80 ProfileControllerMap* map = g_profile_controller_map.Pointer();
78 DCHECK(map != NULL); 81 DCHECK(map != NULL);
79 ProfileControllerMap::iterator it = map->find(profile); 82 ProfileControllerMap::iterator it = map->find(profile);
80 if (it == map->end()) { 83 if (it == map->end()) {
81 // Since we don't currently support multiple profiles, this class 84 // Since we don't currently support multiple profiles, this class
82 // has not been tested against this case. 85 // has not been tested against this case.
83 if (map->size() != 0) { 86 if (map->size() != 0) {
84 return nil; 87 return nil;
85 } 88 }
86 89
87 ClearBrowsingDataController* controller = 90 ClearBrowsingDataController* controller =
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // opening a tab with flash settings. 201 // opening a tab with flash settings.
199 [self closeDialog]; 202 [self closeDialog];
200 203
201 Browser* browser = Browser::Create(profile_); 204 Browser* browser = Browser::Create(profile_);
202 browser->OpenURL(GURL(l10n_util::GetStringUTF8(IDS_FLASH_STORAGE_URL)), 205 browser->OpenURL(GURL(l10n_util::GetStringUTF8(IDS_FLASH_STORAGE_URL)),
203 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); 206 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK);
204 browser->window()->Show(); 207 browser->window()->Show();
205 } 208 }
206 209
207 - (void)closeDialog { 210 - (void)closeDialog {
208 ProfileControllerMap* map = Singleton<ProfileControllerMap>::get(); 211 ProfileControllerMap* map = g_profile_controller_map.Pointer();
209 ProfileControllerMap::iterator it = map->find(profile_); 212 ProfileControllerMap::iterator it = map->find(profile_);
210 if (it != map->end()) { 213 if (it != map->end()) {
211 map->erase(it); 214 map->erase(it);
212 } 215 }
213 [self autorelease]; 216 [self autorelease];
214 [[self window] orderOut:self]; 217 [[self window] orderOut:self];
215 [NSApp stopModal]; 218 [NSApp stopModal];
216 } 219 }
217 220
218 // Initialize the bools from prefs using the setters to be KVO-compliant. 221 // Initialize the bools from prefs using the setters to be KVO-compliant.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 object:self 258 object:self
256 userInfo:userInfo]; 259 userInfo:userInfo];
257 260
258 [self closeDialog]; 261 [self closeDialog];
259 [[self window] orderOut:self]; 262 [[self window] orderOut:self];
260 [self setIsClearing:NO]; 263 [self setIsClearing:NO];
261 remover_ = NULL; 264 remover_ = NULL;
262 } 265 }
263 266
264 @end 267 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698