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

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

Issue 2172443004: [Offline Pages] Add network status, save request textbox, and offline url link to offline internals… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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/offline_internals_ui.cc
diff --git a/chrome/browser/ui/webui/offline_internals_ui.cc b/chrome/browser/ui/webui/offline_internals_ui.cc
index 93ed44994e32922e0c036e5ce4402044ad82cd50..17c0669b021bd37a781ae501169348b34d741e53 100644
--- a/chrome/browser/ui/webui/offline_internals_ui.cc
+++ b/chrome/browser/ui/webui/offline_internals_ui.cc
@@ -19,12 +19,14 @@
#include "chrome/common/url_constants.h"
#include "components/offline_pages/background/request_coordinator.h"
#include "components/offline_pages/background/save_page_request.h"
+#include "components/offline_pages/client_namespace_constants.h"
#include "components/offline_pages/offline_page_model.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
+#include "net/base/network_change_notifier.h"
namespace {
@@ -62,6 +64,12 @@ class OfflineInternalsUIMessageHandler : public content::WebUIMessageHandler {
// Load whether logs are being recorded.
void HandleGetLoggingState(const base::ListValue* args);
+ // Adds a url to the background loader queue.
+ void HandleAddToRequestQueue(const base::ListValue* args);
+
+ // Load whether device is currently offline.
+ void HandleGetNetworkStatus(const base::ListValue* args);
+
// Callback for async GetAllPages calls.
void HandleStoredPagesCallback(
std::string callback_id,
@@ -197,7 +205,7 @@ void OfflineInternalsUIMessageHandler::HandleStoredPagesCallback(
offline_page->SetString("namespace", page.client_id.name_space);
offline_page->SetDouble("size", page.file_size);
offline_page->SetString("id", std::to_string(page.offline_id));
- offline_page->SetString("filePath", page.file_path.value());
+ offline_page->SetString("filePath", page.GetOfflineURL().spec());
offline_page->SetDouble("creationTime", page.creation_time.ToJsTime());
offline_page->SetDouble("lastAccessTime",
page.last_access_time.ToJsTime());
@@ -270,6 +278,18 @@ void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel(
offline_page_model_->GetLogger()->SetIsLogging(should_record);
}
+void OfflineInternalsUIMessageHandler::HandleGetNetworkStatus(
+ const base::ListValue* args) {
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ if (net::NetworkChangeNotifier::IsOffline()) {
dpapad 2016/07/21 18:57:25 Nit: I think you can compress this by using the te
chili 2016/07/21 23:57:20 Done.
+ ResolveJavascriptCallback(*callback_id, base::StringValue("Offline"));
+ } else {
+ ResolveJavascriptCallback(*callback_id, base::StringValue("Online"));
+ }
+}
+
void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
const base::ListValue* args) {
bool should_record;
@@ -308,6 +328,21 @@ void OfflineInternalsUIMessageHandler::HandleGetEventLogs(
ResolveJavascriptCallback(*callback_id, result);
}
+void OfflineInternalsUIMessageHandler::HandleAddToRequestQueue(
+ const base::ListValue* args) {
+ const base::Value* callback_id;
+ CHECK(args->Get(0, &callback_id));
+
+ std::string url;
+ CHECK(args->GetString(1, &url));
+
+ bool result = request_coordinator_->SavePageLater(
+ GURL(url),
+ offline_pages::ClientId(offline_pages::kAsyncNamespace, "foo"));
dpapad 2016/07/21 18:57:25 It is not clear here why "foo" is hardcoded. Pleas
chili 2016/07/21 23:57:20 I changed this in a following version but must've
+
+ ResolveJavascriptCallback(*callback_id, base::FundamentalValue(result));
+}
+
void OfflineInternalsUIMessageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"deleteAllPages",
@@ -341,6 +376,14 @@ void OfflineInternalsUIMessageHandler::RegisterMessages() {
"getLoggingState",
base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState,
weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "addToRequestQueue",
+ base::Bind(&OfflineInternalsUIMessageHandler::HandleAddToRequestQueue,
+ weak_ptr_factory_.GetWeakPtr()));
+ web_ui()->RegisterMessageCallback(
+ "getNetworkStatus",
+ base::Bind(&OfflineInternalsUIMessageHandler::HandleGetNetworkStatus,
+ weak_ptr_factory_.GetWeakPtr()));
// Get the offline page model associated with this web ui.
Profile* profile = Profile::FromWebUI(web_ui());

Powered by Google App Engine
This is Rietveld 408576698