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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/suggestions_internals/suggestions_internals_ui_handler.h"
8 #include "base/values.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h"
11 #include "content/public/browser/web_ui.h"
15 const size_t kSuggestionsCount
= 100;
19 SuggestionsInternalsUIHandler::SuggestionsInternalsUIHandler(Profile
* profile
)
20 : profile_(profile
) {}
22 SuggestionsInternalsUIHandler::~SuggestionsInternalsUIHandler() {}
24 void SuggestionsInternalsUIHandler::OnSuggestionsReady() {
25 if (suggestions_combiner_
->GetPageValues()) {
26 web_ui()->CallJavascriptFunction("suggestionsInternals.setSuggestions",
27 *suggestions_combiner_
->GetPageValues());
31 void SuggestionsInternalsUIHandler::RegisterMessages() {
32 // Setup the suggestions sources.
33 suggestions_combiner_
.reset(new SuggestionsCombiner(this, profile_
));
34 suggestions_combiner_
->SetSuggestionsCount(kSuggestionsCount
);
35 suggestions_combiner_
->EnableDebug(true);
37 web_ui()->RegisterMessageCallback("getSuggestions",
38 base::Bind(&SuggestionsInternalsUIHandler::HandleGetSuggestions
,
39 base::Unretained(this)));
42 void SuggestionsInternalsUIHandler::HandleGetSuggestions(
43 const base::ListValue
* one_element_input_string
) {
44 suggestions_combiner_
->FetchItems(Profile::FromWebUI(web_ui()));