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

Side by Side Diff: chrome/browser/ui/search_engines/template_url_table_model.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
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 #include "chrome/browser/ui/search_engines/template_url_table_model.h" 5 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return kMainGroupID; 240 return kMainGroupID;
241 return row < last_other_engine_index_ ? kOtherGroupID : kExtensionGroupID; 241 return row < last_other_engine_index_ ? kOtherGroupID : kExtensionGroupID;
242 } 242 }
243 243
244 void TemplateURLTableModel::Remove(int index) { 244 void TemplateURLTableModel::Remove(int index) {
245 // Remove the observer while we modify the model, that way we don't need to 245 // Remove the observer while we modify the model, that way we don't need to
246 // worry about the model calling us back when we mutate it. 246 // worry about the model calling us back when we mutate it.
247 template_url_service_->RemoveObserver(this); 247 template_url_service_->RemoveObserver(this);
248 TemplateURL* template_url = GetTemplateURL(index); 248 TemplateURL* template_url = GetTemplateURL(index);
249 249
250 scoped_ptr<ModelEntry> entry(RemoveEntry(index)); 250 std::unique_ptr<ModelEntry> entry(RemoveEntry(index));
251 251
252 // Make sure to remove from the table model first, otherwise the 252 // Make sure to remove from the table model first, otherwise the
253 // TemplateURL would be freed. 253 // TemplateURL would be freed.
254 template_url_service_->Remove(template_url); 254 template_url_service_->Remove(template_url);
255 template_url_service_->AddObserver(this); 255 template_url_service_->AddObserver(this);
256 } 256 }
257 257
258 void TemplateURLTableModel::Add(int index, 258 void TemplateURLTableModel::Add(int index,
259 const base::string16& short_name, 259 const base::string16& short_name,
260 const base::string16& keyword, 260 const base::string16& keyword,
261 const std::string& url) { 261 const std::string& url) {
262 DCHECK(index >= 0 && index <= RowCount()); 262 DCHECK(index >= 0 && index <= RowCount());
263 DCHECK(!url.empty()); 263 DCHECK(!url.empty());
264 template_url_service_->RemoveObserver(this); 264 template_url_service_->RemoveObserver(this);
265 TemplateURLData data; 265 TemplateURLData data;
266 data.SetShortName(short_name); 266 data.SetShortName(short_name);
267 data.SetKeyword(keyword); 267 data.SetKeyword(keyword);
268 data.SetURL(url); 268 data.SetURL(url);
269 TemplateURL* turl = new TemplateURL(data); 269 TemplateURL* turl = new TemplateURL(data);
270 template_url_service_->Add(turl); 270 template_url_service_->Add(turl);
271 scoped_ptr<ModelEntry> entry(new ModelEntry(this, turl)); 271 std::unique_ptr<ModelEntry> entry(new ModelEntry(this, turl));
272 template_url_service_->AddObserver(this); 272 template_url_service_->AddObserver(this);
273 AddEntry(index, std::move(entry)); 273 AddEntry(index, std::move(entry));
274 } 274 }
275 275
276 void TemplateURLTableModel::ModifyTemplateURL(int index, 276 void TemplateURLTableModel::ModifyTemplateURL(int index,
277 const base::string16& title, 277 const base::string16& title,
278 const base::string16& keyword, 278 const base::string16& keyword,
279 const std::string& url) { 279 const std::string& url) {
280 DCHECK(index >= 0 && index <= RowCount()); 280 DCHECK(index >= 0 && index <= RowCount());
281 DCHECK(!url.empty()); 281 DCHECK(!url.empty());
(...skipping 28 matching lines...) Expand all
310 if (entry->template_url() == template_url) 310 if (entry->template_url() == template_url)
311 return static_cast<int>(i - entries_.begin()); 311 return static_cast<int>(i - entries_.begin());
312 } 312 }
313 return -1; 313 return -1;
314 } 314 }
315 315
316 int TemplateURLTableModel::MoveToMainGroup(int index) { 316 int TemplateURLTableModel::MoveToMainGroup(int index) {
317 if (index < last_search_engine_index_) 317 if (index < last_search_engine_index_)
318 return index; // Already in the main group. 318 return index; // Already in the main group.
319 319
320 scoped_ptr<ModelEntry> current_entry(RemoveEntry(index)); 320 std::unique_ptr<ModelEntry> current_entry(RemoveEntry(index));
321 const int new_index = last_search_engine_index_++; 321 const int new_index = last_search_engine_index_++;
322 AddEntry(new_index, std::move(current_entry)); 322 AddEntry(new_index, std::move(current_entry));
323 return new_index; 323 return new_index;
324 } 324 }
325 325
326 int TemplateURLTableModel::MakeDefaultTemplateURL(int index) { 326 int TemplateURLTableModel::MakeDefaultTemplateURL(int index) {
327 if (index < 0 || index >= RowCount()) { 327 if (index < 0 || index >= RowCount()) {
328 NOTREACHED(); 328 NOTREACHED();
329 return -1; 329 return -1;
330 } 330 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 std::vector<ModelEntry*>::iterator i = 366 std::vector<ModelEntry*>::iterator i =
367 std::find(entries_.begin(), entries_.end(), entry); 367 std::find(entries_.begin(), entries_.end(), entry);
368 DCHECK(i != entries_.end()); 368 DCHECK(i != entries_.end());
369 NotifyChanged(static_cast<int>(i - entries_.begin())); 369 NotifyChanged(static_cast<int>(i - entries_.begin()));
370 } 370 }
371 371
372 void TemplateURLTableModel::OnTemplateURLServiceChanged() { 372 void TemplateURLTableModel::OnTemplateURLServiceChanged() {
373 Reload(); 373 Reload();
374 } 374 }
375 375
376 scoped_ptr<TemplateURLTableModel::ModelEntry> 376 std::unique_ptr<TemplateURLTableModel::ModelEntry>
377 TemplateURLTableModel::RemoveEntry(int index) { 377 TemplateURLTableModel::RemoveEntry(int index) {
378 scoped_ptr<ModelEntry> entry(entries_[index]); 378 std::unique_ptr<ModelEntry> entry(entries_[index]);
379 entries_.erase(index + entries_.begin()); 379 entries_.erase(index + entries_.begin());
380 if (index < last_search_engine_index_) 380 if (index < last_search_engine_index_)
381 --last_search_engine_index_; 381 --last_search_engine_index_;
382 if (index < last_other_engine_index_) 382 if (index < last_other_engine_index_)
383 --last_other_engine_index_; 383 --last_other_engine_index_;
384 if (observer_) 384 if (observer_)
385 observer_->OnItemsRemoved(index, 1); 385 observer_->OnItemsRemoved(index, 1);
386 return entry; 386 return entry;
387 } 387 }
388 388
389 void TemplateURLTableModel::AddEntry(int index, scoped_ptr<ModelEntry> entry) { 389 void TemplateURLTableModel::AddEntry(int index,
390 std::unique_ptr<ModelEntry> entry) {
390 entries_.insert(entries_.begin() + index, entry.release()); 391 entries_.insert(entries_.begin() + index, entry.release());
391 if (index <= last_other_engine_index_) 392 if (index <= last_other_engine_index_)
392 ++last_other_engine_index_; 393 ++last_other_engine_index_;
393 if (observer_) 394 if (observer_)
394 observer_->OnItemsAdded(index, 1); 395 observer_->OnItemsAdded(index, 1);
395 } 396 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search_engines/template_url_table_model.h ('k') | chrome/browser/ui/startup/default_browser_prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698