Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / history_ui.cc
index 7f9a513..24f4f78 100644 (file)
@@ -20,9 +20,7 @@
 #include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
 #include "base/values.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "chrome/browser/bookmarks/bookmark_utils.h"
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/extensions/activity_log/activity_log.h"
 #include "chrome/browser/history/history_notifications.h"
@@ -42,6 +40,8 @@
 #include "chrome/common/chrome_switches.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
+#include "components/bookmarks/core/browser/bookmark_model.h"
+#include "components/bookmarks/core/browser/bookmark_utils.h"
 #include "content/public/browser/notification_details.h"
 #include "content/public/browser/notification_source.h"
 #include "content/public/browser/url_data_source.h"
@@ -386,7 +386,10 @@ bool BrowsingHistoryHandler::HistoryEntry::SortByTimeDescending(
   return entry1.time > entry2.time;
 }
 
-BrowsingHistoryHandler::BrowsingHistoryHandler() {}
+BrowsingHistoryHandler::BrowsingHistoryHandler()
+    : has_pending_delete_request_(false),
+      weak_factory_(this) {
+}
 
 BrowsingHistoryHandler::~BrowsingHistoryHandler() {
   history_request_consumer_.CancelAllRequests();
@@ -529,7 +532,10 @@ void BrowsingHistoryHandler::HandleQueryHistory(const base::ListValue* args) {
 
 void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) {
   Profile* profile = Profile::FromWebUI(web_ui());
+  // TODO(davidben): history.js is not aware of this failure and will still
+  // override |deleteCompleteCallback_|.
   if (delete_task_tracker_.HasTrackedTasks() ||
+      has_pending_delete_request_ ||
       !profile->GetPrefs()->GetBoolean(prefs::kAllowDeletingBrowserHistory)) {
     web_ui()->CallJavascriptFunction("deleteFailed");
     return;
@@ -612,10 +618,11 @@ void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) {
       &delete_task_tracker_);
 
   if (web_history) {
-    web_history_delete_request_ = web_history->ExpireHistory(
+    has_pending_delete_request_ = true;
+    web_history->ExpireHistory(
         expire_list,
         base::Bind(&BrowsingHistoryHandler::RemoveWebHistoryComplete,
-                   base::Unretained(this)));
+                   weak_factory_.GetWeakPtr()));
   }
 
 #if defined(ENABLE_EXTENSIONS)
@@ -635,9 +642,8 @@ void BrowsingHistoryHandler::HandleRemoveVisits(const base::ListValue* args) {
 void BrowsingHistoryHandler::HandleClearBrowsingData(
     const base::ListValue* args) {
 #if defined(OS_ANDROID)
-  Profile* profile = Profile::FromWebUI(web_ui());
-  const TabModel* tab_model =
-      TabModelList::GetTabModelWithProfile(profile);
+  const TabModel* tab_model = TabModelList::GetTabModelForWebContents(
+      web_ui()->GetWebContents());
   if (tab_model)
     tab_model->OpenClearBrowsingData();
 #else
@@ -886,14 +892,12 @@ void BrowsingHistoryHandler::RemoveComplete() {
 
   // Notify the page that the deletion request is complete, but only if a web
   // history delete request is not still pending.
-  if (!(web_history_delete_request_.get() &&
-        web_history_delete_request_->is_pending())) {
+  if (!has_pending_delete_request_)
     web_ui()->CallJavascriptFunction("deleteComplete");
-  }
 }
 
-void BrowsingHistoryHandler::RemoveWebHistoryComplete(
-    history::WebHistoryService::Request* request, bool success) {
+void BrowsingHistoryHandler::RemoveWebHistoryComplete(bool success) {
+  has_pending_delete_request_ = false;
   // TODO(dubroy): Should we handle failure somehow? Delete directives will
   // ensure that the visits are eventually deleted, so maybe it's not necessary.
   if (!delete_task_tracker_.HasTrackedTasks())
@@ -1002,12 +1006,6 @@ HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
 }
 
 // static
-const GURL HistoryUI::GetHistoryURLWithSearchText(const base::string16& text) {
-  return GURL(std::string(chrome::kChromeUIHistoryURL) + "#q=" +
-              net::EscapeQueryParamValue(base::UTF16ToUTF8(text), true));
-}
-
-// static
 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
       ui::ScaleFactor scale_factor) {
   return ResourceBundle::GetSharedInstance().