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

Unified Diff: ios/chrome/browser/web_resource/ios_web_resource_service.cc

Issue 880433002: In-process JSON parsing for web resources on iOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 11 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
« no previous file with comments | « ios/chrome/browser/web_resource/ios_web_resource_service.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web_resource/ios_web_resource_service.cc
diff --git a/ios/chrome/browser/web_resource/ios_web_resource_service.cc b/ios/chrome/browser/web_resource/ios_web_resource_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5d538c9bc5153c5e5c052814f3c331edaaa9877c
--- /dev/null
+++ b/ios/chrome/browser/web_resource/ios_web_resource_service.cc
@@ -0,0 +1,81 @@
+// Copyright 2015 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 "ios/chrome/browser/web_resource/ios_web_resource_service.h"
+
+#include "base/bind.h"
+#include "base/json/json_reader.h"
+#include "base/values.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/web/public/web_thread.h"
+
+namespace {
+
+const char kInvalidDataTypeError[] =
+ "Data from web resource server is missing or not valid JSON.";
+
+const char kUnexpectedJSONFormatError[] =
+ "Data from web resource server does not have expected format.";
+
+// Helper method to run a closure.
+void RunClosure(const base::Closure& closure) {
+ closure.Run();
+}
+
+} // namespace
+
+IOSWebResourceService::IOSWebResourceService(
+ PrefService* prefs,
+ const GURL& web_resource_server,
+ bool apply_locale_to_url,
+ const char* last_update_time_pref_name,
+ int start_fetch_delay_ms,
+ int cache_update_delay_ms)
+ : web_resource::WebResourceService(
+ prefs,
+ web_resource_server,
+ apply_locale_to_url ? GetApplicationContext()->GetApplicationLocale()
+ : std::string(),
+ last_update_time_pref_name,
+ start_fetch_delay_ms,
+ cache_update_delay_ms,
+ nullptr) {
+}
+
+IOSWebResourceService::~IOSWebResourceService() {
+}
+
+// static
+base::Closure IOSWebResourceService::ParseJSONOnBackgroundThread(
+ const std::string& data,
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback) {
+ if (data.empty())
+ return base::Bind(error_callback, std::string(kInvalidDataTypeError));
+
+ scoped_ptr<base::Value> value(base::JSONReader::Read(data));
+ if (!value.get()) {
+ // Page information not properly read, or corrupted.
+ return base::Bind(error_callback, std::string(kInvalidDataTypeError));
+ }
+
+ if (!value->IsType(base::Value::TYPE_DICTIONARY))
+ return base::Bind(error_callback, std::string(kUnexpectedJSONFormatError));
+
+ return base::Bind(success_callback, base::Passed(&value));
+}
+
+void IOSWebResourceService::ParseJSON(const std::string& data,
+ const SuccessCallback& success_callback,
+ const ErrorCallback& error_callback) {
+ base::PostTaskAndReplyWithResult(
+ web::WebThread::GetBlockingPool(), FROM_HERE,
+ base::Bind(&IOSWebResourceService::ParseJSONOnBackgroundThread, data,
+ success_callback, error_callback),
+ base::Bind(&RunClosure));
+}
+
+net::URLRequestContextGetter* IOSWebResourceService::GetRequestContext() {
+ return GetApplicationContext()->GetSystemURLRequestContext();
+}
« no previous file with comments | « ios/chrome/browser/web_resource/ios_web_resource_service.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698