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

Side by Side Diff: chrome/browser/ui/app_list/search/common/json_response_fetcher.cc

Issue 1865213004: Convert //chrome/browser/ui from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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/values.h" 11 #include "base/values.h"
11 #include "components/safe_json/safe_json_parser.h" 12 #include "components/safe_json/safe_json_parser.h"
12 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
13 #include "net/url_request/url_fetcher.h" 14 #include "net/url_request/url_fetcher.h"
14 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace app_list { 18 namespace app_list {
18 19
19 const char kBadResponse[] = "Bad Web Service search response"; 20 const char kBadResponse[] = "Bad Web Service search response";
(...skipping 18 matching lines...) Expand all
38 net::LOAD_DISABLE_CACHE); 39 net::LOAD_DISABLE_CACHE);
39 fetcher_->Start(); 40 fetcher_->Start();
40 } 41 }
41 42
42 void JSONResponseFetcher::Stop() { 43 void JSONResponseFetcher::Stop() {
43 fetcher_.reset(); 44 fetcher_.reset();
44 weak_factory_.InvalidateWeakPtrs(); 45 weak_factory_.InvalidateWeakPtrs();
45 } 46 }
46 47
47 void JSONResponseFetcher::OnJsonParseSuccess( 48 void JSONResponseFetcher::OnJsonParseSuccess(
48 scoped_ptr<base::Value> parsed_json) { 49 std::unique_ptr<base::Value> parsed_json) {
49 if (!parsed_json->IsType(base::Value::TYPE_DICTIONARY)) { 50 if (!parsed_json->IsType(base::Value::TYPE_DICTIONARY)) {
50 OnJsonParseError(kBadResponse); 51 OnJsonParseError(kBadResponse);
51 return; 52 return;
52 } 53 }
53 54
54 callback_.Run(make_scoped_ptr( 55 callback_.Run(base::WrapUnique(
55 static_cast<base::DictionaryValue*>(parsed_json.release()))); 56 static_cast<base::DictionaryValue*>(parsed_json.release())));
56 } 57 }
57 58
58 void JSONResponseFetcher::OnJsonParseError(const std::string& error) { 59 void JSONResponseFetcher::OnJsonParseError(const std::string& error) {
59 callback_.Run(scoped_ptr<base::DictionaryValue>()); 60 callback_.Run(std::unique_ptr<base::DictionaryValue>());
60 } 61 }
61 62
62 void JSONResponseFetcher::OnURLFetchComplete( 63 void JSONResponseFetcher::OnURLFetchComplete(
63 const net::URLFetcher* source) { 64 const net::URLFetcher* source) {
64 CHECK_EQ(fetcher_.get(), source); 65 CHECK_EQ(fetcher_.get(), source);
65 66
66 scoped_ptr<net::URLFetcher> fetcher(std::move(fetcher_)); 67 std::unique_ptr<net::URLFetcher> fetcher(std::move(fetcher_));
67 68
68 if (!fetcher->GetStatus().is_success() || 69 if (!fetcher->GetStatus().is_success() ||
69 fetcher->GetResponseCode() != 200) { 70 fetcher->GetResponseCode() != 200) {
70 OnJsonParseError(kBadResponse); 71 OnJsonParseError(kBadResponse);
71 return; 72 return;
72 } 73 }
73 74
74 std::string json_data; 75 std::string json_data;
75 fetcher->GetResponseAsString(&json_data); 76 fetcher->GetResponseAsString(&json_data);
76 77
77 // The parser will call us back via one of the callbacks. 78 // The parser will call us back via one of the callbacks.
78 safe_json::SafeJsonParser::Parse( 79 safe_json::SafeJsonParser::Parse(
79 json_data, base::Bind(&JSONResponseFetcher::OnJsonParseSuccess, 80 json_data, base::Bind(&JSONResponseFetcher::OnJsonParseSuccess,
80 weak_factory_.GetWeakPtr()), 81 weak_factory_.GetWeakPtr()),
81 base::Bind(&JSONResponseFetcher::OnJsonParseError, 82 base::Bind(&JSONResponseFetcher::OnJsonParseError,
82 weak_factory_.GetWeakPtr())); 83 weak_factory_.GetWeakPtr()));
83 } 84 }
84 85
85 } // namespace app_list 86 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698