Skip to content

Commit

Permalink
Remove TemplateURLService::profile()
Browse files Browse the repository at this point in the history
Change its only user template_url_table_model.cc to get FaviconService* from KeywordEditorController.

BUG=386367
TEST=git cl try
TBR=markusheintz@chromium.org for browsing_data_remover.cc

Review URL: https://codereview.chromium.org/363633002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280989 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
hashimoto@chromium.org committed Jul 2, 2014
1 parent 6af9b59 commit 0b46ce2
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 47 deletions.
1 change: 0 additions & 1 deletion chrome/browser/browsing_data/browsing_data_remover.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ void BrowsingDataRemover::OnKeywordsLoaded() {
// else notifies observers and deletes this BrowsingDataRemover.
TemplateURLService* model =
TemplateURLServiceFactory::GetForProfile(profile_);
DCHECK_EQ(profile_, model->profile());
model->RemoveAutoGeneratedBetween(delete_begin_, delete_end_);
waiting_for_clear_keyword_data_ = false;
template_url_sub_.reset();
Expand Down
6 changes: 0 additions & 6 deletions chrome/browser/search_engines/template_url_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,7 @@ class TemplateURLService : public WebDataServiceConsumer,
const TemplateURL* turl,
syncer::SyncChange::SyncChangeType type);

// DEPRECATED: Profile will be removed from this class. crbug.com/371535
Profile* profile() const { return profile_; }

// Returns a SearchTermsData which can be used to call TemplateURL methods.
// Note: Prefer using this method to instantiating UIThreadSearchTermsData on
// your own, especially when your code hasn't depended on Profile, to avoid
// adding a new dependency on Profile.
const SearchTermsData& search_terms_data() const {
return *search_terms_data_;
}
Expand Down
26 changes: 13 additions & 13 deletions chrome/browser/ui/search_engines/keyword_editor_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include "chrome/browser/ui/search_engines/keyword_editor_controller.h"

#include "base/prefs/pref_registry_simple.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/search_engines/template_url_table_model.h"
Expand All @@ -17,9 +16,10 @@
using base::UserMetricsAction;

KeywordEditorController::KeywordEditorController(Profile* profile)
: profile_(profile) {
: url_model_(TemplateURLServiceFactory::GetForProfile(profile)) {
table_model_.reset(new TemplateURLTableModel(
TemplateURLServiceFactory::GetForProfile(profile)));
url_model_,
FaviconServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS)));
}

