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

Unified Diff: chrome/browser/ui/webui/instant_ui.cc

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/instant_ui.cc
diff --git a/chrome/browser/ui/webui/instant_ui.cc b/chrome/browser/ui/webui/instant_ui.cc
index 0e00082fa2f5c670b032f5514441d68b32b12c85..b725601330e5a77a474f3356f57bf0af7abb4779 100644
--- a/chrome/browser/ui/webui/instant_ui.cc
+++ b/chrome/browser/ui/webui/instant_ui.cc
@@ -1,21 +1,16 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/instant_ui.h"
#include "base/bind.h"
-#include "base/prefs/pref_service.h"
#include "base/stringprintf.h"
-#include "base/time.h"
-#include "chrome/browser/instant/instant_controller.h"
+#include "base/values.h"
+#include "chrome/browser/instant/instant_service.h"
+#include "chrome/browser/instant/instant_service_factory.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/browser.h"
-#include "chrome/browser/ui/browser_finder.h"
-#include "chrome/browser/ui/browser_instant_controller.h"
-#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
-#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
@@ -26,7 +21,6 @@ namespace {
content::WebUIDataSource* CreateInstantHTMLSource() {
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIInstantHost);
- source->SetJsonPath("strings.js");
source->AddResourcePath("instant.js", IDR_INSTANT_JS);
source->AddResourcePath("instant.css", IDR_INSTANT_CSS);
source->SetDefaultResource(IDR_INSTANT_HTML);
@@ -41,117 +35,68 @@ std::string FormatTime(int64 time) {
exploded.hour, exploded.minute, exploded.second, exploded.millisecond);
}
-// This class receives JavaScript messages from the renderer.
-// Note that the WebUI infrastructure runs on the UI thread, therefore all of
-// this class's methods are expected to run on the UI thread.
-class InstantUIMessageHandler
- : public content::WebUIMessageHandler,
- public base::SupportsWeakPtr<InstantUIMessageHandler> {
+// This class receives JavaScript messages from the renderer. Note that the
+// WebUI infrastructure runs on the UI thread, therefore all of this class's
+// methods are expected to run on the UI thread.
+class InstantUIMessageHandler : public content::WebUIMessageHandler {
public:
InstantUIMessageHandler();
virtual ~InstantUIMessageHandler();
- // WebUIMessageHandler implementation.
+ private:
+ // Overridden from content::WebUIMessageHandler:
virtual void RegisterMessages() OVERRIDE;
- private:
- void GetPreferenceValue(const base::ListValue* args);
- void SetPreferenceValue(const base::ListValue* args);
- void GetDebugInfo(const base::ListValue* value);
- void ClearDebugInfo(const base::ListValue* value);
+ void GetDebugEvents(const base::ListValue* value);
+ void ClearDebugEvents(const base::ListValue* value);
DISALLOW_COPY_AND_ASSIGN(InstantUIMessageHandler);
};
-InstantUIMessageHandler::InstantUIMessageHandler() {}
+InstantUIMessageHandler::InstantUIMessageHandler() {
+}
-InstantUIMessageHandler::~InstantUIMessageHandler() {}
+InstantUIMessageHandler::~InstantUIMessageHandler() {
+}
void InstantUIMessageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
- "getPreferenceValue",
- base::Bind(&InstantUIMessageHandler::GetPreferenceValue,
- base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- "setPreferenceValue",
- base::Bind(&InstantUIMessageHandler::SetPreferenceValue,
+ "getDebugEvents",
+ base::Bind(&InstantUIMessageHandler::GetDebugEvents,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
- "getDebugInfo",
- base::Bind(&InstantUIMessageHandler::GetDebugInfo,
+ "clearDebugEvents",
+ base::Bind(&InstantUIMessageHandler::ClearDebugEvents,
base::Unretained(this)));
- web_ui()->RegisterMessageCallback(
- "clearDebugInfo",
- base::Bind(&InstantUIMessageHandler::ClearDebugInfo,
- base::Unretained(this)));
-}
-
-void InstantUIMessageHandler::GetPreferenceValue(const base::ListValue* args) {
- std::string pref_name;
- if (!args->GetString(0, &pref_name)) return;
-
- base::StringValue pref_name_value(pref_name);
- if (pref_name == prefs::kInstantUIZeroSuggestUrlPrefix) {
- PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
- base::StringValue arg(prefs->GetString(pref_name.c_str()));
- web_ui()->CallJavascriptFunction(
- "instantConfig.getPreferenceValueResult", pref_name_value, arg);
- }
-}
-
-void InstantUIMessageHandler::SetPreferenceValue(const base::ListValue* args) {
- std::string pref_name;
- if (!args->GetString(0, &pref_name)) return;
-
- if (pref_name == prefs::kInstantUIZeroSuggestUrlPrefix) {
- std::string value;
- if (!args->GetString(1, &value))
- return;
- PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
- prefs->SetString(pref_name.c_str(), value);
- }
}
-void InstantUIMessageHandler::GetDebugInfo(const base::ListValue* args) {
-#if !defined(OS_ANDROID)
- typedef std::pair<int64, std::string> DebugEvent;
-
- if (!web_ui()->GetWebContents())
- return;
- Browser* browser = chrome::FindBrowserWithWebContents(
- web_ui()->GetWebContents());
- if (!browser || !browser->instant_controller())
+void InstantUIMessageHandler::GetDebugEvents(
+ const base::ListValue* /* args */) {
+ InstantService* service =
+ InstantServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
+ if (!service)
return;
- InstantController* instant = browser->instant_controller()->instant();
- const std::list<DebugEvent>& events = instant->debug_events();
-
- base::DictionaryValue data;
- base::ListValue* entries = new base::ListValue();
- for (std::list<DebugEvent>::const_iterator it = events.begin();
- it != events.end(); ++it) {
- base::DictionaryValue* entry = new base::DictionaryValue();
- entry->SetString("time", FormatTime(it->first));
- entry->SetString("text", it->second);
- entries->Append(entry);
+ base::ListValue events;
+ const InstantService::DebugEventsList& source = service->debug_events();
+
+ for (InstantService::DebugEventsList::const_iterator i = source.begin();
+ i != source.end(); ++i) {
+ scoped_ptr<base::DictionaryValue> event(new base::DictionaryValue());
+ event->SetString("time", FormatTime(i->first));
+ event->SetString("text", i->second);
+ events.Append(event.release());
}
- data.Set("entries", entries);
- web_ui()->CallJavascriptFunction("instantConfig.getDebugInfoResult", data);
-#endif
+ web_ui()->CallJavascriptFunction("instantConfig.setDebugEvents", events);
}
-void InstantUIMessageHandler::ClearDebugInfo(const base::ListValue* args) {
-#if !defined(OS_ANDROID)
- if (!web_ui()->GetWebContents())
- return;
- Browser* browser = chrome::FindBrowserWithWebContents(
- web_ui()->GetWebContents());
- if (!browser || !browser->instant_controller())
- return;
-
- browser->instant_controller()->instant()->ClearDebugEvents();
-#endif
+void InstantUIMessageHandler::ClearDebugEvents(
+ const base::ListValue* /* args */) {
+ InstantService* service =
+ InstantServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
+ if (service)
+ service->ClearDebugEvents();
}
} // namespace
@@ -167,8 +112,5 @@ InstantUI::InstantUI(content::WebUI* web_ui) : WebUIController(web_ui) {
content::WebUIDataSource::Add(profile, CreateInstantHTMLSource());
}
-// static
-void InstantUI::RegisterUserPrefs(PrefRegistrySyncable* registry) {
- registry->RegisterStringPref(prefs::kInstantUIZeroSuggestUrlPrefix, "",
- PrefRegistrySyncable::UNSYNCABLE_PREF);
+InstantUI::~InstantUI() {
}

Powered by Google App Engine
This is Rietveld 408576698