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

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

Issue 341060: [Mac] Prevent search engines from disappearing in the preferences list (Closed)
Patch Set: Created 11 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/cocoa/search_engine_list_model_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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/search_engine_list_model.h" 5 #import "chrome/browser/cocoa/search_engine_list_model.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/search_engines/template_url.h" 8 #include "chrome/browser/search_engines/template_url.h"
9 #include "chrome/browser/search_engines/template_url_model.h" 9 #include "chrome/browser/search_engines/template_url_model.h"
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 [engines addObject:base::SysWideToNSString(modelURLs[i]->short_name())]; 81 [engines addObject:base::SysWideToNSString(modelURLs[i]->short_name())];
82 } 82 }
83 83
84 [self setSearchEngines:engines.get()]; 84 [self setSearchEngines:engines.get()];
85 } 85 }
86 86
87 // The index into |-searchEngines| of the current default search engine. 87 // The index into |-searchEngines| of the current default search engine.
88 - (NSUInteger)defaultIndex { 88 - (NSUInteger)defaultIndex {
89 if (!model_) return 0; 89 if (!model_) return 0;
90 90
91 NSUInteger index = 0;
91 const TemplateURL* defaultSearchProvider = model_->GetDefaultSearchProvider(); 92 const TemplateURL* defaultSearchProvider = model_->GetDefaultSearchProvider();
92 if (defaultSearchProvider) { 93 if (defaultSearchProvider) {
93 typedef std::vector<const TemplateURL*> TemplateURLs; 94 typedef std::vector<const TemplateURL*> TemplateURLs;
94 TemplateURLs urls = model_->GetTemplateURLs(); 95 TemplateURLs urls = model_->GetTemplateURLs();
95 TemplateURLs::iterator i = 96 for (std::vector<const TemplateURL*>::iterator it = urls.begin();
96 find(urls.begin(), urls.end(), defaultSearchProvider); 97 it != urls.end(); ++it) {
pink (ping after 24hrs) 2009/11/02 15:46:23 align with |std| above, not paren.
97 if (i != urls.end()) 98 const TemplateURL* url = *it;
98 return static_cast<int>(i - urls.begin()); 99 if (url->id() == defaultSearchProvider->id())
100 return index;
101 if (url->ShowInDefaultList())
102 ++index;
103 }
99 } 104 }
100 return 0; 105 return 0;
101 } 106 }
102 107
103 - (void)setDefaultIndex:(NSUInteger)index { 108 - (void)setDefaultIndex:(NSUInteger)index {
104 if (model_) { 109 if (model_) {
105 typedef std::vector<const TemplateURL*> TemplateURLs; 110 typedef std::vector<const TemplateURL*> TemplateURLs;
106 TemplateURLs urls = model_->GetTemplateURLs(); 111 TemplateURLs urls = model_->GetTemplateURLs();
107 DCHECK(index < urls.size()); 112 DCHECK(index < urls.size());
108 model_->SetDefaultSearchProvider(urls[index]); 113 model_->SetDefaultSearchProvider(urls[index]);
109 } 114 }
110 } 115 }
111 116
112 @end 117 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/cocoa/search_engine_list_model_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698