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

Side by Side Diff: chrome/browser/search_engines/keyword_editor_controller.cc

Issue 6291003: Revert 71485 - Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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
OLDNEW
1 // Copyright (c) 2011 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 #include "chrome/browser/search_engines/keyword_editor_controller.h" 5 #include "chrome/browser/search_engines/keyword_editor_controller.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/metrics/user_metrics.h" 8 #include "chrome/browser/metrics/user_metrics.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search_engines/template_url.h" 11 #include "chrome/browser/search_engines/template_url.h"
(...skipping 18 matching lines...) Expand all
30 30
31 int KeywordEditorController::AddTemplateURL(const string16& title, 31 int KeywordEditorController::AddTemplateURL(const string16& title,
32 const string16& keyword, 32 const string16& keyword,
33 const std::string& url) { 33 const std::string& url) {
34 DCHECK(!url.empty()); 34 DCHECK(!url.empty());
35 35
36 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword"), 36 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword"),
37 profile_); 37 profile_);
38 38
39 TemplateURL* template_url = new TemplateURL(); 39 TemplateURL* template_url = new TemplateURL();
40 template_url->set_short_name(title); 40 template_url->set_short_name(UTF16ToWideHack(title));
41 template_url->set_keyword(keyword); 41 template_url->set_keyword(UTF16ToWideHack(keyword));
42 template_url->SetURL(url, 0, 0); 42 template_url->SetURL(url, 0, 0);
43 43
44 // There's a bug (1090726) in TableView with groups enabled such that newly 44 // There's a bug (1090726) in TableView with groups enabled such that newly
45 // added items in groups ALWAYS appear at the end, regardless of the index 45 // added items in groups ALWAYS appear at the end, regardless of the index
46 // passed in. Worse yet, the selected rows get messed up when this happens 46 // passed in. Worse yet, the selected rows get messed up when this happens
47 // causing other problems. As a work around we always add the item to the end 47 // causing other problems. As a work around we always add the item to the end
48 // of the list. 48 // of the list.
49 const int new_index = table_model_->RowCount(); 49 const int new_index = table_model_->RowCount();
50 table_model_->Add(new_index, template_url); 50 table_model_->Add(new_index, template_url);
51 51
52 return new_index; 52 return new_index;
53 } 53 }
54 54
55 void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url, 55 void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url,
56 const string16& title, 56 const string16& title,
57 const string16& keyword, 57 const string16& keyword,
58 const std::string& url) { 58 const std::string& url) {
59 const int index = table_model_->IndexOfTemplateURL(template_url); 59 const int index = table_model_->IndexOfTemplateURL(template_url);
60 if (index == -1) { 60 if (index == -1) {
61 // Will happen if url was deleted out from under us while the user was 61 // Will happen if url was deleted out from under us while the user was
62 // editing it. 62 // editing it.
63 return; 63 return;
64 } 64 }
65 65
66 // Don't do anything if the entry didn't change. 66 // Don't do anything if the entry didn't change.
67 if (template_url->short_name() == title && 67 if (template_url->short_name() == UTF16ToWideHack(title) &&
68 template_url->keyword() == keyword && 68 template_url->keyword() == UTF16ToWideHack(keyword) &&
69 ((url.empty() && !template_url->url()) || 69 ((url.empty() && !template_url->url()) ||
70 (!url.empty() && template_url->url() && 70 (!url.empty() && template_url->url() &&
71 template_url->url()->url() == url))) { 71 template_url->url()->url() == url))) {
72 return; 72 return;
73 } 73 }
74 74
75 table_model_->ModifyTemplateURL(index, title, keyword, url); 75 table_model_->ModifyTemplateURL(index, title, keyword, url);
76 76
77 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_ModifiedKeyword"), 77 UserMetrics::RecordAction(UserMetricsAction("KeywordEditor_ModifiedKeyword"),
78 profile_); 78 profile_);
(...skipping 26 matching lines...) Expand all
105 return url_model()->loaded(); 105 return url_model()->loaded();
106 } 106 }
107 107
108 const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const { 108 const TemplateURL* KeywordEditorController::GetTemplateURL(int index) const {
109 return &table_model_->GetTemplateURL(index); 109 return &table_model_->GetTemplateURL(index);
110 } 110 }
111 111
112 TemplateURLModel* KeywordEditorController::url_model() const { 112 TemplateURLModel* KeywordEditorController::url_model() const {
113 return table_model_->template_url_model(); 113 return table_model_->template_url_model();
114 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698