KeywordEditorController::~KeywordEditorController() {
Expand Down Expand Up @@ -69,35 +69,35 @@ void KeywordEditorController::ModifyTemplateURL(TemplateURL* template_url,

bool KeywordEditorController::CanEdit(const TemplateURL* url) const {
return (url->GetType() != TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION) &&
(!url_model()->is_default_search_managed() ||
(url != url_model()->GetDefaultSearchProvider()));
(!url_model_->is_default_search_managed() ||
(url != url_model_->GetDefaultSearchProvider()));
}

bool KeywordEditorController::CanMakeDefault(const TemplateURL* url) const {
return url_model()->CanMakeDefault(url);
return url_model_->CanMakeDefault(url);
}

bool KeywordEditorController::CanRemove(const TemplateURL* url) const {
return url != url_model()->GetDefaultSearchProvider();
return url != url_model_->GetDefaultSearchProvider();
}

void KeywordEditorController::RemoveTemplateURL(int index) {
table_model_->Remove(index);
content::RecordAction(UserMetricsAction("KeywordEditor_RemoveKeyword"));
}

TemplateURL* KeywordEditorController::GetDefaultSearchProvider() {
return url_model_->GetDefaultSearchProvider();
}

int KeywordEditorController::MakeDefaultTemplateURL(int index) {
return table_model_->MakeDefaultTemplateURL(index);
}

bool KeywordEditorController::loaded() const {
return url_model()->loaded();
return url_model_->loaded();
}

TemplateURL* KeywordEditorController::GetTemplateURL(int index) {
return table_model_->GetTemplateURL(index);
}

TemplateURLService* KeywordEditorController::url_model() const {
return table_model_->template_url_service();
}
8 changes: 4 additions & 4 deletions chrome/browser/ui/search_engines/keyword_editor_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class KeywordEditorController {
// Remove the TemplateURL at the specified index in the TableModel.
void RemoveTemplateURL(int index);

// Returns the default search provider.
TemplateURL* GetDefaultSearchProvider();

// Make the TemplateURL at the specified index (into the TableModel) the
// default search provider. Return the new index, or -1 if nothing was done.
int MakeDefaultTemplateURL(int index);
Expand All @@ -64,11 +67,8 @@ class KeywordEditorController {
return table_model_.get();
}

TemplateURLService* url_model() const;

private:
// The profile.
Profile* profile_;
TemplateURLService* url_model_;

// Model for the TableView.
scoped_ptr<TemplateURLTableModel> table_model_;
Expand Down
25 changes: 10 additions & 15 deletions chrome/browser/ui/search_engines/template_url_table_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
#include "chrome/browser/ui/search_engines/template_url_table_model.h"

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/i18n/rtl.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service.h"
#include "components/favicon_base/favicon_types.h"
#include "components/search_engines/template_url.h"
#include "grit/generated_resources.h"
#include "grit/ui_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/table_model_observer.h"
#include "ui/base/resource/resource_bundle.h"
Expand All @@ -38,7 +32,7 @@ static const int kExtensionGroupID = 2;
// Icon used while loading, or if a specific favicon can't be found.
static const gfx::ImageSkia* default_icon = NULL;

class ModelEntry {
class TemplateURLTableModel::ModelEntry {
public:
ModelEntry(TemplateURLTableModel* model, TemplateURL* template_url)
: template_url_(template_url),
Expand Down Expand Up @@ -79,15 +73,13 @@ class ModelEntry {

void LoadFavicon() {
load_state_ = LOADED;
FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
model_->template_url_service()->profile(), Profile::EXPLICIT_ACCESS);
if (!favicon_service)
if (!model_->favicon_service_)
return;
GURL favicon_url = template_url()->favicon_url();
if (!favicon_url.is_valid()) {
// The favicon url isn't always set. Guess at one here.
if (template_url_->url_ref().IsValid(
model_->template_url_service()->search_terms_data())) {
model_->template_url_service_->search_terms_data())) {
GURL url(template_url_->url());
if (url.is_valid())
favicon_url = TemplateURL::GenerateFaviconURL(url);
Expand All @@ -96,7 +88,7 @@ class ModelEntry {
return;
}
load_state_ = LOADING;
favicon_service->GetFaviconImage(
model_->favicon_service_->GetFaviconImage(
favicon_url,
favicon_base::FAVICON,
gfx::kFaviconSize,
Expand Down Expand Up @@ -125,9 +117,11 @@ class ModelEntry {
// TemplateURLTableModel -----------------------------------------

TemplateURLTableModel::TemplateURLTableModel(
TemplateURLService* template_url_service)
TemplateURLService* template_url_service,
FaviconService* favicon_service)
: observer_(NULL),
template_url_service_(template_url_service) {
template_url_service_(template_url_service),
favicon_service_(favicon_service) {
DCHECK(template_url_service);
template_url_service_->Load();
template_url_service_->AddObserver(this);
Expand Down Expand Up @@ -381,7 +375,8 @@ void TemplateURLTableModel::OnTemplateURLServiceChanged() {
Reload();
}

scoped_ptr<ModelEntry> TemplateURLTableModel::RemoveEntry(int index) {
scoped_ptr<TemplateURLTableModel::ModelEntry>
TemplateURLTableModel::RemoveEntry(int index) {
scoped_ptr<ModelEntry> entry(entries_[index]);
entries_.erase(index + entries_.begin());
if (index < last_search_engine_index_)
Expand Down
13 changes: 6 additions & 7 deletions chrome/browser/ui/search_engines/template_url_table_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "chrome/browser/search_engines/template_url_service_observer.h"
#include "ui/base/models/table_model.h"

class ModelEntry;
class FaviconService;
class TemplateURL;
class TemplateURLService;

Expand All @@ -36,7 +36,8 @@ class ImageSkia;
class TemplateURLTableModel : public ui::TableModel,
TemplateURLServiceObserver {
public:
explicit TemplateURLTableModel(TemplateURLService* template_url_service);
TemplateURLTableModel(TemplateURLService* template_url_service,
FaviconService* favicon_service);

virtual ~TemplateURLTableModel();

Expand Down Expand Up @@ -91,10 +92,6 @@ class TemplateURLTableModel : public ui::TableModel,
// If there is an observer, it's notified the selected row has changed.
void NotifyChanged(int index);

TemplateURLService* template_url_service() const {
return template_url_service_;
}

// Returns the index of the last entry shown in the search engines group.
int last_search_engine_index() const { return last_search_engine_index_; }

Expand All @@ -103,7 +100,7 @@ class TemplateURLTableModel : public ui::TableModel,
int last_other_engine_index() const { return last_other_engine_index_; }

private:
friend class ModelEntry;
class ModelEntry;

// Notification that a model entry has fetched its icon.
void FaviconAvailable(ModelEntry* entry);
Expand All @@ -125,6 +122,8 @@ class TemplateURLTableModel : public ui::TableModel,
// The model we're displaying entries from.
TemplateURLService* template_url_service_;

FaviconService* favicon_service_;

// Index of the last search engine in entries_. This is used to determine the
// group boundaries.
int last_search_engine_index_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void SearchEngineManagerHandler::OnModelChanged() {

// Find the default engine.
const TemplateURL* default_engine =
list_controller_->url_model()->GetDefaultSearchProvider();
list_controller_->GetDefaultSearchProvider();
int default_index = list_controller_->table_model()->IndexOfTemplateURL(
default_engine);

Expand Down

0 comments on commit 0b46ce2

Please sign in to comment.