OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/app_list/search/common/json_response_fetcher.h" | 5 #include "chrome/browser/ui/app_list/search/common/json_response_fetcher.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 fetcher_->Start(); | 40 fetcher_->Start(); |
41 } | 41 } |
42 | 42 |
43 void JSONResponseFetcher::Stop() { | 43 void JSONResponseFetcher::Stop() { |
44 fetcher_.reset(); | 44 fetcher_.reset(); |
45 weak_factory_.InvalidateWeakPtrs(); | 45 weak_factory_.InvalidateWeakPtrs(); |
46 } | 46 } |
47 | 47 |
48 void JSONResponseFetcher::OnJsonParseSuccess( | 48 void JSONResponseFetcher::OnJsonParseSuccess( |
49 std::unique_ptr<base::Value> parsed_json) { | 49 std::unique_ptr<base::Value> parsed_json) { |
50 if (!parsed_json->IsType(base::Value::TYPE_DICTIONARY)) { | 50 if (!parsed_json->IsType(base::Value::Type::DICTIONARY)) { |
51 OnJsonParseError(kBadResponse); | 51 OnJsonParseError(kBadResponse); |
52 return; | 52 return; |
53 } | 53 } |
54 | 54 |
55 callback_.Run(base::WrapUnique( | 55 callback_.Run(base::WrapUnique( |
56 static_cast<base::DictionaryValue*>(parsed_json.release()))); | 56 static_cast<base::DictionaryValue*>(parsed_json.release()))); |
57 } | 57 } |
58 | 58 |
59 void JSONResponseFetcher::OnJsonParseError(const std::string& error) { | 59 void JSONResponseFetcher::OnJsonParseError(const std::string& error) { |
60 callback_.Run(std::unique_ptr<base::DictionaryValue>()); | 60 callback_.Run(std::unique_ptr<base::DictionaryValue>()); |
(...skipping 16 matching lines...) Expand all Loading... |
77 | 77 |
78 // The parser will call us back via one of the callbacks. | 78 // The parser will call us back via one of the callbacks. |
79 safe_json::SafeJsonParser::Parse( | 79 safe_json::SafeJsonParser::Parse( |
80 json_data, base::Bind(&JSONResponseFetcher::OnJsonParseSuccess, | 80 json_data, base::Bind(&JSONResponseFetcher::OnJsonParseSuccess, |
81 weak_factory_.GetWeakPtr()), | 81 weak_factory_.GetWeakPtr()), |
82 base::Bind(&JSONResponseFetcher::OnJsonParseError, | 82 base::Bind(&JSONResponseFetcher::OnJsonParseError, |
83 weak_factory_.GetWeakPtr())); | 83 weak_factory_.GetWeakPtr())); |
84 } | 84 } |
85 | 85 |
86 } // namespace app_list | 86 } // namespace app_list |
OLD | NEW |