| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/web_resource/web_resource_util.h" | 5 #include "ios/chrome/browser/web_resource/web_resource_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/task_runner.h" | 10 #include "base/task_runner.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 std::unique_ptr<base::Value> value(base::JSONReader::Read(data)); | 45 std::unique_ptr<base::Value> value(base::JSONReader::Read(data)); |
| 46 if (!value.get()) { | 46 if (!value.get()) { |
| 47 // Page information not properly read, or corrupted. | 47 // Page information not properly read, or corrupted. |
| 48 PostErrorTask(task_runner, error_callback, kInvalidDataTypeError); | 48 PostErrorTask(task_runner, error_callback, kInvalidDataTypeError); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 | 51 |
| 52 if (!value->IsType(base::Value::TYPE_DICTIONARY)) { | 52 if (!value->IsType(base::Value::Type::DICTIONARY)) { |
| 53 PostErrorTask(task_runner, error_callback, kUnexpectedJSONFormatError); | 53 PostErrorTask(task_runner, error_callback, kUnexpectedJSONFormatError); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 | 56 |
| 57 task_runner->PostTask(FROM_HERE, | 57 task_runner->PostTask(FROM_HERE, |
| 58 base::Bind(success_callback, base::Passed(&value))); | 58 base::Bind(success_callback, base::Passed(&value))); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Starts the parsing of |data| as a JSON string asynchronously on a background | 61 // Starts the parsing of |data| as a JSON string asynchronously on a background |
| 62 // thread. Can be called from the UI thread. | 62 // thread. Can be called from the UI thread. |
| 63 void StartParseJSONAsync( | 63 void StartParseJSONAsync( |
| 64 const std::string& data, | 64 const std::string& data, |
| 65 const WebResourceService::SuccessCallback& success_callback, | 65 const WebResourceService::SuccessCallback& success_callback, |
| 66 const WebResourceService::ErrorCallback& error_callback) { | 66 const WebResourceService::ErrorCallback& error_callback) { |
| 67 web::WebThread::PostBlockingPoolTask( | 67 web::WebThread::PostBlockingPoolTask( |
| 68 FROM_HERE, | 68 FROM_HERE, |
| 69 base::Bind(&ParseJSONOnBackgroundThread, | 69 base::Bind(&ParseJSONOnBackgroundThread, |
| 70 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), data, | 70 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), data, |
| 71 success_callback, error_callback)); | 71 success_callback, error_callback)); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 WebResourceService::ParseJSONCallback GetIOSChromeParseJSONCallback() { | 76 WebResourceService::ParseJSONCallback GetIOSChromeParseJSONCallback() { |
| 77 return base::Bind(&StartParseJSONAsync); | 77 return base::Bind(&StartParseJSONAsync); |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace web_resource | 80 } // namespace web_resource |
| OLD | NEW |