| 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 "components/safe_json/json_sanitizer.h" |   5 #include "components/safe_json/json_sanitizer.h" | 
|   6  |   6  | 
|   7 #if defined(OS_ANDROID) |   7 #if defined(OS_ANDROID) | 
|   8 #error Build json_sanitizer_android.cc instead of this file on Android. |   8 #error Build json_sanitizer_android.cc instead of this file on Android. | 
|   9 #endif |   9 #endif | 
|  10  |  10  | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  27 class OopJsonSanitizer : public JsonSanitizer { |  27 class OopJsonSanitizer : public JsonSanitizer { | 
|  28  public: |  28  public: | 
|  29   OopJsonSanitizer(const std::string& unsafe_json, |  29   OopJsonSanitizer(const std::string& unsafe_json, | 
|  30                    const StringCallback& success_callback, |  30                    const StringCallback& success_callback, | 
|  31                    const StringCallback& error_callback); |  31                    const StringCallback& error_callback); | 
|  32  |  32  | 
|  33  private: |  33  private: | 
|  34   friend std::default_delete<OopJsonSanitizer>; |  34   friend std::default_delete<OopJsonSanitizer>; | 
|  35   ~OopJsonSanitizer() {} |  35   ~OopJsonSanitizer() {} | 
|  36  |  36  | 
|  37   void OnParseSuccess(scoped_ptr<base::Value> value); |  37   void OnParseSuccess(std::unique_ptr<base::Value> value); | 
|  38   void OnParseError(const std::string& error); |  38   void OnParseError(const std::string& error); | 
|  39  |  39  | 
|  40   StringCallback success_callback_; |  40   StringCallback success_callback_; | 
|  41   StringCallback error_callback_; |  41   StringCallback error_callback_; | 
|  42  |  42  | 
|  43   DISALLOW_COPY_AND_ASSIGN(OopJsonSanitizer); |  43   DISALLOW_COPY_AND_ASSIGN(OopJsonSanitizer); | 
|  44 }; |  44 }; | 
|  45  |  45  | 
|  46 OopJsonSanitizer::OopJsonSanitizer(const std::string& unsafe_json, |  46 OopJsonSanitizer::OopJsonSanitizer(const std::string& unsafe_json, | 
|  47                                    const StringCallback& success_callback, |  47                                    const StringCallback& success_callback, | 
|  48                                    const StringCallback& error_callback) |  48                                    const StringCallback& error_callback) | 
|  49     : success_callback_(success_callback), error_callback_(error_callback) { |  49     : success_callback_(success_callback), error_callback_(error_callback) { | 
|  50   SafeJsonParser::Parse(unsafe_json, |  50   SafeJsonParser::Parse(unsafe_json, | 
|  51                         base::Bind(&OopJsonSanitizer::OnParseSuccess, |  51                         base::Bind(&OopJsonSanitizer::OnParseSuccess, | 
|  52                                    base::Unretained(this)), |  52                                    base::Unretained(this)), | 
|  53                         base::Bind(&OopJsonSanitizer::OnParseError, |  53                         base::Bind(&OopJsonSanitizer::OnParseError, | 
|  54                                    base::Unretained(this))); |  54                                    base::Unretained(this))); | 
|  55 } |  55 } | 
|  56  |  56  | 
|  57 void OopJsonSanitizer::OnParseSuccess(scoped_ptr<base::Value> value) { |  57 void OopJsonSanitizer::OnParseSuccess(std::unique_ptr<base::Value> value) { | 
|  58   // Self-destruct at the end of this method. |  58   // Self-destruct at the end of this method. | 
|  59   scoped_ptr<OopJsonSanitizer> deleter(this); |  59   std::unique_ptr<OopJsonSanitizer> deleter(this); | 
|  60  |  60  | 
|  61   // A valid JSON document may only have a dictionary or list as its top-level |  61   // A valid JSON document may only have a dictionary or list as its top-level | 
|  62   // type, but the JSON parser also accepts other types, so we filter them out. |  62   // type, but the JSON parser also accepts other types, so we filter them out. | 
|  63   base::Value::Type type = value->GetType(); |  63   base::Value::Type type = value->GetType(); | 
|  64   if (type != base::Value::TYPE_DICTIONARY && type != base::Value::TYPE_LIST) { |  64   if (type != base::Value::TYPE_DICTIONARY && type != base::Value::TYPE_LIST) { | 
|  65     error_callback_.Run("Invalid top-level type"); |  65     error_callback_.Run("Invalid top-level type"); | 
|  66     return; |  66     return; | 
|  67   } |  67   } | 
|  68  |  68  | 
|  69   std::string json; |  69   std::string json; | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  84  |  84  | 
|  85 // static |  85 // static | 
|  86 void JsonSanitizer::Sanitize(const std::string& unsafe_json, |  86 void JsonSanitizer::Sanitize(const std::string& unsafe_json, | 
|  87                              const StringCallback& success_callback, |  87                              const StringCallback& success_callback, | 
|  88                              const StringCallback& error_callback) { |  88                              const StringCallback& error_callback) { | 
|  89   // OopJsonSanitizer destroys itself when it is finished. |  89   // OopJsonSanitizer destroys itself when it is finished. | 
|  90   new OopJsonSanitizer(unsafe_json, success_callback, error_callback); |  90   new OopJsonSanitizer(unsafe_json, success_callback, error_callback); | 
|  91 } |  91 } | 
|  92  |  92  | 
|  93 }  // namespace safe_json |  93 }  // namespace safe_json | 
| OLD | NEW |